Code Mode Reaches Claude Code, One Year After the API

Code Mode

On 12 November 2026, Anthropic shipped a feature called Code Mode in Claude Code version 2.1.323. The release note describes it in one line: Claude writes JavaScript to call its tools. For anyone who has watched agent frameworks fight the round-trip problem, that sentence is the interesting part. Instead of requesting a file read, waiting, requesting an edit, waiting again, the model writes a short program that does the whole job and returns a summary.

What makes the release worth examining is something the release note does not say. Anthropic already shipped this idea, in a different language, on a different surface, almost exactly a year earlier. Programmatic tool calling arrived in the Claude API in beta on 24 November 2025 and runs Python inside a locked-down container with no internet access. Code Mode in Claude Code runs JavaScript in the user's own session. Same concept, same vendor, opposite security posture, and only one of the two has published numbers.

That split is the story. Code Mode is not one feature with one set of trade-offs. It is two implementations that differ in the language they generate, the environment that executes the result, the surfaces they support, and even how they treat the Model Context Protocol. This article separates them, explains what each one actually does, examines the isolation question Anthropic has not answered for the Claude Code version, and looks at the numbers the company has published, including one negative result it chose to print.

What Code Mode does in Claude Code

The Code Mode mechanic is simple to state. Without Code Mode, Claude asks for tool calls directly, one at a time, and reads each result before deciding what to do next. With Code Mode, Claude writes a piece of JavaScript that makes the tool calls, and Claude Code runs that code in the session.

The documented example covers a small refactor in one script. It shells out to a search for a function name, takes the first matching file, applies an edit, runs the relevant tests, and returns an object containing the edited file and the test result. Three tool calls, one program, one summary going back into the model's context.

The vocabulary in that example is worth noting because it is the whole surface. There is a tagged template helper for shell commands, functions for editing and for reading and writing files, an object that exposes tools, and utilities for logging, previewing and sleeping. Anthropic's stated reasons to use Code Mode are parallel execution, chaining one result straight into the next call, and returning only the slice of output that matters instead of the entire response.

Code Mode is marked experimental and off by default, with a warning that it may change or be removed in any release. It is enabled with an environment variable and Claude Code asks for confirmation before the first Code Mode session. That label matters for anyone planning around it. Experimental at Anthropic has historically meant the interface can move without a deprecation cycle.

The design goal is context economy. Every tool result that flows back into a model costs tokens and attention. A search that returns forty file paths, of which one is relevant, is forty paths of context for one useful fact. Code Mode lets the model do the filtering in code and return the single path. That is the same argument Anthropic made a year ago for the API version, and it is the argument Cloudflare made before either of them.

The other Code Mode, a year older

Programmatic tool calling in the Claude API predates Code Mode in Claude Code by roughly twelve months. It launched in beta on 24 November 2025 alongside two other tooling features, and it stopped requiring a beta header on 17 February 2026.

The mechanism is different in an important way. Rather than a global switch, it is opt-in per tool: a tool definition declares that it may be called from code. The API then turns those opted-in tools into Python functions inside a code execution container. When the generated script calls one, execution pauses, the API returns a tool request carrying a marker that says it came from code, the developer supplies the result, and the script resumes. Only the final output of the script returns to the model's context.

That pause-and-resume design is what keeps a human in the loop. It also means the model is not really running tools by itself. It is writing a program that requests tools, and the surrounding application still decides what to answer.

The two features that carry the Code Mode name share a purpose and almost nothing else. In the API it is Python in a managed container. In Claude Code it is JavaScript in the user's terminal session. Anyone comparing them on language alone will miss the part that matters, which is what the code can reach.

The two sandboxes are opposites

This is the section to read carefully if you plan to enable anything.

The API implementation is one of the most restrictive environments Anthropic documents. The container has internet access completely disabled, with no outbound network requests permitted. File access is limited to the workspace directory. Isolation from the host system and from other containers is described as full. Package installation at run time is not available, so the script gets the pre-installed libraries and nothing more. The container is Python 3.11 on Linux, x86_64, with one CPU, five gigabytes of memory and five gigabytes of disk.

The Claude Code implementation documents no equivalent boundary around the JavaScript itself. The docs say Claude Code runs the code in the session, and the session reaches whatever the session's tools can reach: shell commands, file reads and writes, MCP tools and subagents. Where bash commands are covered by the bash sandbox, that protection applies. But the JavaScript that orchestrates them is not described as running inside a separate isolated runtime. Nothing in the documentation states whether it is a Node process, a V8 isolate, a virtual machine or something else.

