Harness Engineering 6 months ahead, in a few hours.

Claude Code Code Mode: when to let Claude script its tool calls

Thomas Poulain ·

Code Mode is an experimental Claude Code feature that shipped in v2.1.323 on November 12, 2026. Instead of calling its tools one at a time, Claude writes a piece of JavaScript that makes the calls, and Claude Code runs it in your session. To turn it on, run CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude in a terminal. It’s off by default, and the docs warn that it may change or be removed in any release.

What does Code Mode actually do?

In Code Mode, a single piece of code can run commands in parallel and feed one result into the next call. It can also return only the part of the output Claude needs.

In the docs’ example, the code finds a file, raises a retry limit and runs the tests.

const files = await $`rg -l "function retryPolicy" src`.text();
const target = files.trim().split("\n")[0];
await edit(target, "maxAttempts: 3", "maxAttempts: 5");
({ edited: target, tests: $`npm test -- retryPolicy`.nothrow() });

The last line hands Claude the file path and the test output. In the conversation, you see the tool calls but not the code. Ctrl+O shows it, in a collapsed Code row.

How do I turn on Code Mode?

You need v2.1.323 or later. Check with claude --version, and run claude update if needed.

To try it, set the variable in your shell.

CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude

To get it in every new session, put it in your user settings, ~/.claude/settings.json.

{
  "env": {
    "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1"
  }
}

Claude Code ignores this variable in a project’s settings. A repository you clone can’t turn Code Mode on for you.

On first launch, Claude Code asks you to confirm. Pick Yes, turn on Code Mode. It restarts and shows this line at the top of the session.

Code Mode (experimental) is on · this session can be resumed only with Code Mode on

If you see Code Mode (experimental) isn't available instead, the reason follows on the same line.

To resume a Code Mode session with claude --continue or claude --resume, keep the variable at 1. Otherwise Claude Code refuses to resume it. To turn Code Mode off, remove the variable or set it to 0. A 0 in one place wins over a 1 in another. An organization can also block Code Mode with 0 in its managed settings, but it can’t force it on.

Will Code Mode work with my setup?

The docs still list OpenTelemetry, DISABLE_TELEMETRY and mods among the blockers. The changelog has relaxed them since.

ItemWhat you need
Versionv2.1.323 or later, on latest or stable
AccountA Claude subscription or Console account, straight to the Anthropic API. No gateway, Bedrock, Claude Platform on AWS, Google Cloud or Foundry
OrganizationNo HIPAA configuration, no zero data retention
ModelOpus 5.5, Sonnet 5.5, Haiku 5.5 or Fable 5.2
SurfaceAn interactive claude session in a terminal. Not the VS Code panel, the Desktop app or cloud sessions
InstallationThe native build, plus Git for Windows on Windows
Sign-in/login or ANTHROPIC_API_KEY. No apiKeyHelper or ANTHROPIC_AUTH_TOKEN
Unavailable featuresRemote Control, Claude in Chrome and computer use
OpenTelemetryEvents and metrics allowed since v2.1.329. Tracing still keeps it off
Telemetry turned offAllowed since v2.1.329, DISABLE_TELEMETRY included
ModsSince v2.1.327, a mod that hooks tool calls no longer blocks it
Agent teamsv2.1.326 or later. Teammates run in Code Mode in the in-process display mode, not in split panes

What changes for permissions?

Every tool call in the code goes through your deny and ask rules and your PreToolUse hooks, under the tool’s usual name, such as Bash. In the modes that prompt, you approve each call as usual.

In auto mode, the classifier reviews each piece of code before it runs, not each tool call. It doesn’t see values computed at run time, such as a path taken from search output. So keep rules or hooks for the calls you must control.

To approve each piece of code before it starts, add an ask rule for REPL, the tool that runs the code.

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

The prompt doesn’t show the code. Press Ctrl+O to read it before you answer. In auto mode, your approval starts the code even if the classifier would have blocked it. If Claude reports that the code can’t start a subagent, remove the rule.

The sandbox only covers the shell commands the code runs. The JavaScript and its file, web and MCP calls run outside it. To isolate everything, the docs point to a container or a virtual machine.

How do I adapt my hooks to Code Mode?

A PreToolUse hook that filters shell commands has to check each part of the command. In Code Mode, a git push in a folder named app can reach it as cd 'app' && git push. A filter that only tests the start of the string lets it through.

To see the code itself, a PreToolUse hook with the REPL matcher gets the JavaScript in tool_input.code. This hook, placed in your user settings, keeps a log of every piece of code. It needs jq.

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "REPL",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.code' >> ~/.claude/code-mode.log"
          }
        ]
      }
    ]
  }
}

Since v2.1.329, a PreToolUse hook that errors no longer refuses a tool call from code, the same as outside Code Mode. A hook that doesn’t finish, after its timeout for instance, still gets the call refused. For a hook that guards calls, add "onFailure": "block", as covered in the guide to failing hooks.

To filter what the code returns, use a PostToolUse hook on REPL. It reads the output from tool_response and returns a redacted copy, with the same shape, as updatedToolOutput. If the shape changes, Claude gets the original output. This hook doesn’t redact the input of a refused call, which the refusedCalls field can repeat.

Since v2.1.328, UserPromptSubmit hooks no longer receive code output, managed ones included. If you checked that output there, move the check to your PostToolUse hook.

How long can the code run?

When Claude waits for the code, it stops after ten minutes. Since v2.1.328, in Manual and acceptEdits modes, time spent at a permission prompt no longer counts. If you start the session in auto mode or bypassPermissions, the code can run in the background for up to two hours. You keep talking to Claude meanwhile.

When should I turn on Code Mode, and when should I skip it?

The docs suggest it when a task chains many related tool calls. They mention the same change across many files, or a search whose results need filtering.

The docs give no figures on the gain, in time or in tokens. To judge it on your project, send the same prompt in two fresh sessions, with and without Code Mode, and compare /usage. The guide to task cost explains how to read those numbers. The docs suggest this prompt for a first try.

Read every Markdown file in this project and list the links that point to local files that don't exist.

Skip it if you work outside the terminal or behind a company gateway, or if you need Remote Control in the session. From v2.1.325 to v2.1.330, every release in the changelog has changed Code Mode. Read it before you suggest Code Mode to your team.


Section 5.4 of module 5, Hooks & automation covers PreToolUse hooks, and section 5.5 covers PostToolUse hooks. The allow, ask and deny rules are in section 3.3 of module 3, Advanced configuration, and permission modes in section 3.4.

To see these articles more often on Google, add Harness Engineering to your preferred sources.

You might also like