{"slug": "anthropic-s-claude-code-rewrites-multi-tool-workflows-in-javascript-to-cut-token", "title": "Anthropic's Claude Code Rewrites Multi-Tool Workflows in JavaScript to Cut Token Use", "summary": "Anthropic shipped Code Mode in Claude Code v2.1.323, an experimental opt-in feature that lets Claude write JavaScript programs to batch tool calls through an internal REPL tool and return only the final result instead of every intermediate output. The feature is enabled with the environment variable CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1, requires confirmation, and preserves existing deny rules, ask rules and PreToolUse hooks on each nested tool call; Anthropic notes the widely cited 37% token-savings figure comes from its separate Programmatic Tool Calling post, not Code Mode. Code Mode targets multi-step refactors, log triage and pipelines, where a ten-step workflow can run in one programmatic turn rather than ten model-directed turns, while administrators can disable it for managed users.", "body_md": "# Anthropic's Claude Code Rewrites Multi-Tool Workflows in JavaScript to Cut Token Use\n\nClaude Code 2.1.323 ships an opt-in Code Mode where Claude writes JavaScript to batch tool calls, cutting token overhead on multi-step work.\n\n- Claude Code v2.1.323 adds experimental [Code Mode](https://code.claude.com/docs/en/code-mode?utm_source=alphasignal) , where Claude writes JavaScript to batch tool calls.\n- Enable with `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1` , then confirm the opt-in prompt.\n- Script runs through a REPL tool, returning only the final result instead of every intermediate output.\n- Deny rules, ask rules and PreToolUse hooks still apply to each tool call inside the script.\n- Best for multi-step refactors, log triage, and pipelines; irrelevant for one-shot edits.\n- The viral 37% token-savings figure is from Anthropic's Programmatic Tool Calling post, not Code Mode.\n\nAnthropic has added [Code Mode](https://code.claude.com/docs/en/code-mode?utm_source=alphasignal), an experimental execution path that lets Claude compose tool calls in a JavaScript program. The program can invoke tools such as `Bash`, `Read`, and `Edit`, filter their output, and return a consolidated result to the conversation. The feature is off by default.\n\nCode Mode arrived in [Claude Code v2.1.323](https://dev.to/raxxostudios/claude-code-21323-adds-code-mode-for-javascript-tool-calls-3ibk?utm_source=alphasignal). It targets workflows where repeated tool calls consume agent turns and fill the context window with intermediate output. Bundling those calls can reduce round trips, limit token use, and let conversations continue while long-running commands execute.\n\n## One script replaces repeated turns\n\nClaude Code’s standard agent loop handles each tool invocation separately:\n\n1. Claude requests a tool call.\n2. The runtime executes it and returns the result.\n3. Claude reads that result and chooses the next action.\n4. The sequence repeats until the task is complete.\n\nEach result enters the conversation context, including output that Claude may need only long enough to select the next file or command. Large searches, logs, and multi-file operations can therefore consume substantial context before producing a useful answer.\n\nCode Mode compresses that sequence into a JavaScript program sent to an internal tool named `REPL`. The program can loop over files, run independent calls concurrently, parse command output, apply conditions, and return the relevant result. A ten-step workflow can occupy one programmatic turn instead of ten model-directed turns.\n\nThe interface continues to show ordinary tool activity and edit diffs. Users do not have to read a stream of generated JavaScript during normal operation.\n\n## Enable it from the shell\n\nClaude Code v2.1.323 or later reads the experimental flag from the environment of the process that launches it. Use the command for the current shell:\n\n- \n**Bash or zsh** code\n\n```\nexport CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1\nclaude\n```\n\n- \n**PowerShell** code\n\n```\n$env:CLAUDE_CODE_EXPERIMENTAL_CODE_MODE = \"1\"\nclaude\n```\n\n- \n**Windows Command Prompt** code\n\n```\nset CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 && claude\n```\n\nClaude Code asks for confirmation before enabling the feature. The environment variable applies to the current shell session unless it is added to a shell profile or system configuration. Organization administrators can disable Code Mode for managed users, and Anthropic warns that the experimental feature may change or be removed.\n\n## Permissions still apply inside scripts\n\nCode Mode preserves Claude Code’s existing permission controls. Every tool invocation created by the program still passes through deny rules, ask rules, and `PreToolUse` hooks.\n\n- **Tool policies:** Each nested call is checked before execution.\n- **Script inspection:** A`PreToolUse` hook targeting`REPL` can inspect the generated JavaScript in`tool_input.code` .\n- **Automatic approval:** In auto mode, the classifier evaluates the complete script.\n\nReview becomes more complex when one program coordinates many operations. Individual calls remain subject to policy, but the program’s loops, branches, and data flow require broader inspection than a single explicit tool request. Teams that log or audit tool use should include `REPL` inputs in that process.\n\n## Best on orchestration-heavy work\n\n| Workflow | Potential benefit | \n|---|---|\n| Repository search | Searches many paths, filters matches locally, and returns only relevant files. | \n| Batch refactoring | Applies a predictable transform across multiple files in one program. | \n| Log triage | Parses large outputs before they enter the conversation context. | \n| Conditional pipelines | Runs a command, evaluates its output, and selects the next tool call. | \n| Parallel inspection | Reads independent files or resources concurrently. | \n| Long-running commands | Keeps the conversation available while execution continues. | \n\nSingle-file edits, one-shot questions, and workflows that require approval at every step gain less from the feature. Code Mode leaves existing behavior unchanged until a user or organization enables it.\n\n## The 37% claim needs context\n\nAnthropic reported a 37% token reduction for its API’s [Programmatic Tool Calling](https://www.anthropic.com/engineering/advanced-tool-use?utm_source=alphasignal) benchmark. Anthropic has not published an equivalent benchmark for Claude Code’s Code Mode.\n\nThe two features share an architectural idea: the model writes code that coordinates several tools and limits the data returned to its context. Actual savings depend on the task. Workflows with many calls and large intermediate results have more room for improvement than short tasks with compact outputs.\n\n## Measure the tradeoffs on real tasks\n\nTeams evaluating Code Mode can compare it with the standard loop on the same repository and task. Useful measurements include:\n\n- Total input and output tokens\n- Elapsed time\n- Number of model turns\n- Permission prompts and denied calls\n- Tool failures and retries\n- Accuracy and quality of generated diffs\n\nTests should run on an isolated branch with existing permission rules intact. Logging `REPL` scripts through a hook provides an audit trail and exposes orchestration errors that may be harder to spot from the final result alone.\n\nCode Mode moves orchestration into code that Claude writes for each task. Loops, branches, concurrency, and local filtering can make multi-tool workflows more efficient, while the broader execution scope raises the value of hooks, logs, and careful review.", "url": "https://wpnews.pro/news/anthropic-s-claude-code-rewrites-multi-tool-workflows-in-javascript-to-cut-token", "canonical_source": "https://alphasignal.ai/news/anthropic-s-claude-code-rewrites-multi-tool-workflows-in-javascript-to-cut", "published_at": "2026-11-17 21:18:55+00:00", "updated_at": "2026-11-18 00:10:09.964556+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models", "ai-products"], "entities": ["Anthropic", "Claude Code", "Claude Code v2.1.323", "Code Mode", "REPL", "PreToolUse"], "also_reported_by": [], "takeaway": "Enabling CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 in Claude Code v2.1.323 lets Claude batch tool calls like Bash, Read and Edit into one JavaScript program run through the REPL tool, collapsing a ten-step workflow into one programmatic turn while deny rules, ask rules and PreToolUse hooks still check ea", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/anthropic-s-claude-code-rewrites-multi-tool-workflows-in-javascript-to-cut-token", "markdown": "https://wpnews.pro/news/anthropic-s-claude-code-rewrites-multi-tool-workflows-in-javascript-to-cut-token.md", "text": "https://wpnews.pro/news/anthropic-s-claude-code-rewrites-multi-tool-workflows-in-javascript-to-cut-token.txt", "jsonld": "https://wpnews.pro/news/anthropic-s-claude-code-rewrites-multi-tool-workflows-in-javascript-to-cut-token.jsonld"}}