codemode for Claude Code: a bridge to Pi's code mode
Code mode for Claude Code: one tool that lets the model write a JavaScript script that calls the session's own tools (Read, Bash, Write, Edit, the MCP resource tools, and the session's MCP tools), and returns only the script's output. Many tool calls become one, and large intermediate results stay out of the context window.
Inspired by Pi's codemode, by Earendil. Earendil's post "You Said No MCP!" explains the idea and why it works, and Armin Ronacher's "What is Codemode" describes it from the harness side. This project does not reimplement it. It is a bridge: it runs Pi's own script runtime, @earendil-works/pi-codemode (QuickJS in WebAssembly), and connects each tools.* call the script makes to Claude Code's own tool call. Your permission rules, prompts and hooks still apply to every one of them, and a script written for Pi's codemode reads the same here.
Status: pilot (v0.13.0). It exposes Read, Bash, Write, Edit, the three MCP resource tools, WebFetch, WebSearch, and every MCP tool connected in the session. The design is in ADR 0001, which is still Proposed. The bridge overhead and the task-level savings are measured — see Benchmarks and issue 0005.

The prompt never mentions codemode. Claude writes one script that runs git ls-files, reads five files in parallel with Promise.allSettled, and keeps only the TODO lines. The nested calls are listed live as they run, and only the script's output returns to the model.
What it is and where it shines
What it is: one tool, codemode. The model sends a short JavaScript script. The script runs in a sandbox and calls the session's tools as tools.Read(...), tools.Bash(...), tools.Write(...), tools.Edit(...), the MCP resource tools (tools.ListMcpResourcesTool(...), tools.ReadMcpResourceTool(...), tools.ReadMcpResourceDirTool(...)), the web tools (tools.WebFetch(...), tools.WebSearch(...)) and tools.mcp__server__tool(...). Only what the script prints returns to the model. Every nested call still meets your permission rules, prompts and hooks.
What it is for: work that takes many tool calls, where each call needs a model turn and each result fills the context.
Where it shines:
- Batching: read or search many files at once with
Promise.allSettled, instead of one call per file.
- Filtering: keep the matching lines and drop the rest, so a large result never reaches the context window.
- Chaining: use the result of one call as the input of the next, such as a
git listing followed by a read of each file, in one turn.
- MCP tools: call several tools of a server, or of different servers, from one script.
Where it does not: a single command, such as one git grep. Claude still calls Bash directly, which is the right choice.
Benchmarks
Measured with no model in the loop (node scripts/overhead.ts, 15 runs per size): the bridge costs ~98 ms to open (child start, sandbox, socket, close) and ~0.1–0.3 ms per nested call — 100 sequential calls add ~3 ms, within run-to-run noise. The bridge is expensive to open and nearly free to use.
The same tasks, with and without the plugin (node scripts/savings.ts, 2026-10-06, Claude Code 2.1.292, claude-opus-5-5, 3 runs per side after one discarded warm-up, medians over all-correct runs, the prompt never naming codemode):
| Task | Turns with / without | Cache-read tokens with / without | Output tokens with / without | Cost with / without |
|---|
| read 5 tracked files, report their TODOs | 2 / 7 | 38,188 / 54,286 | 574 / 966 | $0.023 / $0.039 |
git log → read each changed file | 2 / 4 | 38,222 / 55,041 | 443 / 414 | $0.021 / $0.024 |
| write 3 files | 6 / 8 | 111,935 / 93,581 | 1,229 / 1,321 | $0.062 / $0.059 |
one git grep | 2 / 2 | 38,329 / 32,780 | 164 / 259 | $0.011 / $0.029 |