Skip to content
GUIDES#Claude Code#Code Mode#MCP

Claude Code burning tokens? How to enable Code Mode for MCP

Code Mode lets Claude Code call several tools from JavaScript and return only the data the model needs. Here is how to enable, test and use it honestly.

Yaakov Tzedek
Yaakov Tzedek · AI expert·9 min read
Claude Code using Code Mode to orchestrate MCP tools and reduce unnecessary token usage
THE BOTTOM LINE
  • A practical guide to Claude Code's experimental Code Mode: how to enable it, when it can reduce MCP token usage, what the viral 98.7% claim really means, and the security limits to understand first.
2.1.323 or laterMinimum version
150,000 to 2,000 tokensAnthropic example
Experimental and off by defaultFeature status
44% lower estimated costOne independent test
DID YOU KNOW?

The viral 98.7% figure is not a general benchmark for Claude Code's Code Mode. It came from a November 2025 Anthropic example in which on-demand tool discovery reduced usage from 150,000 to 2,000 tokens.

Claude Code can receive dozens of MCP tools before it starts useful work. A new experimental mode lets it write code that calls several tools and returns only the result it needs. But the viral claim of 98% token savings is not a guarantee for every user. This guide shows how to enable the feature, test it on your own workflow, and keep permissions under control.

In brief:

  • What happened: Anthropic added an experimental Code Mode to Claude Code, allowing JavaScript to orchestrate multiple tool calls.
  • Why it matters: Large intermediate results can remain inside code instead of filling the model's context window.
  • The numbers: Anthropic once showed a reduction from 150,000 to 2,000 tokens, but has not published a universal Claude Code benchmark promising that result.
  • For business: The approach can help workflows that span several systems, large spreadsheets, loops, filtering and parallel operations.

What is actually new in Claude Code's Code Mode?

Code Mode is an experimental Claude Code feature. Instead of requesting one tool, reading its complete output and then deciding which tool to call next, Claude writes a JavaScript program. That program can make several calls, feed one result into another operation, filter large outputs and return only the information Claude needs to read.

According to the official Claude Code documentation, the feature is particularly useful for repetitive changes across files, searches that require filtering, and independent operations that can run in parallel. It is experimental, disabled by default, and may change or disappear in a future release.

If MCP is new to you, start with our plain-language MCP guide, then read the guide to using MCP with Claude Code. Code Mode does not replace those connections. It changes how Claude orchestrates them.

Anthropic's official Claude Code documentation explaining how Code Mode runs several tools from JavaScript Screenshot: Anthropic's official Claude Code Code Mode documentation, November 29, 2026.

Where did the 98.7% token-saving claim come from?

The figure is real, but its context matters. On November 4, 2025, Anthropic published an engineering article about code execution with MCP. In its example, an agent did not load every tool definition in advance.

It discovered the relevant tool, read only the required interface, and moved data between Google Drive and Salesforce inside a code environment.

Anthropic said the approach reduced token use from 150,000 to 2,000, a 98.7% saving. The article did not publish the full benchmark methodology, and it did not claim that every Claude Code task would save the same percentage. The article also predates the current Claude Code feature by more than a year.

Later testing paints a more moderate picture. An independent test published in November 2026 found a 44% lower estimated cost on one task using a real MCP server, with the same execution time, even though model requests more than doubled. On a simple one-call task, Code Mode was slower. The defensible conclusion is not "98% cheaper everywhere." It is that savings can be substantial when large intermediate outputs do not need to enter the model context.

When can Code Mode genuinely help?

Savings appear when code performs mechanical work and the model receives a small conclusion. The best candidates include:

  • Several dependent calls: retrieve a document list, then inspect comments in every document.
  • Large data with a small answer: filter 10,000 rows and return five orders that require attention.
  • Parallel operations: inspect several files, services or environments without a model decision between each call.
  • Loops and conditions: poll for a status, enforce a timeout and handle errors in code.
  • Tool-to-tool transfer: move content from Drive into a CRM without printing the whole payload back into the conversation.

It is less useful for a quick lookup, one small tool result, or a task where Claude must reason over every raw detail. Anthropic's advanced tool use guide makes an important distinction: tool search addresses bloated tool definitions, while programmatic tool calling addresses bloated intermediate results. They solve different problems.

How do you enable Code Mode?

First confirm that you use the native Claude Code installation in an interactive terminal. As of November 29, 2026, version 2.1.323 or later is required. Code Mode does not work in the VS Code panel, desktop app or cloud sessions.

  1. Check the installed version:
claude --version
  1. Update when necessary:
