Agents

Claude Code Code Mode: When It Saves Tokens

Code Mode lets Claude chain tool calls in JavaScript. Anthropic published no savings figure. How it works, when to try it, and which viral numbers to ignore.

Code Mode is an experimental setting in Claude Code that changes how the agent uses tools. Instead of asking for each Bash, Read or Edit call and reading the full result before the next step, Claude writes a short JavaScript program. Claude Code runs that program in your session. The program can chain calls, run some of them at the same time, and hand Claude only the output it needs.

Anthropic has not published a token-saving figure for Code Mode. A viral claim of an “85% token cut” refers to a different, older technique, not this feature. What you can count on is the mechanism, a clear list of limits, and a way to measure the difference on your own tasks.

How Code Mode works

You still describe the task in plain language. With Code Mode on, Claude’s next step is code, not a single tool request. Official docs say one piece of code can run commands in parallel, feed one result into the next call, and return only the part Claude needs to read.

Anthropic’s documentation uses this example. The job is to raise a retry limit. The code finds the file, edits it, and runs the tests. The last line returns the path and the test output to Claude:

const files = await $`rg -l "function retryPolicy" src`.text();
const target = files.trim().split("\n")[0];
await edit(target, "maxAttempts: 3", "maxAttempts: 5");
({ edited: target, tests: $`npm test -- retryPolicy`.nothrow() });

In the conversation you see the tool calls, such as the edit’s diff, not the JavaScript. To read the code, press Ctrl+O to open the transcript viewer and expand a collapsed Code row.

That return step is the point of the design. In ordinary tool use, intermediate output often lands in the model’s context even when Claude only needed a path, a count, or a test summary. Our explainer on what long context really costs covers why those extra tokens add up on every later turn.

When Anthropic says to try it

The official docs recommend Code Mode for tasks that take many related tool calls, such as:

  • A change that repeats across many files
  • A search whose results need filtering before Claude reads them
  • Several independent commands that can run at the same time

A short, one-file edit is a poor first test. A repo-wide rename, a sweep for broken local links, or a script that summarizes many data files is a better one. Clearer task instructions still help, Code Mode or not. See our guide to writing AI agent instructions that work. Code Mode also will not help much if the slow part is Claude’s reasoning rather than a long trail of tool results, and it can be slower on a small task because Claude has to write a program first.

What the token numbers actually say

Three figures get mixed together online. Only one of them is a measurement of Claude Code’s Code Mode, and that one is a single third-party test, not an official result.

Anthropic has not scored Code Mode

The Code Mode documentation and the Claude Code changelog describe the feature and its limits. They do not give a percentage, a before-and-after token count, or a speed claim. Treat any “Code Mode saves X%” headline as unverified unless it names a test you can read.

The “85%” figure is about Tool Search, not Code Mode

On November 24, 2025, Anthropic published “Introducing advanced tool use”. There, the Tool Search Tool loads tool definitions on demand. Anthropic’s example goes from about 77,000 tokens of context before work begins to about 8,700 tokens with Tool Search, “an 85% reduction in token usage.” That is a different product, from a year earlier, aimed at large tool libraries. It is not a Code Mode benchmark.

The 150,000-to-2,000 example is about MCP code execution

A related Anthropic post, “Code execution with MCP” (November 4, 2025), gives an example in which token use falls from 150,000 to 2,000, a 98.7% saving. That example is about MCP tool definitions in a code-execution setup, not Claude Code’s later Code Mode feature. The same November 2025 advanced-tool-use post also reports that Programmatic Tool Calling, a Claude API feature that uses Python, cut average usage from 43,588 to 27,297 tokens on complex research tasks, a 37% reduction. That number belongs to the API feature, not to Code Mode.

One paired test of Code Mode itself

On November 13, 2026, wmedia.es published a paired run on Claude Code v2.1.323. Both sessions used Claude Opus 5.5 at medium effort. The task was to find which three customers spent the most on paid orders across 40 daily JSON files. The only planned difference was Code Mode. The author reported:

