Code Mode in Claude Code is one environment variable: CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1. Set it, start claude in a terminal, confirm once, and Claude stops asking for tools one call at a time. It writes JavaScript that makes the calls and reads back only what the script returns.
Anthropic publishes no savings number for it. Independent testers have measured input-token drops from roughly 15% to 77%, depending almost entirely on what the task is. And one of those tests reportedly ran more than twice as slow with Code Mode on. Setup first, then the numbers, then what breaks.
What Claude Code Code Mode is
Per the Code Mode docs, Claude normally requests Bash, Read or Edit directly and reads each result before deciding the next step. With Code Mode on, it writes a piece of JavaScript that runs commands in parallel, feeds one result into the next call, and returns only the part Claude needs.
The feature shipped in Claude Code v2.1.323, which the changelog dates to November 12, 2026. The docs call it "experimental and off by default" and add that it "may change or be removed in any release". Take that literally. This post is accurate as of December 2026 and may not stay that way.
One thing changes on screen. You see the tool calls, such as an edit's diff, and not the code that made them. To read the code, press Ctrl+O and expand the Code row.
Setup: CLAUDE_CODE_EXPERIMENTAL_CODE_MODE
Check claude --version first. You need v2.1.323 or later, and v2.1.331 or later on Amazon Bedrock, Google Cloud or Microsoft Foundry.
To try it for one session:
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claudeTo turn it on for every new session, put it in ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1"
}
}It has to be the user-level file. Claude Code ignores this variable in a project's settings files, so a repo you clone cannot switch Code Mode on for you. That is a good default.
Claude Code asks you to confirm before the first Code Mode session, then restarts and shows this near the top:
Code Mode (experimental) is on · this session can be resumed only with Code Mode onIf you see Code Mode (experimental) isn't available, the reason follows on the same line and /status repeats it. The docs list 18 of them in a troubleshooting table, each with its fix.
The requirements that trip people most:
- Model: Claude Opus 5.5, Sonnet 5.5, Haiku 5.5 or Fable 5.2. Aliases such as
sonnetcan select older models on some providers. - Surface: an interactive
claudesession in a terminal. Not the VS Code panel, not the Desktop app, not cloud sessions. - Connection: no LLM gateway, no API key helper, and OpenTelemetry tracing off.
- Organization: not on the HIPAA configuration or zero data retention.
I tried the lazy route. On v2.1.332 I ran claude -p with the variable set, on a machine that had never confirmed the first-run prompt. The run started with the ordinary tools and no REPL tool in its list. No error, no notice in the output. That fits the interactive-only requirement, though my run cannot tell that apart from the missing confirmation. Either way, exporting the variable in CI does nothing by itself.
To turn it off, remove the variable or set it to 0. A 0 in any one place wins over a 1 elsewhere. An admin can put that 0 in managed settings to block it for an organization. There is no managed setting that forces it on.
Code Mode token savings: what people measured
The docs page gives no token or speed figure. Every number below belongs to the person who measured it, on their tasks.
The widest test I found is a benchmark posted to r/ClaudeAI: six tasks, four models, 192 runs on v2.1.326. The author reports 62 to 77% fewer tokens processed when totaling 120 records fetched through an MCP tool, 40 to 68% fewer when reading and judging the same records, and 15 to 54% fewer on file work Claude could already script, on three of the four models. Every Code Mode session started about 13,000 tokens smaller.
MindStudio's test averaged about 35% fewer input tokens across five runs. Then they priced cached tokens at their real rate and the saving fell to about 17%. Three of their five runs were slower with Code Mode on.
A developer in a T3 Code discussion ran five pairs of a coding task on Opus 5.5 and reports a median of 236k input tokens against 405k, and 31 seconds against 52. Their read-only task showed no gain: 36 seconds with Code Mode, 29 without.
Wavect's write-up of a test by Juan Andrés Núñez has the result that stuck with me. Ranking customers across 40 JSON files took 94,659 input tokens with Code Mode against 150,364 without. Same answer, 37% fewer tokens. It also took 37 seconds where the ordinary session took 15. I have only read the secondhand account of that one.
Three things fall out of these.
The big wins are on MCP-heavy work, where records stay inside the script and never enter the context. If you have already uninstalled most of your MCP servers, your ceiling is lower.
A chunk of the saving is fixed overhead, not cleverness. MindStudio measured the per-message tool list at about 60,000 tokens normally and about 38,000 with Code Mode. That saving shows up before Claude reads your prompt.
Fewer tokens is not the same as a smaller bill. Most of what Code Mode removes would have been cheap cache reads, which is why 35% became 17%. If cost is your reason, read what the cache really bills before you celebrate a token count.
I did not run a savings measurement of my own. A fair one needs paired interactive sessions and the first-run opt-in, and neither was available for this post.
What breaks: Code Mode hooks not working
This is the section to read before you turn it on in a repo with guardrails.
A hook that times out now refuses the call. Outside Code Mode, a PreToolUse hook that hits its timeout does not block, and the call carries on. In Code Mode the docs say to "expect a refused tool call when a PreToolUse hook doesn't finish". The error text is the hook did not finish. Raise the hook's timeout or set "onFailure": "continue".
A hook that crashes still lets the call through. On v2.1.329 or later, a hook that fails another way, such as a missing script, "goes on to permission checks". If the hook is a policy, set "onFailure": "block".
Your regex sees a different string. The docs' example: in Code Mode, a git push in a folder named app can reach your hook as cd 'app' && git push. A guard anchored to the start of the command misses it. Check each part of a compound command, the way Bash permission rules do. If you copied a guard from our hooks post, it greps anywhere in the string, so it survives this one.
UserPromptSubmit hooks lost a job. On v2.1.328 or later they no longer receive code output. If you scanned output there, move the check to a PostToolUse hook that matches REPL, the tool that runs the code. On earlier versions the opposite failure happens: the hook receives the output as a prompt and can block it.
Redaction fails open. A PostToolUse hook on REPL can return a cleaned copy as updatedToolOutput. If that hook crashes, times out or prints invalid JSON, the docs say "Claude gets the original output."
What changes for permissions and auto mode
In auto mode, the classifier reviews each piece of code once before it runs, not each tool call inside it. The docs spell out the gap: it "doesn't see values computed at run time, such as a path taken from search output".
So the path your script found by grepping is exactly the thing nobody reviewed. Deny rules, ask rules and PreToolUse hooks still fire per call under the tool's usual name. Keep them for anything you must control.
The sandbox covers less than you would guess. Sandbox settings apply to the shell commands the code runs. The JavaScript itself, and its file, web and MCP tool calls, run outside the sandbox.
To read every script before it starts, add an ask rule for the tool:
{
"permissions": {
"ask": ["REPL"]
}
}The prompt does not include the code. You press Ctrl+O to read it, then answer.
Limits that will bite later
- A Code Mode session resumes only with Code Mode on. Unset the variable and
claude --resumerefuses it. - Code that Claude waits on stops after ten minutes. Background code gets up to two hours, and only in sessions started in auto or
bypassPermissionsmode. - No Remote Control, no Claude in Chrome, no computer use.
- You cannot move the session to the Desktop app or turn it into a background session.
The changelog is honest about how young this is. Fixes between v2.1.329 and v2.1.332 include a runaway loop "filling the machine's memory" and Code Mode "silently skipping a tool call whose input has a list of over 4,096 items".
Should you turn Code Mode on?
Yes for bulk, mechanical work: the same change across many files, a search that needs filtering, anything that pulls lots of records through MCP tools. That is where the measured Code Mode token savings are large and repeatable.
No, or not yet, for short read-only questions, for sessions you need to resume anywhere, and for repos where a PreToolUse hook is your only guard. Fix the hook's failure behavior first, then set CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 for one session and compare /usage against a normal run on the same task. Your number will not match anyone else's. For cheaper wins that need no experimental flag, trimming what you load into context still pays.