chase_ai

Claude Code's Code Mode: The Token-Saving Upgrade

Claude Code's experimental code mode writes a JavaScript program to run tool calls instead of calling them one by one. I built the same feature twice and cut token usage by 71%.

By Chase Hannegan8 min read

Want to learn Claude Code?See the Claude Code Masterclass

On this page

I had Claude Code build the same feature twice. The first run burned 2.3 million tokens. The second run cost 660,000 — a 71% drop. The only difference was one experimental Anthropic feature I had turned on: code mode. It changes how Claude Code executes tool calls, and that single change means fewer tokens, often faster runs, and far less context rot on long sessions. Here's exactly how it works and how to turn it on.

What Is Code Mode in Claude Code?

Code mode is an experimental feature from Anthropic that changes the way Claude Code executes tool calls. Instead of firing tools one at a time, Claude writes a JavaScript program that runs the tool calls for it — and filters the results down to only what it actually needs.

A few things to know before you get excited:

  • It's experimental. That means it can change or get removed at any time.
  • It's terminal-only. If you run Claude Code inside the desktop app, code mode doesn't apply. It only kicks in when you're working in the terminal.
  • It has a couple of hard limits. It doesn't work with computer use or remote control (more on that below).

That's the headline. The real value is in what it does to your token usage, so let's break down why.

How Does Claude Code Normally Execute Tool Calls?

To understand why code mode matters, you have to understand what Claude Code does today without it.

Say you ask Claude Code to do something that takes 10 steps — 10 separate tool calls. Right now, that involves a lot of round trips:

  1. Claude goes to tool call number one and executes it.
  2. It reads the response and drops it into its context window.
  3. It moves to tool call number two — but first it re-reads the entire conversation up to that point.
  4. It executes tool call two, gets the response, adds it to context.
  5. Repeat. Over and over, filling up the context window the whole way.

At the end, Claude has to sift through all of that accumulated information from every tool call to figure out its actual answer. Every response — useful or not — is sitting in the context window taking up space. That's the current system, and it's where the bloat comes from.

How Does Code Mode Work Differently?

Instead of calling tools one by one with all that back-and-forth, code mode has Claude write a single JavaScript program that executes the tool calls — simultaneously, not sequentially.

The program does the heavy lifting. It runs the calls, filters all the raw output, and then hands Claude only the information it needs. Claude isn't reading 10 full tool responses anymore; it's reading the filtered result. That's the whole trick.

That design gives you four real advantages:

  • Fewer tokens consumed. The program strips out the junk before it ever hits Claude's context.
  • Slower context fill. Less of your context window gets eaten, so you fight context rot far less on long sessions.
  • Often faster. Not always — but frequently, especially on bigger tasks.
  • A better working experience. Because the tool calls run as a background program, you can keep talking to Claude normally even while a task that takes an hour or two is running.

There's a bonus, too. When you start Claude Code with code mode on, you begin the conversation with about 20,000 fewer tokens already in context. The normal Claude Code tools get replaced by the code mode tool that offloads everything to those custom JavaScript programs, so your starting overhead drops right away.

To put it simply: code mode offloads your tool calls to a program that runs them in parallel and filters the results, instead of making Claude run everything sequentially and then dig through the bloat. The token savings are the real sell. Everything else is a nice bonus.

How Do You Turn On Code Mode?

Setup is simple. You add one experimental flag to the settings file inside your Claude folder. You don't even have to do it by hand — you can just prompt Claude to add the setting itself, and it'll drop it into your settings file for you.

Once it's in there, every time you run Claude Code in the terminal, experimental code mode is active. You'll see a little warning in the terminal confirming that the experimental mode is on. And because it's terminal-only, putting that flag in your settings won't touch your desktop app at all — the two stay separate.

What Do the Actual Numbers Look Like?

I ran three tests: a quick search, a simple one-step task, and a real feature build. Here's how code mode held up at each level of difficulty.

Test 1 — Quick Search Across 1,200+ Files

I pointed Claude at FastAPI — over 1,200 files — and asked it to count every function with no docstring.

  • Speed: 21 seconds with code mode on vs. 25 seconds off. A 4-second difference, nothing dramatic.
  • Context window at the end: 48K with code mode — 37% smaller.
  • Tokens read: 93K vs. over 250K.

