Code Mode explained: Where the '98.7% token savings' claim really comes from

AI agents like Claude Code no longer just call their tools one at a time. They write small JavaScript programs that bundle many calls together. We ran the numbers on how much that actually saves: a lot with huge APIs, not much in everyday coding. We also explain why control shifts from approving individual clicks to a script that hardly anyone reads.

Analysis Nov 21, 2026 11 min read Original analysis by our editors
Illustrative image, AI-generated

What this is about

An AI agent normally works like someone who needs every single move signed off: search, read the result, edit a file, read the result, run the tests, read the result. After each step, the entire conversation goes back to the language model so it can decide what to do next. The jargon for this is a round trip: one trip to the model and back.

Code Mode flips that around. The model writes a short program that calls several tools in sequence or in parallel, processes the intermediate results itself and reports back only the final result. Anthropic added the feature to Claude Code as an experiment on November 12, 2026, with version 2.1.323. Cloudflare, Docker Agent, OpenClaw and MCP gateways such as Bifrost use the same pattern.

Headlines love numbers like "98.7 percent fewer tokens." We checked where they come from. Our take: Code Mode saves a lot mainly with huge tool catalogs, and fairly little in everyday coding. And it shifts control from individual clicks to a script that hardly anyone reads.

How it works in Claude Code

According to the official documentation, in Code Mode Claude gets just one tool, called REPL. A REPL is a programming environment that accepts commands and runs them immediately. Bash, Read, Edit, Grep, WebFetch and MCP tools become JavaScript functions inside it. MCP (Model Context Protocol) is the standard agents use to hook into external tools. Here's the example from the docs:

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() });

The script searches, picks the first file, changes one line and kicks off the tests. That's three tool calls in a single round. Only the last line goes back to Claude. In the chat you still see the individual calls and diffs. What you don't see is the code itself. It sits collapsed in the transcript and you can only get to it with Ctrl+O.

You turn on Code Mode with the environment variable CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1. The requirements are steep: an interactive terminal, the native install of Claude Code and direct access to the Anthropic API. It doesn't work via Bedrock, Google Cloud, Foundry or gateways, and not in organizations with a HIPAA configuration or Zero Data Retention either. Code Mode also won't start if telemetry is disabled or OpenTelemetry export is active. Remote Control, Claude in Chrome and Computer Use are unavailable. If Claude is waiting on a script, it gets killed after ten minutes. In the background, a script can run for up to two hours.

The idea didn't originate with Anthropic. Cloudflare introduced it on September 26, 2025, under the title "Code Mode: the better way to use MCP." The reasoning at the time: language models have seen enormous amounts of real-world TypeScript in training, but only a handful of synthetic examples of tool calls.

"LLMs are better at writing code to call MCP than at calling MCP directly." (Cloudflare)

Where the big numbers come from

The savings figures come from very different scenarios. We checked the math:

Source What was measured Before → after Savings
Cloudflare (Feb 2026) Tool descriptions for more than 2,500 API endpoints, counted with tiktoken 1.17M → approx. 1,000 tokens 99.9%
Anthropic Engineering (Nov 2025) one MCP example, method not disclosed 150,000 → 2,000 tokens 98.7%
Bifrost/Maxim, round 1 96 tools, 6 servers 19.9M → 8.3M input 58.2%
Bifrost/Maxim, round 3 508 tools, 16 servers 75.1M → 5.4M input 92.8%
AIMultiple 63 tools, GPT-4.1, 50 runs per task 15,417 → 3,310 input per run 78.5% (input)
Anthropic Programmatic Tool Calling complex research tasks 43,588 → 27,297 tokens 37%

The math checks out: (1,170,000 − 1,000) / 1,170,000 gives 99.9%, and (150,000 − 2,000) / 150,000 gives 98.7%. But what's being measured varies widely. At its core, Cloudflare only compares the size of the tool descriptions: 2,500 endpoints as individual tools versus two tools, search() and execute(). Oddly, the same page says "over 2 million tokens" in its summary but 1.17 million in the body text. Anthropic's 98.7% comes from a blog post published on November 4, 2025. In it, a meeting transcript, for example, flows straight from Google Drive to Salesforce without ever passing through the model. The post doesn't say which task and which tools produced the number.

Bifrost shows most clearly where the savings come from. With Code Mode, usage stays almost flat: 5.5M tokens with 251 tools, 5.4M with 508 tools. Without Code Mode, it grows with every tool you add. So the savings depend mostly on how big the catalog is. Two caveats: Bifrost is a gateway made by Maxim, so the vendor is promoting its own product here. And the article doesn't say which model was tested.

The most independent test comes from AIMultiple. Input dropped by 78.5%, and total tokens by 77.4%. In return, output rose from an average of 87 to 192 tokens, 2.2x as much, because the model now writes code. Latency went up from 9.66 to 10.37 seconds, or 7%. AIMultiple says its estimated 70% cost savings are only extrapolated from token counts, not measured. And only two tasks were tested, with a single model.

You'll also often see an accuracy jump from 49 to 74% for Claude Opus 4 cited. But that figure belongs to Anthropic's Tool Search Tool, which loads tool descriptions only when needed, not to the code-based approach. For Programmatic Tool Calling, Anthropic reports smaller gains: from 25.6 to 28.5% on internal knowledge retrieval and from 46.5 to 51.2% on the GIA benchmark.

And in real-world Claude Code?

Anthropic hasn't published any savings or speed figures for Claude Code itself. All we have are individual runs by independent developers:

