Skip to content
pi-c Artifact [7db8d9001e]
Login

Artifact [7db8d9001e]

Artifact 7db8d9001ee424386ad1f44f9fb01a04fd21e236356345aad88dc75ff276f22c:


pic

A durable coding agent in C. pic does what the Pi coding agent does (same tools, sessions, compaction, slash commands, JSON events and model catalog), and keeps every turn in a SQLite journal so a crash, a kill or a lost connection never loses work or runs a command twice.

Build and install

make pic           # build/pic/release/pic
make install-pic   # runs the test suite, then installs to ~/.local/bin/pic
make bench-pic     # compare timings with bench/baselines/<OS>-<arch>.tsv

The build uses CC (default cc) and compiles with -Werror; it is warning-clean under clang and gcc (make CC=gcc-16 pic). gcc's -Wformat-truncation, which clang does not have, is off: a clipped error or display string is the intended outcome there.

API keys come from the environment (ANTHROPIC_API_KEY, OPENAI_API_KEY, OPENROUTER_API_KEY, ...), as in Pi, or from pic's credential store:

pic login anthropic          # the key, typed with echo off (or piped on stdin), sealed into ~/.pic/pic.sqlite
pic keys                     # stored keys: names and dates, never values
pic logout anthropic         # remove it

Each stored key is sealed with ChaCha20-Poly1305 (the provider's name bound as associated data), so no plaintext key reaches the database, its WAL, a backup or a log. The sealing key comes from a passphrase, stretched with PBKDF2-HMAC-SHA256 (600,000 iterations, a random salt; both kept in picu_credential_key with a verifier, so a wrong passphrase is refused cleanly). pic asks for the passphrase on the terminal the first time a stored key is needed, and keeps the key only for the life of the process; the terminal interface asks once and hands the key to its request processes through an inherited pipe, never argv, the environment's values or a file. The lookup order is a key written in models.json, then the provider's variable, then the store, then an error naming pic login. /login [PROVIDER] and /logout [PROVIDER] do the same in the terminal interface. The store protects against a stolen disk, backup or database copy; not against a weak passphrase or malware running as you.

Use

pic                          # the terminal interface in the current directory
pic tui -c                   # continue the latest conversation
pic ask "fix the failing test"
pic ask -c "now add a regression test"
pic -p "list the TODOs"      # Pi's print mode: one prompt, the answer on stdout
git diff | pic -p "review this"   # piped stdin comes first in the prompt
pic -p @notes.md @shot.png "summarize"   # @files: text as <file name="...">, images attached
pic --system-prompt "Be terse." -p "..."   # TEXT or a file; --append-system-prompt adds to the default
pic chat                     # a plain line prompt
pic --model openrouter/deepseek/deepseek-v4-flash --thinking high ask "..."
pic models                   # models whose provider has a key
pic sessions                 # conversations in this workspace
pic skills                   # skills in ~/.pic/skills (and the trusted workspace's); /skill:name runs one
pic --json ask "..."         # Pi's JSON events on stdout
pic --mode rpc               # Pi's RPC mode: JSONL commands on stdin, responses and events on stdout

In the terminal interface: / opens the command menu (/model, /settings, /thinking, /tree, /fork, /compact, /export, /share, /resume and the rest of Pi's commands); Ctrl+L picks a model, Ctrl+P cycles models, Shift+Tab cycles thinking levels, Esc stops a reply. pic --help lists every command.

Themes and keybindings

The terminal interface uses Pi's theme model (packages/coding-agent theme.ts, dark.json, light.json). Every colour is one of Pi's 51 tokens (accent, border*, userMessage*, tool*, md*, syntax*, toolDiff*, thinking*, bashMode, ...); the built-in dark and light themes are Pi's files and their OKHSL values convert to the same sRGB as Pi's okhslToRgb. Colours are truecolor when COLORTERM says so and otherwise the nearest of 256, chosen as Pi's rgbToAnsi256 does.

Action pic default Pi's Why (source)
tui.input.newLine Shift+Enter, Ctrl+J, and \ then Enter Shift+Enter, Ctrl+J Claude Code's backslash-Enter works in every terminal
app.message.followUp Ctrl+Q, Alt+Enter Alt+Enter Alt+Enter needs Option as Meta; Claude Code has no follow-up, Ctrl+Q is free and sendable
app.message.dequeue Alt+Up, and Up from the editor's first line Alt+Up Claude Code pulls queued messages back with Up
app.model.select Alt+P Ctrl+L Ctrl+L redraws in Claude Code; Option+P is its model picker (/model and Ctrl+P cycling work too)
app.screen.redraw (pic's) Ctrl+L Claude Code's Ctrl+L
app.exit Ctrl+D twice within 800 ms, on an empty editor Ctrl+D once Claude Code asks for the second press and says so ("press ctrl+d again to exit"); with text in the editor Ctrl+D still deletes forward
app.history.search (pic's) Ctrl+R Claude Code's Ctrl+R over this conversation's prompts (those of a resumed one included): type to filter (case-insensitive), Ctrl+R again for an older match, Enter takes the match into the editor (it is not sent), Esc cancels
app.thinking.cycle Shift+Tab, Alt+T Shift+Tab Option+T is Claude Code's thinking toggle
app.model.cycleBackward Shift+Ctrl+P, Ctrl+N Shift+Ctrl+P terminals drop the Shift on a Ctrl chord
tui.altScreen.pageUp/pageDown PageUp/PageDown, Shift+Up/Shift+Down PageUp/PageDown Mac keyboards reach PageUp as Fn+Up, which not every terminal passes
tui.altScreen.top/bottom Ctrl+Home/Ctrl+End, Shift+PageUp/Shift+PageDown Ctrl+Home/Ctrl+End Mac keyboards have no End key; the "Jump to latest" hint names the bound keys

Also as in Claude Code: Enter while a reply runs steers it, Ctrl+C interrupts a running reply (again: exit) or clears the input, Esc Esc clears a draft (on an empty editor it opens /tree), and sending a message scrolls to the end. Not done: Ctrl+Enter send-now, chords such as Ctrl+X Ctrl+F, and Claude Code's {"bindings":[{"context":...}]} file shape (only Pi's format is read).

Print mode follows Pi's: -p (or --print) takes the prompt as its next argument unless that starts with @ or - (--- excepted), and runs it as pic ask does; exit 0 on an answer, 1 on a failed or cut-short request or an unreadable @file. Piped stdin (when stdin is not a terminal) is trimmed and put first, then the @file blocks, then the first message, with nothing between them; further messages continue the conversation. -- ends the options. --system-prompt replaces the system prompt and --append-system-prompt (repeatable) adds an <addendum> after it; each takes text or the path of a file. Without them pic reads .pic/SYSTEM.md and .pic/APPEND_SYSTEM.md from a trusted workspace, else from ~/.pic/.

Compaction and branch summaries take Pi's settings, in Pi's settings.json shape (pic settings compaction '{"reserveTokens":16384,"keepRecentTokens":20000}'): compaction.enabled (default true; off stops automatic compaction, overflow recovery included, as in Pi, but not pic compact; /settings Auto-compact and the RPC command set_auto_compaction set it), compaction.reserveTokens, compaction.keepRecentTokens, compaction.modelOverrides["provider/model"], branchSummary.reserveTokens and branchSummary.skipPrompt. Leaving a branch in /tree asks Pi's "Summarize branch?"; a summary (pic fork ID --at ENTRY --summarize) is a journaled, priced request, and the new conversation starts with Pi's branch_summary entry.

RPC mode

pic --mode rpc speaks Pi's RPC protocol (Pi's docs/rpc.md and docs/rpc-commands.md): one JSON command per line on stdin, each answered by a response line with its id, command, success and data or error, with Pi's JSON events in between. -c (or --continue) continues the latest conversation and --session ID that one; otherwise a new one starts. --model and --thinking set where it starts. Closing stdin ends the process; SIGTERM, SIGHUP and SIGINT cancel what runs first.

Every Pi command is there with Pi's fields, responses and errors: prompt (with images and streamingBehavior), steer, follow_up, abort, clear_queue, new_session, get_state, get_messages, set_model, cycle_model, get_available_models, set_thinking_level, cycle_thinking_level, get_available_thinking_levels, set_steering_mode, set_follow_up_mode, compact, set_auto_compaction, set_auto_retry, abort_retry, bash, abort_bash, get_session_stats, export_html, switch_session, fork, clone, get_fork_messages, get_entries, get_tree, get_last_assistant_text, set_session_name and get_commands. Where pic differs: a session is a conversation in the journal, so sessionFile is left out, switch_session takes a conversation id (or a file pic export --pi wrote) as sessionPath, and get_entries and get_tree cover the conversation's own path; a model or thinking change applies from the next request; set_auto_retry is saved as Pi's retry.enabled, which only RPC mode reads. pic has no extensions or subscription login, so extension_ui_response, login and logout are answered with an error that says so.

The process holds the journal only while it works: for one command when idle, and for the length of a request, a compaction or a bash command, so other pic commands can use the journal in between. While a request runs, steering, queries and setting changes are answered at once; compact, new_session, switch_session, fork and clone abort the request first (journaled as Ctrl-C's cancel is) and run once it has stopped; anything else waits its turn. compact then compacts at once, outside any request: the compaction and its summary request belong to the conversation's latest request and commit together, so a crash leaves either the compaction or a failed attempt. A crash mid-request recovers as any pic run's (pic run, or the next request). Steering sent while idle is held for the next prompt, as Pi's is.

Benchmarks

Three switches help compare runs of pic against each other:

Hooks

pic runs command hooks written for Claude Code. They live in ~/.pic/hooks.json, and in the workspace's .pic/hooks.json once you trust it (pic trust yes). Both files use Claude Code's hooks object, and pic never writes them:

{"hooks": {"PreToolUse": [{"matcher": "Bash|Read", "hooks": [{"type": "command", "command": "ctx gate", "timeout": 5}]}]}}

The events are SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, PreCompact, Stop and SessionEnd, with Claude Code's input on stdin plus "harness":"pic". session_id is the conversation's id, the same id its Pi session header carries. transcript_path is ~/.pic/pic.sqlite, not the journal, which pic keeps locked while it runs. Before every hook runs, the conversation's Pi lines in that file's picu_pi_session_line table are committed through its latest entry, even mid-request. The file is never locked while a hook runs, so a hook can read the conversation there. Edit also matches as MultiEdit. A hook runs with pic's whole environment, API keys included, plus PIC_HOOK=1. Only configure commands you trust. A matcher accepts pic's tool names and Claude Code's (Bash, Read, Edit, Write, Grep, Glob, LS), and tool_input carries file_path as well as path.

pic reads exit 2, additionalContext, permissionDecision and decision: block the way Claude Code does. A PreToolUse ask runs the call, because pic has no permission prompts. Context a hook adds is journaled, so a resumed conversation sends it again without running the hook again. A hook that times out (default 10 s, at most 60), crashes or prints bad JSON is ignored and recorded. A hook dies with pic, and Ctrl-C stops it. pic kills a hook's process group only at its timeout, when pic dies, or on Ctrl-C. pic bounds the hook command, not what it backgrounds; use async: true for work that should outlive the hook under a timeout. To clean up children yourself, wait for them or trap 'kill 0' EXIT. Each run is journaled before it starts. If a crash cuts one off, it is never run again and its output is not used. A tool call whose PreToolUse hook was cut off does not run. A steer or follow-up sent with --commands is answered "queued" at once. Its prompt hooks run before it can be delivered, after a crash too, and a block returns it (queue_returned, with the reason). A follow-up sent after the reply has finished becomes the next request at once, so its hooks can add context but cannot block it. pic hooks lists the configured hooks, and pic dump lists every run.

Processes

pic ps lists the processes pic itself started that are still running: hooks (sync and async), bash tool and ! commands, and the terminal interface's request children. pic ps --all adds those finished in the last 7 days, with their exit status; --json prints JSON. pic ps --kill ID (or --kill --all) sends SIGTERM to the recorded process group, then SIGKILL after 3 seconds, and only to a process that is still the one recorded (its pid is alive and its start time matches, so a reused pid is never signaled). The records live in picu_proc of ~/.pic/pic.sqlite, so they span workspaces. At startup pic prints one line to stderr, at most once an hour, if processes of earlier runs are still running. It is not a watcher: it lists what pic recorded. Processes a hook script starts on its own are not tracked.

Test

make test-pic      # crash, tool, provider, session, TUI and unit suites; ASan/UBSan and release builds

CI runs the same suite on every check-in and gates trunk. Changes are also run under Fil-C, where any memory error is a crash (tools/remote/).

Where pic can run

pic is C11 with every dependency vendored, links only libc, libm and pthread, does its own TLS, and keeps all its state in SQLite. What touches the operating system sits behind two interfaces: pic_platform (clocks, entropy, the lock, input files, the SQLite VFS) and pic_executor (file operations and running commands). That makes unusual targets reachable:

Documents

reference/pi.lock.json pins the Pi revision used as the behavioural reference. Pi's source is not part of this repository.

License

BSD 2-Clause; see LICENSE. Vendored code and adapted Pi material keep their own licenses; see NOTICE.