That gap in tokens read is the JavaScript program filtering at work — it took a huge chunk of the token load off Claude.

Test 2 — A Simple One-Step README Task

Next I kept it dead simple: read a README and bring back some information. I wanted to see how code mode handles a trivial task versus normal tool calling.

  • Speed: here it was actually slower — 15 seconds vs. 11 seconds. That's likely because it had to build the program for a simple maneuver.
  • Context window at the end: 52K — 38% smaller.
  • Tokens read: 35% fewer.

So even when code mode loses on speed for a tiny task, it still wins on tokens and cost.

Test 3 — Adding a Real Feature to a Codebase

The last test was the substantial one: go into Django and add a JSON output option for migrations. This is where code mode pulls away from the pack.

  • Speed: 27% faster — a little over 200 seconds vs. 275.
  • Context window at the end: 77K for code mode vs. 112K without.
  • Tokens read: 660,000 with code mode vs. 2.3 million without — 71% fewer.

The pattern is clear: the more tool calls a task requires, the more code mode pulls ahead. On big, agentic jobs, offloading to a filtering program saves you hundreds of thousands — sometimes millions — of tokens.

And performance didn't suffer. Every task passed all its tests across the board, with code mode on or off. Claude Code without code mode wasn't worse at the work — code mode just streamlines the process of getting there.

Why Do the Token Savings Matter So Much?

Because tokens are money and tokens are performance. Saving hundreds of thousands or millions of tokens on a long task is a huge deal — especially when you're paying API costs on more expensive models or working against a usage cap.

There's a second-order win, too. Because code mode fills your context window more slowly, you hold a higher performance level deeper into a session. You're simply not fighting context rot the way you are when every raw tool response piles up in context. For anyone who lives in the terminal running long agentic tasks, that combination — lower cost and steadier performance — is the real pitch.

What Are the Downsides of Code Mode?

It's not all upside, and the limits are worth knowing before you flip it on:

  • Terminal only. It doesn't apply inside the Claude Code desktop app.
  • No computer use. By the nature of how computer use works, it's incompatible with code mode.
  • No remote control. Same story — it won't work with remote control either.

These are the kinds of rough edges you'd expect from an experimental feature. Hopefully Anthropic irons them out before code mode graduates from experimental to generally available, because a version of this inside the Claude Code desktop would be fantastic.

Should You Use Code Mode Right Now?

If you spend a lot of time in the terminal running larger tasks, yes — give it a shot. The token savings alone justify it, the context-rot relief is real, and in my testing it never hurt the quality of the output. Just remember it's experimental, so treat it as something that can change, and keep computer use and remote control off the table while it's on.

This feels like the direction Claude Code is heading, and it's a direction I'm happy to see.

Frequently Asked Questions

What is code mode in Claude Code?

Code mode is an experimental Anthropic feature that changes how Claude Code executes tool calls. Instead of running tools one at a time, Claude writes a JavaScript program that runs the calls in parallel and filters the results, handing Claude only what it needs. The result is fewer tokens used and often faster runs.

How much does code mode reduce token usage?

In my tests it varied by task size. A quick search read 93K tokens vs. over 250K without code mode, and a full feature build read 660,000 tokens vs. 2.3 million — a 71% reduction. The bigger and more tool-heavy the task, the larger the savings.

Does code mode work in the Claude Code desktop app?

No. Code mode is terminal-only. Even if you add the experimental flag to your settings file, it won't affect the desktop app — the terminal and desktop stay separate.

How do I enable code mode?

Add the experimental code mode flag to the settings file inside your Claude folder. You can also just ask Claude to add it for you. Once it's in, every terminal session of Claude Code runs with code mode on, and you'll see a warning in the terminal confirming it's active.

What are the limitations of code mode?

Code mode is experimental, so it can change or be removed. It only works in the terminal, and it's incompatible with both computer use and remote control. It also added build overhead that made one trivial task slightly slower, though it still used fewer tokens.


If you want to go deeper into getting the most out of Claude Code, join the free Chase AI community for templates, prompts, and live breakdowns. And if you're serious about building with AI, check out the paid community, Chase AI+, for hands-on guidance on how to make money with AI.

Topicsclaude-codeanthropicai-codingcode-modedeveloper-toolstokens

Chase Hannegan

I teach people to build real things with AI, on YouTube and inside Chase AI+.