Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 5 min read

Code Mode makes Claude Code write JavaScript instead of calling tools one at a time

Claude Code 2.1.323 added Code Mode, an experimental opt-in where Claude stops asking for Bash, Read and Edit one at a time and instead writes a piece of JavaScript that makes those calls. Claude Code runs that code in y

Code Mode makes Claude Code write JavaScript instead of calling tools one at a time

Claude Code 2.1.323 added Code Mode, an experimental opt-in where Claude stops asking for Bash, Read and Edit one at a time and instead writes a piece of JavaScript that makes those calls. Claude Code runs that code in your session. One script can fan out commands in parallel, feed one result into the next call, and hand back only the slice of output the model needs to read.

// Detect dark theme var iframe = document.getElementById('tweet-2121789088499933223-781'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2121789088499933223&theme=dark" }

I tried it with Fable 5.2 on a task that is all plumbing: find every Markdown link in the project that points at a local file that does not exist. It came back with 13 tool calls in 2 model turns and all 3 broken links. Without Code Mode that is 13 round trips, each one spending a turn of context and a wait.

// Detect dark theme var iframe = document.getElementById('tweet-2121789095168868770-541'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2121789095168868770&theme=dark" }

What changes when Code Mode is on

In the conversation you see what you always saw: the edit diffs, the command output. You do not see the JavaScript. Press Ctrl+O to open the transcript viewer and each script is there as a collapsed Code row.

The code looks like ordinary scripting. A shell call goes through a tagged template, an edit goes through a helper, and the last expression is what Claude reads back.

const files = await $`rg -l "function retryPolicy" src`.text();
await edit(files.trim().split("\n")[0], "maxAttempts: 3", "maxAttempts: 5");

That shift matters for debugging. The script is the unit of work now, so when a run surprises you, the script is the thing to read, not the tool list.

Turning it on, and the one place the variable has to go

The variable is CLAUDE_CODE_EXPERIMENTAL_CODE_MODE set to 1. You can export it for one session, or put it in your user settings so every new session starts with it.

I packaged the settings version as a Code Mode setting so you do not have to hand edit JSON:

npx claude-code-templates@latest --setting environment/code-mode

// Detect dark theme var iframe = document.getElementById('tweet-2121789098994135137-106'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2121789098994135137&theme=dark" }

One thing to get right: Claude Code ignores this variable in project and local settings files. That is deliberate, so a repository you clone cannot switch Code Mode on for you. When the installer asks which settings file to merge into, pick User settings. Anything else installs cleanly and does nothing.

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

The first session asks you to confirm. After you accept, Claude Code restarts and prints Code Mode (experimental) is on near the top. If you get Code Mode (experimental) isn't available instead, the reason is on the same line and /status repeats it.

Permissions still run, but auto mode reviews the code

Every tool call a script makes still goes through your deny and ask rules and your PreToolUse hooks. You do not need a new matcher for this: a Bash call from inside a script is matched by your Bash rules the same way it was before.

Auto mode is where the shape changes. The classifier reviews each piece of code before it runs, not each tool call, and it does not see values computed at run time, such as a path taken out of search output. If there is a call you genuinely need to control, put it in a rule or a hook instead of leaning on that review.

To check the JavaScript itself, write a PreToolUse hook that matches REPL, the tool that runs Claude’s code, and read it from tool_input.code.

One caveat the post did not mention: Bash rules match command text, so a denied command can still be written in a form your rule does not match. That is true with or without Code Mode. Sandboxing is the limit that does not depend on how the command is spelled.

What you give up

  1. Resuming: a session started in Code Mode resumes only with Code Mode still on. With it off, claude --continue and claude --resume refuse the session.
  2. Time: code you wait on stops after ten minutes, including the time you spend at permission prompts. Background code gets up to two hours, and only if you started the session in auto or bypassPermissions mode.
  3. Surfaces: interactive terminal, native build. Not -p, the Agent SDK, the VS Code panel, the Desktop app or cloud sessions, and not Remote Control, Claude in Chrome or computer use.
  4. Models: Opus 5.5, Sonnet 5.5, Haiku 5.5 or Fable 5.2.
  5. Accounts: a Claude subscription or Console account. Not through a gateway, Bedrock, Google Cloud or Microsoft Foundry, and not under the HIPAA configuration or zero data retention.
  6. Conflicts: it will not start with an API key helper, agent teams, OpenTelemetry export or DISABLE_TELEMETRY in place.

For a team, the off switch is the same variable with the value 0 in managed settings. People already inside a Code Mode session stay there until they restart, and after that nobody can resume one. Managed settings can block it, they cannot turn it on.

Is the trade worth it? For a repetitive edit across many files, a search whose output needs filtering before the model reads it, or a few independent commands that can run at once, yes. For a two call task you are adding a code generation step to something that was already one round trip. It is experimental, and Anthropic says it can change or be removed in any release, so do not build a workflow that depends on it.

Where the settings live

The Code Mode setting lives in the catalog next to the other things you would put in ~/.claude/settings.json:

You can follow me on my social media:

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.