One round per action
Editing 20 files means dozens of round trips between Claude and its tools.
Does Code Mode really cut 90% of tokens? Anthropic added it to Claude Code this month.
Early numbers people report:
Same LLM, same task, far fewer tokens.
Normally Claude Code uses tools one call per action: reading a file is a call, editing a file is a call, running a command is a call.
With Code Mode on, Claude writes a piece of JavaScript that calls the tools and does it all in one go. No repetition.
Say you ask Claude to edit 20 files.
The old way: Claude edits them one by one, reports back after each, and every report takes up room in memory.
Code Mode on: Claude writes one short script and the machine runs through all 20 files. No memory spent.
Simplified illustration; the old way is set to 100. These are not measured numbers; real savings depend on the task.
Three reasons, and they compound.
Editing 20 files means dozens of round trips between Claude and its tools.
File contents and command output are all handed to Claude, even when it needs just one line.
On every new round, Claude re-reads the whole conversation. It gets pricier as it goes.
Tools, MCP, context window and tokens: each is a cost that shrinks when Code Mode is on.
Every read, edit or command is its own round. Editing 20 files takes about 20 rounds.
One script makes all 20 calls. Claude thinks for just 1–2 rounds.
Every Gmail, GitHub or Notion call is a round, and long raw JSON lands in the conversation.
Code calls MCP in a loop, filters the JSON and returns only what's needed. Tool descriptions get leaner too (one test: 24,600 → 11,100 tokens).
File contents, logs and search results fill memory. When it's full, Claude compacts and forgets earlier work.
Intermediate data lives in code variables, not in memory. Sessions run longer before compaction.
Every round resends the full history, so tokens compound with each round.
Fewer rounds plus a smaller memory means far fewer tokens. Bonus: faster, because independent tasks run in parallel.
The idea isn't new: Cloudflare introduced "Code Mode" for MCP in 2025, and Anthropic wrote about it in "Code execution with MCP". This time it ships inside Claude Code itself.
With Code Mode on, Claude stops calling Read, Edit or Bash directly. Everything goes through these two tools.
Claude sends a piece of JavaScript; the REPL runs it right in your Claude Code session.
Inside the code, Claude calls file reads, edits, shell commands and MCP tools like functions, with loops, conditions and parallel runs.
What comes back to Claude is the value the code returns, not all the data that passed through.
Each run is capped at 10 minutes. Longer work moves to the background, up to 2 hours.
When code runs long, Claude doesn't sit and wait; it can do other work or answer you.
Claude calls Poll to get progress or the result once the code finishes.
Full test suites, builds, big data processing, syncing thousands of records.
The official docs only describe REPL. The Poll details come from community write-ups.
oldApi."// The REPL runs this. Function names are illustrative.
const files = await glob("src/**/*.ts");
const hits = [];
for (const f of files) {
const text = await read(f); // 300 files read here...
if (text.includes("oldApi(")) hits.push(f);
}
return `${hits.length} files: ${hits.join(", ")}`; // ...one line back to Claude
You need Claude Code v2.1.323 or later, running in a terminal. It's off by default.
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude
$env:CLAUDE_CODE_EXPERIMENTAL_CODE_MODE = "1"
claude
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1"
}
}
The first time, Claude Code asks you to confirm; pick "Yes, turn on Code Mode". It doesn't yet work in VS Code, the Desktop app or cloud sessions. A Code Mode session can only be resumed with Code Mode still on.
Rule of thumb: requests with words like "all", "every", "bulk", "filter", "count" are usually good fits for Code Mode.
getUser to fetchUser across the repo."Code Mode: finds the 40 files with the old name, edits each in a loop, runs typecheck, reports only the file list and the check result.
The contents of 40 files never enter memory.
Code Mode: reads a log tens of MB in size, groups errors by type, counts them and returns the top 5.
The whole log never passes through Claude, only the summary.
Code Mode: runs all three commands at once and keeps only the error lines.
Faster, and thousands of output lines stay out of memory.
Code Mode: scans the repo, counts per directory and returns a small table.
Hundreds of search hits become a few lines.
Gmail MCP: code pulls 500 emails, filters by sender and reply status, and returns the 8 that need attention.
500 emails of JSON never hit the conversation.
bug."GitHub MCP: lists issues, filters them and labels 30 in one loop.
30 calls packed into one script instead of 30 rounds.
Database MCP: runs 12 queries, merges them into one table and returns the summary.
Only the final table reaches Claude, not 12 raw results.
Notion + CRM MCP: reads from Notion, writes each record to the CRM, returns the count synced and any errors.
For long jobs it runs in the background and Claude uses Poll to check progress.
// MCP function names are illustrative.
const mails = await gmail.search({ query: "newer_than:7d", max: 500 });
const pending = mails.filter(m =>
m.from.endsWith("@customer.com") && !m.replied
);
return pending.map(m => `${m.from}: ${m.subject}`); // 8 lines instead of 500 emails
You don't need Code Mode for: fixing one bug in one file, asking for an explanation of some code, or work you want to approve step by step.
The more repetitive the job, the bigger the drop. One- or two-step tasks barely change.
| Test | Result |
|---|---|
| Code Mode on vs off on the same task Community video tutorial, single run |
~90% less context |
| Tool descriptions measured with /context Community test, single run |
24,600 → 11,100 tokens (−55%) |
| Moving data Google Drive → Salesforce Anthropic, 2025. Same idea, not yet Code Mode |
150,000 → 2,000 tokens (−98.7%) |
| Creating 31 calendar events Cloudflare's Code Mode demo |
~81% fewer tokens |
Anthropic has not published an official figure for Code Mode. These are one-off tests; treat them as a reference and measure on your own work.
The deny and ask rules you already set still govern each call made from the code.
Add an ask rule for REPL so Claude must ask before running code.
Project settings are ignored, so downloading code never turns Code Mode on for you.
Claude Code's sandbox is a cage that limits folders and network. With Code Mode on, shell commands from the code stay in the cage, but file reads/writes, web access and MCP calls from the JavaScript do not. Permission rules still apply; for full isolation, run Claude Code in a container or VM.
Instead of one line like rm -rf build, you review a whole script with loops and conditions. In auto mode, the check looks at the code before it runs, so it can't see values that only appear at run time (see the example below).
Anthropic says plainly it may change or be removed in any release.
const folder = await read("config.txt"); // only known at run time
await $`rm -rf ${folder}`; // "build" is harmless, "/" is a disaster
| Code Mode off | Code Mode on | |
|---|---|---|
| Sandbox | Wraps every shell command | Wraps shell commands only; file, web and MCP calls from code are not |
| Manual review | Read one command, easy | Read a whole script, harder |
| Auto check | Checks each action | Checks the code before it runs; can't see run-time values |
Tip: for unfamiliar repos or sensitive work, run Claude Code in a container, or add ask rules for dangerous commands like Bash(rm *) and Bash(git push *).
The same change across many files, searches whose results need filtering, several independent commands at once.
One- or two-step tasks, or risky actions you want to approve step by step, like deleting data or pushing to production.
Code Mode doesn't make the AI smarter. It lets the AI write code instead of calling tools one by one, so there are fewer round trips and the memory isn't stuffed with results nobody needs.
If you use Claude Code with many files, large data or several MCP servers, it's worth a try. Turn it on for one repetitive task, measure with /context, and decide for yourself.