AI Writings · Claude Code

Code Mode: 90% fewer tokens.

Does Code Mode really cut 90% of tokens? Anthropic added it to Claude Code this month.

Status Experimental Updated 11/2026 Read ~5 min

Early numbers people report:

  • ~90% less context on the same task
  • 150,000 → 2,000 tokens (−98.7%) moving data from Google Drive to Salesforce
  • ~81% fewer tokens creating 31 events

Same LLM, same task, far fewer tokens.

01 · The idea

What is Code Mode?

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.

Illustration
Same job: edit 20 files

Code Mode off
Claude Tool
Round trips0
Tokens spent0
Code Mode on
Claude Script
Round trips0
Tokens spent0

Simplified illustration; the old way is set to 100. These are not measured numbers; real savings depend on the task.

02 · The problem

Why does the old way burn tokens?

Three reasons, and they compound.

1

One round per action

Editing 20 files means dozens of round trips between Claude and its tools.

2

Every result goes into memory

File contents and command output are all handed to Claude, even when it needs just one line.

3

Each round re-reads the last

On every new round, Claude re-reads the whole conversation. It gets pricier as it goes.

03 · Where it saves

Four places Code Mode saves.

Tools, MCP, context window and tokens: each is a cost that shrinks when Code Mode is on.

01 · Tools

Number of tool calls

Off

Every read, edit or command is its own round. Editing 20 files takes about 20 rounds.

On

One script makes all 20 calls. Claude thinks for just 1–2 rounds.

02 · MCP

External tools

Off

Every Gmail, GitHub or Notion call is a round, and long raw JSON lands in the conversation.

On

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).

03 · Context window

Conversation memory

Off

File contents, logs and search results fill memory. When it's full, Claude compacts and forgets earlier work.

On

Intermediate data lives in code variables, not in memory. Sessions run longer before compaction.

04 · Tokens

The final bill

Off

Every round resends the full history, so tokens compound with each round.

On

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.

04 · Under the hood

Two tools: REPL and Poll.

With Code Mode on, Claude stops calling Read, Edit or Bash directly. Everything goes through these two tools.

Runs code

REPL

  • Takes code, runs it

    Claude sends a piece of JavaScript; the REPL runs it right in your Claude Code session.

  • Old tools become functions

    Inside the code, Claude calls file reads, edits, shell commands and MCP tools like functions, with loops, conditions and parallel runs.

  • Returns only what's needed

    What comes back to Claude is the value the code returns, not all the data that passed through.

  • Time limit

    Each run is capped at 10 minutes. Longer work moves to the background, up to 2 hours.

Checks progress

Poll

  • For background code

    When code runs long, Claude doesn't sit and wait; it can do other work or answer you.

  • Asks "done yet?"

    Claude calls Poll to get progress or the result once the code finishes.

  • Made for long jobs

    Full test suites, builds, big data processing, syncing thousands of records.

  • A note on sources

    The official docs only describe REPL. The Poll details come from community write-ups.

How it works, step by step

  1. You make a request. For example: "Find every file still using oldApi."
  2. Claude writes code and calls REPL. Just one round of thinking.
  3. The code runs and calls tools. Each call inside still goes through your permission rules.
  4. The code filters and merges results in variables. None of this enters Claude's memory.
  5. REPL returns a compact result. If the code runs in the background, Claude uses Poll to fetch it.
  6. Claude reads the result and answers you.
Code Claude might write for that request
// 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
05 · How-to

How to turn it on.

You need Claude Code v2.1.323 or later, running in a terminal. It's off by default.

macOS · Linux · WSL
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude
Windows (PowerShell, requires Git for Windows)
$env:CLAUDE_CODE_EXPERIMENTAL_CODE_MODE = "1"
claude
For every session: add to ~/.claude/settings.json
{
  "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.

06 · Examples

Real-world uses.

Rule of thumb: requests with words like "all", "every", "bulk", "filter", "count" are usually good fits for Code Mode.

In code
"Rename 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.

"What errors were in yesterday's production log?"

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.

"Run lint, tests and typecheck, then fix the errors."

Code Mode: runs all three commands at once and keeps only the error lines.

Faster, and thousands of output lines stay out of memory.

"Count TODOs and FIXMEs per directory."

Code Mode: scans the repo, counts per directory and returns a small table.

Hundreds of search hits become a few lines.

With MCP
"Which customer emails this week haven't been answered?"

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.

"Label every issue mentioning crash this week as bug."

GitHub MCP: lists issues, filters them and labels 30 in one loop.

30 calls packed into one script instead of 30 rounds.

"Compare 12 months of revenue by region."

Database MCP: runs 12 queries, merges them into one table and returns the summary.

Only the final table reaches Claude, not 12 raw results.

"Sync 200 customers from Notion to the CRM."

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.

Gmail example: code Claude might write
// 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.

07 · The numbers

How much does it save?

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.

08 · Safety

Is it safe? When should you use it?

Reassuring

You stay in control

  • Permission rules still apply

    The deny and ask rules you already set still govern each call made from the code.

  • You can approve each script

    Add an ask rule for REPL so Claude must ask before running code.

  • A cloned repo can't switch it on

    Project settings are ignored, so downloading code never turns Code Mode on for you.

Careful

Risks to know

  • The sandbox only wraps shell commands

    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.

  • Harder to review

    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).

  • It's experimental

    Anthropic says plainly it may change or be removed in any release.

Example: why the auto check can't see everything
const folder = await read("config.txt");  // only known at run time
await $`rm -rf ${folder}`;                 // "build" is harmless, "/" is a disaster
Code Mode offCode Mode on
SandboxWraps every shell commandWraps shell commands only; file, web and MCP calls from code are not
Manual reviewRead one command, easyRead a whole script, harder
Auto checkChecks each actionChecks 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 *).

Use it for

Repetitive, multi-step work

The same change across many files, searches whose results need filtering, several independent commands at once.

Skip it for

Small or sensitive tasks

One- or two-step tasks, or risky actions you want to approve step by step, like deleting data or pushing to production.

Takeaway

Same AI. A different way of working saves the tokens.

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.

Sources: Claude Code Docs, InfoQ, MarkTechPost, wmedia, Anthropic: Code execution with MCP, WorkOS, current to 11/2026. The feature is experimental, so details may change.