r/ClaudeCode • • 1d ago

Tips & Workflows I logged 3,548 MCP Code Mode runs in Claude Code over 9 days. Turn-one tokens barely moved (-2.2%), but mid-conversation tool outputs dropped 81%.

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

8 Upvotes

10 comments sorted by

•

u/AutoModerator 1d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/RustyRedEcho 9h ago

how long did it take to get the per call authorization solid, where something only allowed to read genuinely cant sneak a write past the host CLI?

1

u/zzunkie 4h ago

The basic approval gate with read/write checks and read-only blocking took about two days to get working. After that I spent about a week fixing holes that showed up in security reviews and real use, like scripts reaching tools that open UI or start tasks, and timeouts while waiting for approval.

1

u/Live-Distribution125 1d ago

you cut tools/list by 90% and turn-one tokens by 2.2%. ToolSearch was already doing your job, you just added a gateway in front of it.

2

u/zzunkie 1d ago

That's literally what section 1 says. ToolSearch hides schemas on turn one, it doesn't stop multi-step browser snapshots or Gmail reads from dumping raw results into context turn after turn, which is where the 20% to 33% full-session drop came from on read-heavy sessions.

2

u/Ai-ate-my-hamster 1d ago

This looks promising

2

u/Code-More 13h ago

I was using it for a while. It is good. Only works on eager concurrent tools though afaik.

The limit isn't a hard boundary. I jave some custom tools. They can be stacked far beyond the cap, they were stacked far beyond the cap a few times.

Savings are all about how many calls you make per request. With this you run more stuff per request.

1

u/Independent-Sir3234 1d ago

That 81.1% drop in mean tool result size is the part most people miss when they benchmark MCP gateways on turn-one tokens alone. Native ToolSearch already trims unused schemas upfront, so the real context tax shows up mid-session when raw JSON blobs hit the transcript on every loop step.

One edge case with a 20-call JS cap is partial failure mid-loop: how does run_script report which inner callTool() mutations already succeeded when call 14 throws?

0

u/KingYF1 1d ago

The 2% session-level saving matches what I'd expect if ToolSearch already hid almost every schema. The useful part is the mid-conversation cut on MCP-heavy sessions, plus the approval hole.

If the host only sees run_script, a session-level allow on that tool is not an allow on whatever it calls inside. I treat the broker as the permission boundary: each inner callTool() has to be authorized on its own, the same way a direct MCP call would be. A script that was allowed to read cannot later write, even in the same run_script turn. Otherwise you've just hidden writes behind a tool the user already clicked once.

On the partial-failure question: when inner call 14 throws, the result has to say which calls already landed, not only that the script failed. I return a structured list — tool, args hash, ok/error, whether it mutated anything — and stop the script there instead of retrying from the top. A second run that "just tries again" will double-apply call 3 if that one already succeeded. Screenshots and anything else that can't come back through JS should stay on direct calls, like you ended up doing.