Does Code Mode in Claude Code Actually Save Tokens?

2026-11-21
Brian

Subscribe
Get New Posts by Email
New RepoSquare posts in your inbox: comparisons, setup guides and explainers on open-source tools and AI coding agents. No spam, and you can unsubscribe anytime.

Yes. Code Mode cuts the tokens Claude Code sends by about a third, because every request starts roughly 15,000 tokens lighter. But most of those tokens were already cheap cached text, so on a warm session the bill only dropped 4 to 8 percent in my tests. The real saving shows up on a cold cache, or when the session is short enough that the setup is still being written. This is a different lever from TokenEconomizer or the RTK vs Caveman tricks: Code Mode changes what Claude Code itself ships on every request. The same setup cost is why Claude Code gets more expensive once you start measuring it.

You switch on an experimental flag, and Claude starts writing little JavaScript programs instead of calling tools one by one. The promise is fewer tokens. I wanted the actual number, so I ran the same three tasks with Code Mode on and off and counted every token.

Here is the thread to hold on to: fewer tokens is not the same as a smaller bill.

What Code Mode Does

Code Mode test cards: first request 31,400 vs 46,200 tokens, 30 to 36 percent fewer tokens, bill down 4 to 8 percent, cold cache 26 to 32 percent, warm cache about 8 percent.
Code Mode in the test: fewer tokens, a smaller cut on the bill, and a bigger gap on a cold cache.
Many lines merging into one code block, Claude Code Code Mode
Many lines merging into one code block, Claude Code Code Mode

Code Mode lets Claude write one script that calls many tools, instead of calling each tool in its own turn.

Start from the base fact. Claude Code works through tools (small built-in actions like Bash, Read and Edit). In normal mode Claude asks for one tool call, waits for the result, reads it, then decides the next step. Every one of those steps is a full round trip to the model.

Code Mode changes the shape of that loop. Claude writes a short JavaScript snippet, Claude Code runs it inside your session, and the snippet can call several tools, filter the output and hand back only the part Claude needs. The tool that runs the snippet is called REPL (a small code runner that keeps state between snippets).

Think of it like a shopping list. Normal mode drives to the shop for each item. Code Mode writes the list first and does one trip.

Normal mode makes one tool call per reply, Code Mode runs many tool calls in one script
Normal mode makes one tool call per reply, Code Mode runs many tool calls in one script

That picture is why people expect big savings. Fewer trips should mean fewer tokens. So I tested whether the trips actually go away.

How to Turn Code Mode On

One environment variable, then one confirmation screen.

Update Claude Code first with claude update, because older builds start without it. Then launch it like this:

CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude

Claude Code asks you to confirm. Pick “Yes, turn on Code Mode” and it restarts with this line near the top:

To keep it on for every session, put the same variable in the env block of ~/.claude/settings.json. A project’s own settings file can’t switch it on, so a repo you clone can’t turn it on for you. To see the scripts Claude writes, press Ctrl+O and expand a “Code” row.

Terminal with the Code Mode banner and the JavaScript Claude wrote for a rename
Terminal with the Code Mode banner and the JavaScript Claude wrote for a rename

Three limits matter before you rely on it. It only runs in an interactive terminal session, so claude -p, the VS Code panel and the Desktop app start without it. A session started in Code Mode can only be resumed with Code Mode still on. And code that waits in the foreground stops after ten minutes.

How I Tested Code Mode Against Normal Mode

Same project, same three prompts, Code Mode on and off, every token read from the session log.

The test project was a small JavaScript app with 32 files and a test script. I gave Claude three jobs that cover the common cases:

  1. Rename a function across 13 files, then run the tests.
  2. Fix one bug in one file, then run the tests.
  3. Read all 32 files and report each file’s exported function and top comment.

Each job ran twice per mode on Haiku 5.5, plus one rename run per mode on Sonnet 5.5. After each run I reset the files with git, so every run started from the same state.

Where do the numbers come from? Claude Code writes a transcript for every session (a JSONL file in ~/.claude/projects/).

Each model reply in it carries a usage block: fresh input tokens, tokens written to the cache, tokens read from the cache, and output tokens. I priced each one at the API’s per-token rates. On the one Sonnet run where Claude Code also logged its own cost figure, my math matched it to the cent.

Round Trips Barely Changed

Barely. Claude in normal mode was already batching its work.

Did normal mode really need 13 separate edits? I expected it to read and edit 13 files one at a time. It didn’t. Haiku grepped for the name, ran one sed command across every file, then ran the tests. Five or six model calls in total.