claude update
  1. For a one-time macOS, Linux or WSL session, run:
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude
  1. To keep it enabled, add this block to ~/.claude/settings.json:
{
  "env": {
    "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1"
  }
}
  1. Confirm the first-time prompt and restart if Claude asks you to. The session header should say that Code Mode is on. Press Ctrl+O to open the transcript viewer and expand a Code row to inspect the JavaScript Claude wrote.

How should you test whether it helps your workflow?

Do not compare two random runs. Pick a repeatable task with an answer you can verify. Run it three times in ordinary mode and three times with Code Mode while keeping the model, effort level and input data unchanged.

Record elapsed time, tool calls, model requests, token use when available, and whether the answer was correct. Also inspect how much raw information entered the context. Cached reads can be much cheaper, so a token reduction does not always translate into the same percentage of financial savings.

A good test is to inspect 20 documents, find open comments without a reply, group them by document and return only five examples. A poor test is to fetch one document title. The first requires loops and filtering; the second needs one call.

What prompt can you paste into Claude Code?

The prompt below is not magic and does not promise 98% savings. It asks Claude to decide whether Code Mode fits the task, process large outputs in code, and report measurements you can compare:

Review the task and the connected MCP tools before execution.

1. Show a short plan and list the tools you need.
2. Use Code Mode only when the task has at least three related calls, large results that require filtering, loops, conditions, or operations that can run in parallel.
3. Do not load or display definitions for tools that are irrelevant to the task.
4. Keep intermediate results in code variables. Filter, sort, group and calculate in code before returning information to the model.
5. Return only a summary, counts and up to five examples. Do not return a full array unless I explicitly request it.
6. Do not print secrets, tokens, personal information or sensitive content. When data must move between tools, transfer it directly without displaying it in the conversation.
7. Do not write, delete, send, publish or change permissions without my explicit approval.
8. At the end, report the tools used, number of calls, what was filtered in code, what entered the model context, elapsed time and token or cost data when available.
9. If Code Mode is not appropriate, explain why in one sentence and use ordinary tool calls.

Task: [insert your task here]

You can later save an adapted version as a command or skill, but only after testing it on a real task. Reusable code is valuable when it removes repetitive work, not when it hides actions nobody reviews.

What are the security and permission limits?

Code Mode can keep intermediate results out of the model context, but that does not automatically keep data inside a trusted organizational boundary. Anthropic's documentation says that JavaScript plus file, web and MCP calls run outside the shell sandbox. Sandbox rules apply to the shell commands the code invokes.

In auto mode, the classifier reviews the code rather than every individual runtime call. It cannot see values that will be computed while the code runs. Organizations should therefore keep deny and ask rules, use hooks for sensitive actions, and run Claude Code in a container or virtual machine when stronger isolation is required.

To require approval for each code block before it runs, add:

{
  "permissions": {
    "ask": ["REPL"]
  }
}

Before connecting production systems, read our guide to common MCP mistakes and the case in which a Claude Code approval setting exposed secrets. Saving tokens is never worth exposing a credential or allowing an irreversible action.

What does this mean for your business?

For a company connecting an agent to Gmail, Drive, CRM, invoices and reporting, token cost is only part of the problem. A crowded context can make the agent focus on irrelevant raw data, duplicate content between tools and spend time on information that code could reduce to a few numbers.

Start with one high-volume workflow that has a clear answer, such as an exception report or a list of leads waiting for a reply. Define which fields the model may see, which actions need approval and what a correct answer looks like. Expand only after you have measured the result.

Want to learn Claude Code and AI agents step by step?

AI TV includes short practical lessons on Claude Code, MCP, AI agents and automation. Learn how to connect tools, write reliable instructions and keep human approval in the loop before moving a workflow into your business.

🎓 Continue learning in the AI TV app

More than 2,800 lessons and more than 140 courses, in Hebrew and English, organized by profession and field.

Join AI TV and start learning →

Sources

Official Claude Code Code Mode documentation · Anthropic engineering article on code execution with MCP · Anthropic advanced tool use announcement · Cloudflare Code Mode · Independent November 2026 cost comparison. Information verified on November 29, 2026.

Frequently asked questions

Was this article helpful?
Share:WhatsAppLinkedInX
Yaakov Tzedek
WRITTEN BY

Yaakov Tzedek

An Israeli AI lecturer, consultant and implementer who has supported 100+ organizations in AI implementation and lectured for 200+. Official content partner of Meta, Google, Canva and TikTok, featured on Israel's Channel 13.

More about Yaakov →