Source: Claude Code documentation, Run tool calls from code with Code Mode (code.claude.com/docs/en/code-mode), announced by Addy Osmani of the Claude Code team, Nov 2026. Experimental and off by default; may change or be removed.
The idea
A standard coding-agent loop is one tool call per model turn: run a search, read the full result into context, decide, run the next call. For work with many related calls, that wastes model turns and context on raw output the model only needs to filter.
In Code Mode the model writes a short JavaScript program that makes the tool calls itself: run commands in parallel, feed one result into the next call, and return only the part the model needs to read. The docs' example finds a file with ripgrep, edits a constant and runs the matching tests, then returns just the path and test output.
This is the "code as the action space" pattern applied to a production coding harness: the tools become functions in a scripting environment, and the model's action is a program, not a single call.
How it fits the harness
A tool that runs code. The program runs through a tool named
REPLin the user's session. It exposes the usual tools (shell, edit, file, web, MCP) as callable functions.Visibility. The transcript shows the resulting tool calls (for example the edit's diff). The JavaScript itself is collapsed and can be expanded in the transcript viewer.
Permissions still apply per call. Each tool call inside the program goes through the deny and ask rules and
PreToolUsehooks under its normal tool name. In auto mode, the safety classifier reviews the program, not each call, and cannot see values computed at run time, such as a path taken from search output. Hard limits therefore belong in rules, hooks or the sandbox, not in the classifier.Gating the program. A
PreToolUsehook onREPLcan read the JavaScript before it runs. Anaskrule onREPLmakes every program wait for human approval.Gating the output. A
PostToolUsehook onREPLcan redact the program's result before the model reads it, for example to strip a token from a file it read. The docs warn that refused calls can echo their input unredacted.Sandbox scope. Sandbox settings cover the shell commands the program runs. The JavaScript itself, and its file, web and MCP calls, run outside the sandbox. Full isolation needs a container or VM.
Long-running work. By default a program blocks and stops after ten minutes. In auto or bypass-permissions mode it can run in the background for up to two hours while the conversation continues, managed with
/tasks.Shell-rule subtlety. A hook that allows or blocks shell commands must parse compound commands. From a program, a push inside a subfolder can arrive as
cd 'app' && git push.
Requirements and limits
It runs in an interactive terminal session only, on the native build of a recent version, against the direct API with a subscription or Console account, on the current model families. It is not available through cloud providers or gateways, with API key helpers, with OpenTelemetry export, under HIPAA or zero-data-retention configurations, in the IDE panel, the desktop app or cloud sessions. It is incompatible with remote control, browser control and computer use. A Code Mode session can only be resumed with Code Mode on. Administrators can block it in managed settings, and a project's own settings file cannot turn it on.
Tradeoffs
Fewer turns and less context vs less inspectable steps. One program replaces many visible decisions. The model no longer re-reads intermediate output, which is the point, but a human reviewing the transcript sees calls, not the reasoning that chained them.
Classifier sees intent, not values. Reviewing code before it runs cannot judge data-dependent paths. Anything that must never happen needs a deterministic rule.
Parallelism vs ordering bugs. Programs that fan out edits or commands introduce the usual concurrency mistakes a one-call-at-a-time loop avoided.
Background runs vs attention. Two-hour background programs free the conversation but can keep making tool calls while the user is doing something else.
Platform constraints. It is incompatible with several enterprise setups (gateways, telemetry export, ZDR), which limits where teams can adopt it.
Failure modes
A program edits many files from a search result that matched more than intended, and the error is only visible in the aggregate diff.
A token read by the program reaches the model because the redaction hook crashed or returned the wrong shape. The docs say the original output passes through in that case.
Shell allow-lists that match on the command prefix miss compound forms generated by programs.
Background programs left running after the user moves on, still holding permissions.
Review checklist
Are critical denials expressed as rules or sandbox policy, not left to the classifier?
Do shell-command hooks parse every part of compound commands?
Is there a
PostToolUsehook onREPLfor secrets, and does it fail closed?For bulk edits, does someone read the full diff, not just the final summary?
Is the session in a container or VM if file, web and MCP calls need isolation too?
Are background tasks visible and stopped at the end of the work?
Related entries
R139 (Claude Code practices that moved off the user's plate as the harness matured).
R132 (folding subagents into the main loop with progressive disclosure).
R182 (how the Claude Code team verifies agent-written code).
R071 (a gateway turning thousands of services into agent tools).
R201 (where agent token cost actually goes).