In Code Mode, Anthropic does enforce permissions, and the enforcement is at the right level. Each tool call the generated code makes passes through the same deny and ask rules and the same pre-tool-use hooks as a direct call, so existing rules keep working without changes. A hook can even inspect the JavaScript itself, because the code arrives as an input field on the tool that runs it.

The weakness in Code Mode is review granularity. In auto mode, the classifier reviews each piece of code before it runs rather than each tool call, and Anthropic states plainly that the classifier does not see values computed at run time, such as a path taken from search output. That is a real gap and the company documents it rather than hiding it. The docs also concede that bash rules match command text, so a denied command can be run in a form the rule does not match, with or without Code Mode.

Put beside the API version, the contrast is stark. Programmatic tool calling treats generated code as hostile by default and puts it behind a network airgap. Code Mode treats generated code as an extension of the user's own session, with per-call permission checks standing in for isolation. Neither position is indefensible. They are different answers to the same question, and Anthropic has not published an argument for why the Claude Code answer is safe.

The number everyone quotes measures something else

A figure travels with this topic: 98.7 percent, usually described as the token saving from code execution. It comes from a 150,000 to 2,000 token reduction and it appears in Anthropic's November 2025 engineering post about code execution with the Model Context Protocol.

That figure measures something narrower than the way it is commonly used. It compares loading every tool definition upfront against having the agent explore a generated file tree and load only the definitions it needs. It is about tool discovery, not about the results of tool calls, and it is a worked illustration rather than a benchmark.

No numbers at all have been published for Code Mode in Claude Code. The documentation page has none, the release note has none, and there is no announcement post. Any token or speed claim attached specifically to the Claude Code version is unsourced, including claims that borrow the 98.7 percent figure. The honest position is that the feature ships with a stated design rationale and no measured evidence.

What Anthropic's own data says, including a negative

The API version is a different matter. Anthropic has measured it repeatedly, and the results are more mixed than a vendor launch usually admits.

An engineering post reports average token use on complex research tasks falling from 43,588 to 27,297, a 37 percent reduction, with accuracy rising from 25.6 to 28.5 percent on an internal knowledge retrieval evaluation and from 46.5 to 51.2 percent on a general instruction benchmark. A documentation section reports roughly 38 percent fewer billed input tokens on a 75-tool project management agent with no accuracy change, and typical savings of 20 to 40 percent for production traffic carrying between 10 and 49 tool definitions. On agentic search, a combination of benchmarks shows 11 percent better performance with 24 percent fewer input tokens.

Then there is the result that deserves more attention than it gets. On the tau-squared benchmark, covering airline, retail and telecom scenarios, programmatic tool calling left scores unchanged and cost roughly 8 percent more. Anthropic published that. The same documentation names the cases where the feature is a weak fit: strictly sequential workflows where each call depends on reasoning about the previous result, a small number of calls with small responses where container and script overhead exceeds the saving, and tools that need immediate user feedback between calls.

That list is the most useful guidance in the entire documentation set, and it applies with equal force to the Claude Code version even though that version publishes no guidance of its own. If a workflow is sequential and shallow, Code Mode adds a layer without removing anything.

Anthropic's engineering post also names the cost of adoption directly. Running agent-generated code requires a secure execution environment with sandboxing, resource limits and monitoring, and those requirements add operational overhead that direct calls avoid. That admission sits awkwardly beside a Claude Code feature whose documentation does not describe its execution environment.

Where it will not run

The surface restrictions are extensive and easy to miss, and they explain why some people will try Code Mode and find nothing.

Code Mode requires version 2.1.323 or later on either release channel. It works only in an interactive terminal session. It does not work with the non-interactive print mode, the Agent SDK, the editor panel, the desktop application or cloud sessions. It needs a Claude subscription or a console account and cannot be used through a gateway, through Bedrock, through the platform on AWS, through Google Cloud or through Microsoft Foundry. It is unavailable under HIPAA configuration and under zero data retention. It supports four models: Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.2. On Windows it requires Git for Windows installed alongside a native build.

There are lifetime limits too. Foreground code stops after ten minutes including time spent waiting at permission prompts, and backgrounded code can run for two hours. A session cannot be resumed outside the terminal with Code Mode on, cannot move to the desktop application, and cannot become a background session. Remote control, the browser extension and computer use are unavailable while it is active.

Those constraints point to a feature built for one workflow: a developer sitting at a terminal, watching an agent work through a multi-file change. Everything else is excluded for now.

The MCP inconsistency

The Model Context Protocol is what motivated this whole line of work. The 2025 engineering post is entirely about presenting MCP servers as a file tree of callable functions so a model can read only what it needs, and Anthropic credits Cloudflare for naming the pattern Code Mode.