Without Code Mode With Code Mode
Requests to the model 4 4
Input tokens, first request 36,404 22,233
Input tokens in total, cache included 150,364 94,659
Output tokens 1,172 1,213
Time 15 seconds 37 seconds
Answer initech, umbrella, acme initech, umbrella, acme

That is 55,705 fewer input tokens, or about 37% of the baseline input, across four requests. The author is clear that one run each is not a benchmark, and that Code Mode was slower on this task. The ordinary session also wrote a script, in Python through Bash, so the saving did not come from “using a script versus not.” The author traced most of the difference to fixed tool context: after the first reply, /context showed system tools at 24.6k tokens without Code Mode and 11.1k with it. In that write-up, the model got two tools, REPL and Poll, with the rest described more briefly as JavaScript functions. Use the table as one documented example, not a promise for your repo. Cached input is cheaper than fresh input, output ticked up slightly, and a different task could shrink or wipe out the gap.

How to turn Code Mode on

Code Mode is off by default. You opt in, then confirm once.

  1. Check your version with claude --version. You need v2.1.323 or later, or v2.1.331 or later on Bedrock, Google Cloud’s Agent Platform or Foundry. If you’re older, run claude update. If you’re on the stable channel and the update has not reached the version you need yet, wait or switch to the latest channel.
  2. Start a session with the environment variable set to 1. In a macOS, Linux or WSL terminal:
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude

In Windows PowerShell:

$env:CLAUDE_CODE_EXPERIMENTAL_CODE_MODE = "1"
claude

To turn it on for every new session, put this env block in ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1"
  }
}

Claude Code ignores this variable in a project’s settings files, so a repository you clone cannot turn Code Mode on for you.

  1. On the first Code Mode session, confirm the prompt. Select “Yes, turn on Code Mode.” Claude Code restarts and should show a line such as: “Code Mode (experimental) is on ยท this session can be resumed only with Code Mode on.” Give Claude a task with many tool calls (the docs suggest listing local Markdown links that don’t exist), then press Ctrl+O and expand a Code row to see the JavaScript.

To resume later, keep the variable set to 1 when you run claude --continue or claude --resume. With Code Mode off, Claude Code refuses to resume that session. Sessions started without Code Mode stay without it, even if the variable is set. To turn it off, remove the variable or set it to 0 in your shell or in ~/.claude/settings.json, then start a new session. A 0 in one place keeps Code Mode off even if the other place is set to 1. Organization admins can put a 0 in managed settings to block it. They cannot force it on.

Requirements and limits

Before you plan a workflow around Code Mode, check that you can live with the official limits. The feature is experimental and can change or be removed in any release. Anthropic asks for feedback through /feedback.

  • Version: Claude Code v2.1.323 or later, on either release channel. Some setups need newer builds: v2.1.326 for agent teams, v2.1.327 for a mod that hooks tool calls, v2.1.329 if feature-flag fetching is off or OpenTelemetry events and metrics are on, and v2.1.331 for a cloud provider. Teammates run in Code Mode in the default in-process display mode, and start without it in split panes.
  • Account or provider: a Claude subscription, a Console account, or, from v2.1.331, a cloud provider such as Amazon Bedrock, Google Cloud’s Agent Platform, or Microsoft Foundry. It does not work through a gateway or with Claude for Government. If you reach a cloud provider through an Enterprise Admin Console sign-in, you need Agent Platform, or Bedrock without the Mantle endpoint.
  • Organization: not available if your organization uses the HIPAA configuration or zero data retention.
  • Model: Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2. On a cloud provider that uses deployment names, check that yours points to one of these models.
  • Surface: an interactive claude session in a terminal, on the native build. It does not work in the VS Code panel, the Desktop app, or cloud sessions. Windows needs Git for Windows.
  • Features you lose in that session: Remote Control, Claude in Chrome, and computer use. You cannot move the session to the Desktop app or turn it into a background session, and /fork cannot start a background copy. A Code Mode session that ran on a Claude subscription or Console account cannot be resumed later on a cloud provider such as Bedrock.
  • Time limits: if Claude waits for the code, it stops after ten minutes. From v2.1.328, time spent at a permission prompt in Manual and acceptEdits modes does not count toward that limit. Background code can run for up to two hours while you keep talking to Claude, if you started the session in auto or bypassPermissions mode.
  • Auto mode: the classifier reviews each piece of code before it runs, not each tool call inside it. Official docs note that it does not see values computed at run time, such as a path taken from search output. Your usual deny and ask rules, and PreToolUse hooks, still apply to each tool call under its usual name, such as Bash. By default, expect a call to be refused if its PreToolUse hook does not finish, and to still run if the hook fails another way; set "onFailure": "block" on a hook that must refuse.
  • Subagents: if a subagent has a tools list, add REPL to it so that the subagent uses Code Mode.

