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.
- Durable. Each request, model reply and tool call is committed to
WORKSPACE/.pic/journal.sqlitebefore and after it happens. A run that dies is picked up by the nextpic; a command that may have run is reported as such, never silently re-run. - Any model. Anthropic, OpenAI (Chat Completions and Responses), OpenRouter and any OpenAI-compatible server, with Pi's thinking levels. One conversation can move between providers.
- One binary, no runtime. C11, built with Make. Its only dependencies are vendored: SQLite with libfossil, zlib and BearSSL. It links libc, libm and pthread, nothing else.
- No state in loose files. pic's own state lives in SQLite: the journal per workspace and
~/.pic/pic.sqlitefor settings, the model catalog, trust decisions and the conversation lines that ctx archives.
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.
- Choosing one.
--theme NAME(or--use-theme) for one run; thethemesetting, set in/settings(Theme opens a picker that previews as you move and saves on enter) or withpic settings theme dark.light/darkpicks by the terminal, and so doessystem(the default): light whenCOLORFGBGnames a background of 7 or 9-15, else dark, as Pi decides. Text already printed to the scrollback keeps the colours it was drawn with. - Custom themes. JSON files in Pi's schema (
name, optionalappearance,vars,colors,export; colours as#rgb/#rrggbb,oklch(),okhsl(), a 0-255 index,""for the terminal's default, or a variable) in~/.pic/themes/*.json, and in the workspace's.pic/themes/only once it is trusted. They are read through the input reader. An invalid file is reported with Pi's messages (missing tokens, bad variables) and skipped; of two themes with one name the user's wins. pic does not generate Pi's terminal-palettesystemtheme. - Keybindings.
~/.pic/keybindings.jsonin Pi's format ({"app.exit": "ctrl+q", "tui.input.newLine": ["shift+enter", "ctrl+j"], "app.suspend": []}) uses Pi's 90 action names (plusapp.screen.redraw) and key syntax, with Pi's defaults except the Mac-friendly ones below (ctrl+shift+x,alt+enter,pageUp,f5,super+k; a value replaces the action's defaults and[]disables it; Pi's older action names are migrated)./hotkeysshows the effective bindings. pic warns about an invalid key (the action keeps its default), an unknown action, and a key two actions claim (Pi detects the conflict but shows no message). Actions that need views pic does not have (the session and model list filters, tree navigation, transcript search, semantic-prompt jumps) are accepted and do nothing. Alt+letter chords need the letter to be bound in the file (otherwise Esc followed by the letter is typed as before). - Defaults that differ from Pi. Pi's defaults assume keys a stock macOS Terminal or iTerm2 does not send (no End key, Option is not Meta, Shift+Ctrl chords are lost). Where that bites, pic's default is the key Claude Code uses for the same job, and Pi's stays as an alternate where it can; everything is overridable in
keybindings.json.
| 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.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+D needing a second press, Ctrl+R history search, 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).
/reloadre-reads the keybindings file, the theme files and the theme setting, along with the instructions, skills, templates and model catalog./forkwith no argument opens Pi's "Fork from Message" picker of your earlier messages: Enter forks the path before the chosen message into a new conversation and puts that message in the editor./fork ENTRYforks after an entry (seepic log)./changelogshowsCHANGELOG.md, compiled into the binary (src/changelog.inc, made by the Makefile). Add an entry under today's date inCHANGELOG.mdwith each landing, in words a user would use;makeregenerates the.inc, and the regenerated file is part of the change.
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:
- Lapse compaction.
--lapse on|off(PIC_LAPSE, settinglapseCompaction, default off) compacts before a request when the conversation has been idle longer than the prompt cache lives and its context is above a floor, since the cache is cold anyway. Idle time is the journal's clock less the end of the conversation's last reply. The lifetime defaults to the cache retention in effect: 300 s, 3600 s withcacheRetentionlong (86400 s for OpenAI's 24-hour retention), and never fornone; set it with--lapse-seconds(PIC_LAPSE_SECONDS,lapseSeconds). The floor is 20000 context tokens; set it with--lapse-floor(PIC_LAPSE_FLOOR,lapseFloorTokens). The compaction is journaled with reasonlapse, the idle seconds and the context's tokens (pic_generation.reason,idle_seconds,context_tokens), and its events are Pi'scompaction_startandcompaction_endwith"reason":"lapse". Forked conversations look idle, so leave it off for runs that replay them. - Trial labels.
--trial LABEL(PIC_TRIAL; 1 to 64 printable characters) is kept on every request the invocation admits (pic_submission.trial).pic usage --by-trial [--json]sums each arm's requests, input, output, cache read and cache write tokens, and cost, summary requests included. Pi's session format has no place for it on a message, so the Pi export leaves it out. - A request cap.
--max-requests N(PIC_MAX_REQUESTS) stops a request cleanly before it would send its (N+1)th reply request. Retries of one request count once, summary requests not at all, and the count comes from the journal, so recovery after a crash keeps it. The request ends with statusstoppedandstop_reasonrequest_cap, andagent_endcarries"status":"stopped","stopReason":"request_cap".pic ask -ccontinues the conversation.
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:
- Today, or a build flag away: Linux and macOS; a single static musl binary for any Linux (distroless containers, rescue systems); ARM and RISC-V boards and routers, fully offline against a local OpenAI-compatible model server; the BSDs and illumos; Android under Termux; a memory-safe build under Fil-C, which already passes every suite.
- Reachable through the interfaces: a microVM with no userland, pic as its only process and the project in SQLite, commands run on a separate runner (the optional no-OS build in the plan); unikernels such as Unikraft, OSv or Nanos; WebAssembly under WASI or in a browser tab, with the journal in browser storage and a
fetchor WebSocket transport; a Cloudflare Durable Object, whose built-in SQLite storage holds the journal. - With more porting: Windows natively (processes, the terminal and locking; WSL works today) and iOS, where there is no
fork, through WebAssembly or the remote runner.
Documents
- Implementation plan: stages, decisions in force, what comes next
- CI and remote runs
- Credential project
- Earlier design and qualification notes: contracts and evidence, durability contracts, provider contracts, feature map
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.