A session grows. The context stays small.
Every tool call
Tool call
The agent runs Read, Bash, WebFetch or an MCP tool.
PreToolUse hook
Sends a big call to ctx_execute or ctx_index.
Sandbox / index
ctx_execute runs the code; ctx_index keeps the full output.
When the host compacts
Compaction
The host fires PreCompact, or its own event.
Snapshot
The task, files and last steps, in 2,048 B at most.
Resume / search
ctx_resume reads a full row; ctx_search finds the rest.
context.db
One SQLite FTS5 file per project, on your disk. BM25 and trigram search.
Index: every full output, searchable
Journal: each step of the session
Snapshot: the state at each compaction
small reply
274.7 KB → 3.4 KB
Debugging session, 8 outputs and 3 searches. Row g-session-total.
432.5 KB → 2.0 KB
Long session, 40 outputs, then compaction. ctx_resume block. Row e-long-session.
651.2 KB → 15.3 KB
One large log. The full copy stays searchable. Row d-synth-1m.
Reading the figure. Top: the hook sends a tool call to the sandbox or the index; the full output goes into context.db and a small reply returns. Bottom: at compaction a snapshot keeps the state, and the agent reads it back. Numbers: raw output against bytes in the context, median of 5 runs, bench/results/2026-10-31-darwin-arm64.json (context-mode 2.0.0-next.8).