Code Mode took four or five. Inside its scripts it fired more tool calls (up to 98 in the read-every-file job), but those run inside your session and cost no model tokens.

So the round trips barely changed. Then where did the savings come from?

Why Every Request Starts 15,000 Tokens Lighter

Every request starts about 15,000 tokens smaller.

First, a quick prerequisite. A token is a small chunk of text, often a short word or part of a longer one. Every time Claude Code calls the model, it sends the whole setup again: the system instructions, the list of tools, and the conversation so far. The context window (the most text the model can read at once) has to hold all of it.

In Code Mode that setup is lighter. The very first request of a session was 31,400 tokens on Haiku with Code Mode on, against 46,200 with it off. Sonnet showed the same gap: 30,700 against 45,500. Since every later request carries that setup again, the gap repeats on every call.

First request: 46.2k tokens with Code Mode off, 31.4k with it on
First request: 46.2k tokens with Code Mode off, 31.4k with it on

Across all three jobs, Code Mode sent 30 to 36 percent fewer tokens. That is the number people quote. It is real.

The Bill Dropped Less Than the Token Count

Much less than the token count suggests, once the cache is warm.

Here’s the catch. Prompt caching (the API stores the repeated start of your request and reuses it) means that big setup block is mostly billed as a cache read. A cache read costs a tenth of the normal input price on Haiku, and a twentieth on Sonnet and Opus. So the 15,000 tokens Code Mode saves were already the cheapest tokens in the request.

Code Mode also wrote slightly more output, because a script is longer than a one-line tool call. Output tokens cost five times the input price.

Put together, the warm-cache runs looked like this:

JobTokens sentDollar cost
Rename across 13 files36% fewer8% lower
Fix one bug30% fewer5% lower
Read 32 files and report36% fewer4% lower
Code Mode: 30 to 36 percent fewer tokens, 4 to 8 percent lower cost
Code Mode: 30 to 36 percent fewer tokens, 4 to 8 percent lower cost

A third fewer tokens. A few percent off the bill. That’s the thread again: fewer tokens is not the same as a smaller bill.

When Code Mode Saves Real Money

On the first task after a break, when nothing is cached yet.

Claude Code writes its setup into a cache that lasts up to an hour, and writing to that cache costs twice the normal input price. When the cache is empty, the full setup gets written at that higher rate. A setup that is 15,000 tokens smaller costs a lot less to write.

My first runs had a cold cache, and there the gap was big. The first Sonnet rename cost 32 percent less with Code Mode on. The first Haiku rename cost 26 percent less. Later runs in the same hour found the setup already cached, and the saving fell back to single digits.

Cold cache saving 26 to 32 percent, warm cache 8 percent
Cold cache saving 26 to 32 percent, warm cache 8 percent

So if you work in short bursts with long gaps between them, Code Mode trims a real slice off each session’s opening cost. If you work all afternoon in one warm session, expect a small saving.

What Code Mode Costs You

A second or two per task, and a different permission story.

On average Code Mode was a little slower: about 2.6 seconds longer on the rename, 1.8 seconds on the bug fix, 1.3 seconds on the read-everything job. Writing and running a script adds a step.

Permissions also change shape. Each tool call inside a script still goes through your deny and ask rules and your PreToolUse hooks (scripts you set to run before a tool call).

Auto mode is different. In auto mode (where a safety check approves low-risk actions for you), that check reads each script once before it runs. It doesn’t see values the script works out while running, like a file path pulled from a search result.

If you rely on auto mode to stop risky commands, keep explicit deny rules for the ones that matter.

There is one quiet upside for subscription users. A lighter setup leaves more of the context window for your actual work. That means more room before Claude has to compact (summarize older parts of the conversation to free space).

Should You Turn Code Mode On?

Turn it on if you hit context limits or start many short sessions. Skip it if you need -p, VS Code or stable behavior.

There’s a fair case for leaving it off. It is experimental, it can change in any release, it is slower per task, and on a warm session it saves a few cents at most.

Still, the test changed how I think about it. Code Mode is not mainly a “fewer round trips” feature, at least not with a model that already chains shell commands well. It is a lighter-setup feature. That helps context room every time and helps the bill most when the cache is cold.

Try it on one real task and open the session log before and after. Count the cache reads, not just the tokens.

Get New Posts by Email
New RepoSquare posts in your inbox: comparisons, setup guides and explainers on open-source tools and AI coding agents. No spam, and you can unsubscribe anytime.

Leave a comment