Anthropic added an experimental Code Mode to Claude Code (v2.1.323, behind CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1), where the model writes short JavaScript to chain tool calls instead of calling them one turn at a time. Since that flag only works in interactive terminal sessions and not in stream-json or wrapped desktop sessions, I built an MCP-level version (search + a sandboxed JavaScriptCore run_script with a 20-call cap and no filesystem/network access) and measured 9 days of actual Claude Code transcripts (Nov 24 to Dec 3, deduplicated by realpath and tool_use.id).
1. Turn-one prompt tokens barely changed
With 9 connected MCP services (280 connector tools + 58 core tools), turning Code Mode on shrank tools/list from 644.3 KB down to 65.3 KB (-89.9%). Yet matched sessions before and after showed median first-turn input tokens only moved from 62,864 to 61,482 (-2.2%, cache creation 34,825 to 32,579).
The reason is simple: Claude Code's native ToolSearch already withheld 336 of 338 schemas on turn one. Hiding them behind a Code Mode gateway mostly trimmed deferred name lines. (For comparison, Codex dropped 0% and called the MCP wrapper 0 times over the same 9 days because it already runs native code mode.)
2. The actual savings happened mid-conversation
Across 3,555 run_script calls in Claude Code main sessions through Dec 3:
- 60.0% chained two or more
callTool() calls or ran a loop in a single turn (6,577 static inner calls; parsing the runtime toolCalls count from script responses shows 9,756 actual inner calls, averaging 2.74 per script, with 27.8% containing loops). - Error rate was 2.4% (86 of 3,555 results).
- Text payloads shrank 61.7% to 74.4% (2.6x to 3.9x smaller) when matched tool-for-tool:
run_script returned 6.56 MB total (mean 1,844 B, median 534 B), compared to 17.1 MB (tool medians) to 25.6 MB (tool means) had those same 9,756 text calls run directly without screenshots.
The unexpected part was which tools Claude Code pulled into JS. Nearly half of all inner calls (3,129) were browser_* tools, followed by gmail_* (794) and slack_* (742), even though every browser tool stayed directly exposed on tools/list. Given both paths, the model used direct calls for quick clicks/waits and moved noisy DOM snapshots and multi-tab reads into JS to filter them before returning to context.
Full-session token impact: Reconstructing saved turns (3,602 to 6,214 fewer turns) and avoided downstream context re-reads up to compaction, minus 443 standalone search_yardlet_tools lookup turns (10% to 15% overhead):
- Across all 137 Claude Code sessions that used
run_script (126,424 turns total, where 97.2% of turns are ordinary coding/coordination), net full-session cost savings were 2.1% to 3.8% (2.6% to 4.5% at standard 0.1x cache-read pricing). - Across the 18 MCP- and browser-heavy sessions (where
run_script was at least 15% of turns), net full-session savings were 26.6% to 33.1% (per-session median 14.7% to 24.2%). - That matches our cleanest recurring scheduled task before/after Nov 24 (same prompt and model, n=10 before vs. n=34 after): turns dropped 20.0% to 24.3% (median 5 to 4), context growth dropped 26.8% to 33.2%, and warm-session cost normalized to the same starting context dropped 21.1% to 23.3%.
3. Three things that broke in practice
- Per-inner-call approvals: The host CLI only sees
run_script, not whether the script calls gmail_read_thread or gmail_send_message. Session-allowing one read script would bypass confirmation for later writes, so authorization had to move inside the MCP broker per inner callTool(), with external writes always prompting and Plan or read-only mode refusing state-changing calls. - Double-deferral overhead: Before marking both meta-tools
anthropic/alwaysLoad: true and returning structured JSON with inline inputSchema when 10 or fewer tools match, Claude Code burned an extra ToolSearch turn just to discover the search tool. - Screenshots and UI-rendering tools: Distilling script output to JSON strips binary screenshots and collapses UI-rendering tool calls into one script row. Those had to be excluded from
callTool() so the model keeps calling them directly.
Caveats: One developer's daily workload on macOS, not a controlled A/B benchmark. Even on text-only direct calls (58,774 calls, excluding screenshots), outputs are skewed (median 145 B vs. mean 690 B, 4.8x) because clicks and short waits return tiny acks while list_tasks (12.8 KB mean), read_task (9.7 KB), and browser_snapshot (1.3 to 5.3 KB) drive context growth.
Edit: Corrected the payload reduction figure from the 81% (5.3x) in the title. Re-checking the logs showed 95.2% of raw direct-call bytes came from base64 screenshots, which Code Mode cannot return. Excluding screenshots and matching text tools 1:1 gives 61.7% to 74.4% (2.6x to 3.9x) smaller payloads, and I added the full-session cost breakdown above (also updated in the blog post).
Full write-up with the 10-CLI comparison table (Claude Code, Codex, OpenCode, Pi, Cursor, Grok, Hermes, Kiro, Antigravity, Kimi): https://yardlet.app/blog/what-is-code-mode-direct-tool-calling.html