One tool call, step by step. Output stays in the sandbox.
Every tool call
Agent
Claude Code, Codex, Gemini CLI, Pi, and 6 more. Runs a tool.
Hook
PreToolUse denies a big Read and names the exact ctx_execute call. A hook failure ends in exit 0.
ctx_* MCP server
ctx_execute, ctx_batch, ctx_index, ctx_search, and 5 more tools.
Sandbox / SQLite FTS5
Code runs in a subprocess; its printed output returns. One context.db per project; BM25 and trigram.
When the host compacts
Compaction
The host fires PreCompact, or its own event. The hook reads the journal.
Snapshot
State block of 2,048 B at most. A long line becomes a ctx_resume(seq) pointer; every line stays whole.
Resume
Next prompt: a recall block of whole rows, 2,048 B at most. ctx_resume reads a full row.
Agent carries on
Same task, same files, small context.
small reply
Reading the figure. Top: a tool call goes through the hook to the MCP server; the sandbox and the index keep the raw output; a small reply returns. Bottom: the journal in context.db feeds the snapshot and the resume. "Sandbox" means output stays in the sandbox, out of the context. The code runs on your host as your user. Source: context-mode 2.0.0-next.20, src/core, checked 2026-11-01.