Claude Code's experimental Code Mode lets Claude write one short JavaScript program that runs many tool calls locally and sends back only the filtered result. In creator tests it cut token use sharply on big multi-file jobs and cost more on small questions. It is opt-in, terminal-only, and could change or disappear, so treat it as a tool for heavy work, not a default.
What Code Mode changes
Normally Claude Code works in round trips. Each file read, search or command is a separate tool call, and the model re-reads the growing conversation each time. That is why long sessions drain tokens. Engineers were already flagging this back in April.
With Code Mode on, Claude writes a temporary JavaScript program that runs inside the local Claude Code process. The script coordinates several tool calls, loops and filters the data, and returns only the final result to the model. Variables stay in memory between script steps in the session.
What the creator tests found
Numbers here come from individual creators, not from Anthropic, and no official changelog entry for Code Mode turned up in our research, so read them as examples rather than guarantees.
Chase AI built the same feature twice and reported about 660,000 tokens with Code Mode versus 2.3 million without it, roughly 71% fewer on that one test.
DanManREAL ran 12 sessions on his own project and measured 52% fewer tokens.
Better Stack tested a 53-file refactor and saw it run roughly 80% faster with 28% fewer round trips.
Bigger claims of 50-92% savings come from MCP gateway vendors with a commercial stake. Treat them as unverified.
When it backfires
Writing the script is not free. On simple, one-step questions, creator tests showed Code Mode could be slightly slower and use up to 45% more tokens than the normal path. A sensible setup is two commands: a plain claude for everyday questions and an alias that sets the Code Mode variable for migrations, log filtering and other heavy jobs.
Limits and security
Code Mode is terminal-only. It does not work with the desktop app, the VS Code extension, Bedrock, Remote Control or Computer Use.
It also runs locally with your user permissions, unlike Anthropic's API code execution, which runs in an isolated server-side sandbox. Creators point out that /sandbox only restricts the shell commands the script invokes, not the script runtime itself. In auto mode, the safety check reviews the whole script once before it runs, so destructive actions decided at runtime can slip through unless you set explicit ask or deny rules. For risky codebases, run the session in a container or virtual machine.
Try it today
Open your terminal and update Claude Code to version 2.1.323 or later.
Set the environment variable
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1for one heavy multi-file job.Type
/clearwhen you finish a task so the next job does not carry old context and break your cache.
FAQ
What is Claude Code's Code Mode?
An experimental, opt-in mode where Claude writes one JavaScript program to run many tool calls locally and return only the filtered result.
How do I turn on Code Mode?
Update to Claude Code 2.1.323 or later and set CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 in your shell or settings file.
Does Code Mode always save tokens?
No. Creator tests showed large savings on heavy jobs and up to 45% more tokens on simple questions.
Is Code Mode safe to leave on?
It is experimental and runs locally with your permissions. Keep it for specific jobs and add ask or deny rules for destructive commands.
Companion Episode:
Want more practical AI builds like this? Get the free playbooks at joebuildsai.com.