Some settings still prevent Code Mode from starting. The official troubleshooting table includes an API key helper or an Authorization header on a direct connection to Anthropic, a gateway or proxy set up in place of a direct connection, and OpenTelemetry tracing, which keeps Code Mode off on any version. Turning off feature-flag fetching (for example with DISABLE_TELEMETRY) or turning on OpenTelemetry events and metrics blocked it on older builds; from v2.1.329 both work. If you see “Code Mode (experimental) isn’t available” at the top of a session, the rest of that line is the reason. Fix that setting, then start a new session.

How to measure it on your own work

The useful question is not “how many tokens does Code Mode save in general?” It is whether the job finishes correctly, in less paid context, without getting slower in a way you care about. That is the same habit we recommend in how to test an AI feature: same task, one change at a time, recorded results.

  1. Pick 5 to 10 real tasks from a project you know, the kind with many tool calls.
  2. Run each twice, once with Code Mode off and once with it on, in fresh sessions, on the same model and effort level.
  3. After Claude’s first reply, run /context and note the system-tools line. Compare total input tokens, output tokens, cache reads if your plan shows them, elapsed time, and whether the answer was right.
  4. If you pay for tokens through the Console, look at the bill for those runs. If you use a Claude subscription, look at how much of your usage window the same work consumed. Do not convert a single blog test into a monthly savings figure.

Code Mode is a different way to call the same tools, not a substitute for deciding what an agent should be allowed to do. For a broader picture of where agents help and where they stall, see what AI agents can do today.

Key takeaways

  • Code Mode is an experimental, opt-in Claude Code feature, added in v2.1.323, in which Claude writes JavaScript that chains tool calls and returns selected results.
  • Anthropic has not published a token-saving figure for it. The widely shared “85%” reduction is from the Tool Search Tool in 2025, not from Code Mode.
  • One third-party paired test on Opus 5.5 saw input tokens, cache included, fall from 150,364 to 94,659 over four requests, while the Code Mode run was slower. That is one task, one run each, not a benchmark.
  • It is worth trying on multi-file, filter-heavy, or parallel tool work in an interactive terminal. It is not available in VS Code, Desktop, cloud sessions, or through a gateway. Bedrock, Google Cloud’s Agent Platform and Foundry work from v2.1.331.
  • Measure it on your own tasks with /context and a side-by-side log before you change a team default.

Sources: Anthropic, “Run tool calls from code with Code Mode”; Claude Code changelog (Code Mode added in v2.1.323; agent teams in v2.1.326; feature-flag-off and OpenTelemetry events and metrics allowed in v2.1.329, tracing still blocks it; cloud providers added in v2.1.331); Anthropic, “Introducing advanced tool use” (Nov 24, 2025); Anthropic, “Code execution with MCP” (Nov 4, 2025); wmedia.es, Code Mode token test (Nov 13, 2026); MarkTechPost (Nov 17, 2026); Dataconomy (Nov 19, 2026).

Kabeer Ahmed

Kabeer Ahmed is the founder and editor of The AI Year, where he explains AI tools, models, agents and AI security in plain English. He works on AI automations for businesses and is the founder of Runnex Logistics and of Aurel Digitals, a web design and automation agency. He writes practical guides for people using AI at work, covers selected news with links to primary sources, and reviews every post before it's published. Reach him at hello@theaiyear.com or on LinkedIn: https://www.linkedin.com/in/kabeerahmed09

Keep reading