Artifact fce9ba075f435b6a16bdb965cfd38330f1c7503bb2a772ec083ad577eca72668:
- File README.md — part of check-in [dc279ade3b] at 2026-11-20 16:39:01 on branch pic-ps — Merge trunk (ctx benchmark pieces) into pic-ps (user: dmestas, size: 10425) [annotate] [blame] [check-ins using] [more...]
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.
- 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. pic never stores a key.
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 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
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.
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.