Test Input tokens Cost Time
wmedia.es (40 JSON files, Opus 5.5) 150,364 → 94,659 (−37%) n/a 15 s → 37 s
dev.to, Arindam (modify 8 services, v2.1.330) 264k → 140k read (−47%) $0.35 → $0.34 54 s → 16 s*
bestagent.dev, feature task cache reads roughly halved ≈$0.45 → ≈$0.35 ≈80 s → ≈60 s
bestagent.dev, 20 files with a version number smaller, but more cache writes unchanged 13–15 s → 13 s

*36 of the 54 seconds were the time the author needed to read a follow-up question.

The most reliable figure is the fixed tool block that ships with every request. According to wmedia.es, it shrinks from 24.6k to 11.1k tokens, a 55% cut. That explains a good chunk of the savings: Code Mode simply shortens the descriptions. Little of that shows up in costs, though, because prompt caching blunts the effect. With caching, the provider stores text it has already read and charges less for it the next time. In Arindam's test, the first Code Mode request wrote a lot into a still-empty cache, which is why the run cost practically the same. A claim making the rounds on X says Code Mode saves 37% and stretches usage limits by 1.6x. But that 37% comes from Anthropic's Programmatic Tool Calling API feature, not from Claude Code.

Our take: If you only have a few MCP servers connected in Claude Code, expect cost savings in the single digits to low double digits, not 98%. The benefit becomes noticeable with repetitive bulk work like link checks or making the same change across many files. For tasks where Claude genuinely has to think between steps, it barely helps.

The uncomfortable part: Who's checking the script?

The really new part is in Anthropic's docs, and it's stated pretty openly. In auto mode, a classifier, a second AI model, decides whether an action can run without asking you. In Code Mode, it checks each script once before it starts, not every individual call inside it. It also can't see values that only appear at runtime, such as a path from a search result. That means it can't fully assess a script like "delete everything the search finds." Anthropic recommends setting up your own rules or hooks for critical calls. Hooks are custom check programs that run before or after a tool call.

Three more issues on top of that:

  • Sandbox only for the shell: The sandbox is an isolated area that restricts what programs are allowed to do. It only applies to shell commands. According to the docs, "the JavaScript itself and its file, web and MCP calls" run outside it. If you want those parts isolated too, you have to run Claude Code in a container or a virtual machine.
  • Hooks see commands differently: A git push in the app folder reaches the hook as something like cd 'app' && git push. A hook that only looks at the start of the command will miss it. And as of v2.1.329, a call actually goes ahead by default after most hook errors. It's only rejected if the hook didn't finish, for example because of a timeout. If you run security hooks, you should set "onFailure": "block".
  • Redaction has gaps: A PostToolUse hook can redact the script's output before Claude reads it. But the refusedCalls field can echo rejected inputs back unchanged. In a GitHub issue opened on November 20 (#111259), a user also reports that in v2.1.329, mods don't get to see the script output at all. Mods are extensions that run their own code inside Claude Code. A script can assemble secrets on its own, for example via atob. Values like that could then reach the model unredacted.

Even if you want to approve every script with the rule "ask": ["REPL"], the prompt you get doesn't show the code. To read it, you have to expand it separately with Ctrl+O.

There's good news too. Every call in the script goes through the deny and ask rules and the PreToolUse hooks under its normal name. A cloned repository can't switch Code Mode on, because Claude Code ignores the variable in project settings. That matters, since tampered .claude/settings.json files have just recently served attackers as a way in. Admins can also lock Code Mode for the entire organization.

How others lock down the script

System Where the script runs Checks on inner calls
Claude Code in the Claude Code session, outside the sandbox yes, via rules and hooks
Cloudflare V8 isolate without fetch(), credentials stay with the supervisor permissions via OAuth scopes
Docker Agent embedded goja engine, no file, network or process access no, one approval covers the whole script
OpenClaw Node (not a security boundary, per the docs) or QuickJS yes, same as direct calls
Bifrost Starlark, no imports, no files, no network n/a

A V8 isolate is a tiny, sealed-off JavaScript environment that Cloudflare says starts in a few milliseconds. Docker itself warns that approving only the outer call is a serious problem with destructive tools. Still, a hard sandbox isn't a cure-all. An AWS Hero going by guyernest writes on dev.to: "Sandboxing is not the most important security boundary for Code Mode." If the script is allowed to call a destructive endpoint with valid credentials, even the best isolation won't protect you. Only permissions and rules at the interface itself can do that.

The bottom line

Code Mode is a sensible idea saddled with wildly inflated numbers. The 99.9% and 98.7% figures are calculated correctly, but they describe edge cases: thousands of API endpoints, or a transcript that doesn't have to pass through the model twice. The savings really do get big as the tool catalog grows, as Bifrost clearly shows. In normal Claude Code sessions, though, independent testers measure more like 34 to 47% less input and 0 to roughly 22% lower costs. In one case, the task took more than twice as long. All of these tests are single runs or very small samples.

Our take: The bigger shift is about control. Until now, you could see and approve each step individually. Now the classifier checks a program once, and what that program does depends on data the classifier never sees. And by default, you don't get to see the code. Anthropic handles this better than Docker, because the inner calls are still checked. But its own docs list several pitfalls, and hooks and approvals were patched across more than five versions within a single week. If you try Code Mode, use ask rules for risky commands, onFailure: block for security hooks and ideally a container.

#claude code#mcp#ai agents#security#code mode#tokens

Ask the AI assistant

Questions about this article, installation or background? Our assistant knows this page and runs on our own machine, not in someone else's cloud.

Connecting …

The Assistant is an AI (Gemma 4) and can make mistakes – please check important details against the source. Questions are used only to generate an answer and are deleted after one hour. Please don't enter any personal data.

Comments

What do you think? Already tried it? Write it here, no sign-up needed.

  1. Loading comments …

Comments are public. Links aren't allowed, and we delete abusive posts. You can delete your own comment at any time in this browser. Learn more in the Privacy Policy.