Programs (codemode)
With the codemode tool, the model can write a short JavaScript program that calls Tatu’s other tools. Instead of fifty separate tool calls whose results all land in the conversation, it makes one call, and only what the program prints comes back. It is faster and uses fewer tokens.
For example, ask:
List every TODO in the Go files, group them by package and tell me which package has the most.The model may write a program that searches the project, counts the matches in a loop and prints one short table. You see one Codemode(...) block with the tool calls it made under it:
⏺ Codemode(// count the TODOs per package) ⎿ Done · 3 tool calls · 1.2s Grep(TODO) Find(*.go) Read(internal/core/agent.go) 1.4s internal/core 14 internal/tui 9How it works
Section titled “How it works”- The program runs in an isolated sandbox. It has no file system, network or timers of its own: it reaches the outside only through tools, which are the tools the model already has.
- Each tool call a program makes goes through your hooks like a call the model made itself. A hook that blocks
bashblocks it inside a program too. - Calls that only read run together when the program starts them together. Calls that change files or run commands run one at a time.
- Press Ctrl+O to see every call and the whole output. Esc stops a program that is running, and the calls it started are cancelled.
- A program can keep small values for the next one with
storeandload. They belong to that branch of the conversation and come back with/resume. - By default a program may run for five minutes and print about 10,000 tokens to the model. A longer output is cut, and the whole of it is kept in a file in the temporary folder, with its path in the result. The program can change both limits on its first line:
// @options: {"timeout_ms": 60000, "max_output_tokens": 20000}.
The model decides when a program is worth it. For one or two calls it calls the tools directly, so you see each step.
Tools from MCP servers
Section titled “Tools from MCP servers”The tools of MCP servers can stay out of the model’s tool list and be reached only through programs. That keeps the list short when you connect many servers: the model searches for the tools it needs (searchTools) and calls them from a program. Tatu decides this by itself by default, and exposure in mcp.json lets you choose it for each server or tool.
Limits and cautions
Section titled “Limits and cautions”- Programs cannot call
plan_writeorplan_update. The model calls these tools directly so your plan and its progress stay recorded in the conversation. - A program that fails after some calls does not undo them. The result lists the calls that were made, so you and the model can see what changed.
- The sandbox limits memory and time. A program that loops forever or uses too much memory fails with an error instead of freezing Tatu.
- Programs are written by the model, like any tool call: read the calls under the block when the work matters.
- Turn the tool off with
"codemode": { "enabled": false }in your settings. Tools of MCP servers are then all given to the model directly, whatever theirexposuresays. - Subagents of the general-purpose type can write programs over their own tools. A custom subagent gets the tool only if its
toolslist namescodemode.