Claude Code Has Learned to Write Scripts: Code Mode Compresses Multi-Step Tool Calls into a Single JS Block
Claude Code's new experimental Code Mode feature lets Claude orchestrate multiple tool calls with JavaScript, supporting parallel execution, output filtering, and background runs of up to two hours. How to enable it, what the limits are, and what the community thinks—all here.
Claude Code has shipped an experimental feature called Code Mode. It changes how Claude calls tools.
Previously, when Claude needed to call tools like Bash, Read, and Edit, it called one at a time and decided the next step after seeing the result. During multi-file refactors, this back-and-forth consumed a lot of context and was slow. Code Mode's idea is to have Claude directly write a piece of JavaScript and let Claude Code execute it. The script can run multiple commands in parallel, pass the result of one call to the next, and return only filtered output to Claude, reducing context usage.
The official example: have Claude change the retry cap from 3 to 5. It might generate code like this:
const files = await Wink - AI原生创新,忠于用户,专属智能体验 rg -l "function retryPolicy" src`.text();
const target = files.trim().split("\n")[0];
await edit(target, "maxAttempts: 3", "maxAttempts: 5");
({ edited: target, tests: Wink - AI原生创新,忠于用户,专属智能体验 npm test -- retryPolicy`.nothrow() });
The last line returns only the file path and test results to Claude; it does not stuff the entire search output into context.
In the conversation, you see tool calls and diffs, not the code itself. To see the JavaScript Claude generated, press Ctrl+O to open the transcript viewer and expand the Code line. This also lets you inspect the code before it runs.
Another practical point of Code Mode is that long tasks can run in the background. In auto or bypassPermissions mode, scripts can run for up to two hours. When running tests or complex builds, you don't have to wait idle; you can keep chatting with Claude or do other things. Use the /tasks command to view and control background scripts.
For permissions, every tool call inside the script still goes through the existing deny/ask rules, sandbox constraints, and PreToolUse hooks. You can even write a separate hook for the REPL tool to inspect it before JavaScript runs, or redact sensitive tokens from output before it is read into context. In other words, efficiency improves, but the security boundary is not bypassed.
If you want to try it, you need these conditions:
- Claude Code v2.1.323 or later
- Model is Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.2
- An interactive session in the terminal; desktop app, VS Code panel, and cloud sessions are not supported
- Cannot go through gateways, Bedrock, or other third-party channels, and cannot have HIPAA and zero data retention enabled
There are two ways to enable it. Launch it in the shell:
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude
Or add it to ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_CODE_MODE": "1"
}
}
The first launch will ask for confirmation. Once enabled, the session can only be resumed under Code Mode; if the variable is turned off, the session cannot be resumed. Organizations can disable it by setting it to 0 through managed settings.
The community reaction to this feature is interesting. Some say the idea is basically consistent with the 2024 CodeAct paper: using executable code to unify an agent's action space. Others warn that the sandbox only wraps shell commands inside the script; JavaScript itself, along with file, network, and MCP calls, is outside the sandbox. If your security model relies on the sandbox, you'd better run the entire Claude Code inside a container. Still others say a syntax error will crash the whole flow—a new risk after moving from conversational tool calls to programmatic orchestration.
One user said he had used a community-made code-mode MCP a year earlier, and this time it has effectively been brought into the official harness. He attached two screenshots in his reply:
The most common request in the comments is desktop app support. One user posted a video in reply with the caption: Claude code in desktop app please…
Code Mode is still experimental, and the official docs also say it may change or be removed in any version. To give feedback, run /feedback in the terminal.
This direction is worth watching: when an agent no longer calls tools one by one but writes its own scripts to orchestrate tools, its efficiency ceiling and failure modes both change. For developers, this is a signal worth testing the waters on.
References:
- Official docs: https://code.claude.com/docs/en/code-mode
- Addy Osmani's tweet: https://x.com/addyosmani/status/2124229492248019362
发布时间: 2026-11-22 05:36