Yet the two implementations disagree about MCP. In Claude Code, MCP tools can be called from generated code, with changelog entries covering MCP calls and a tools object that keeps working past four thousand tools. In the API, tools provided by an MCP connector cannot be called programmatically at all.

One surface allows it, the other forbids it, and no published document explains why. The most plausible reading is that the API restriction follows from the container boundary, where a connector-mediated tool has no route into an airgapped sandbox, while Claude Code has no such boundary to cross. But that reading is inference. A customer planning a multi-surface deployment should treat the difference as unresolved rather than as a bug that will be fixed.

Cloudflare named it, everyone else followed

The term Code Mode predates Anthropic's usage. Cloudflare published the pattern first, describing the conversion of MCP tools into a TypeScript interface and asking a model to write code that calls it. Anthropic cites Cloudflare by name in the 2025 post.

Cloudflare's implementation is also the most aggressive on isolation. Execution happens in V8 isolates rather than containers, the sandboxed worker is prohibited from talking to the internet with the global fetch and connect functions throwing errors, and MCP servers are reachable only through bindings, so generated code cannot leak credentials it cannot see. OpenAI's equivalent runs JavaScript in a fresh V8 runtime with no Node, no package installation, no network, no general filesystem, no subprocess execution and no console. Google's code execution tool runs Python only and documents no way to call a custom function from inside generated code.

Set against those four, Anthropic's Claude Code implementation is the outlier. It is the only one of the four that runs generated orchestration code in the user's own environment rather than in a network-isolated runtime. The API implementation, by contrast, sits comfortably alongside the others. The company has built both, which suggests the divergence is a product decision about where the code runs rather than a technical limit.

For teams weighing the pattern more broadly, our coverage of Droid and programmatic tool calling looks at how another coding agent exposes the same idea, and our piece on how coding agents are judged in 2026 covers the evaluation side of the same question.

What to check before you enable it

Four questions are worth answering before switching Code Mode on, and none of them has a published answer.

First, what isolates the JavaScript. If the answer is nothing beyond the permission system, then the boundary protecting a machine is the quality of the rules and hooks configured for it, which puts unusual weight on rule hygiene. A team with broad allow rules should expect Code Mode to exercise them in ways a human reviewer would not anticipate.

Second, whether a workflow is sequential or parallel in shape. The documented weak fits for the API version apply here too. A chain of dependent calls gains nothing from being wrapped in a program, and a single call with a small response may cost more.

Third, whether the session handles anything regulated. Code Mode is unavailable under HIPAA configuration and zero data retention, which tells you something about how Anthropic classifies its maturity.

Fourth, whether hooks are in place to inspect generated code. A pre-tool-use hook matching the code runner can read the JavaScript before it executes, which is the only documented point at which a human or an automated check can see the whole program rather than one call at a time.

Readers tracking how agents are being secured in practice may find our look at persistent agent security a useful companion, and our earlier explainer on agent workspaces covers the environment side.

Questions readers are asking

What is Code Mode in Claude Code? It is an experimental, off-by-default feature, shipped in version 2.1.323 on 12 November 2026, in which Claude writes JavaScript that calls its tools instead of requesting one tool call at a time. Claude Code runs that code in the user's session.

Is Code Mode the same as Anthropic's programmatic tool calling? No. Programmatic tool calling is an API feature that launched in beta on 24 November 2025 and runs Python inside a managed container with no internet access. Code Mode runs JavaScript in the local session. They share a concept and a name, not an implementation.

Is Code Mode safe to enable? Anthropic enforces per-call permissions and hooks, and documents that in auto mode the classifier reviews code before it runs without seeing values computed at run time. The documentation does not describe a separate sandbox around the JavaScript itself. The decision depends on how tightly a team has configured its rules.

Does Code Mode reduce token use? Anthropic has published no token or latency figures for the Claude Code version. The widely cited 98.7 percent saving comes from a November 2025 post about loading tool definitions on demand, which is a different measurement.

Where can I use it? Only in an interactive terminal session on version 2.1.323 or later, with a subscription or console account, on Opus 5.5, Sonnet 5.5, Haiku 5.5 or Fable 5.2. It does not work with the Agent SDK, the editor panel, the desktop app or cloud sessions.

When does Anthropic say not to use this pattern? Its API documentation names strictly sequential workflows, a small number of calls with small responses, and tools needing immediate user feedback. It also reports that on the tau-squared benchmark the API version cost roughly 8 percent more with unchanged scores.

Sources

[fluentform id="2"]