DEV Community

Jeongki Park
Jeongki Park

Posted on Originally published at yardlet.app

What Is "Code Mode"? Direct Tool Calling vs. Sandboxed Scripts Across 10 Coding Agent CLIs

In mid-November, Anthropic added an experimental Code Mode to Claude Code (v2.1.323, behind CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1), letting the model write JavaScript to run multiple tool calls in one go instead of calling them turn by turn. Codex, OpenCode, and Pi already ship their own versions of it by default.

So what actually is Code Mode? When a coding agent talks to external tools over MCP (browsers, email, Slack, issue trackers, databases), there are now two fundamentally different ways it calls those tools and reads back the results: Direct Tool Calling and Code Mode.

Both patterns are often discussed around the same headline problem: hundreds of tool schemas crowding out the context window on turn one. Looking at how 10 coding agent CLIs actually load MCP tools today, and measuring 4,459 sandboxed script runs in production, shows something different. Most modern CLIs have already solved turn-one schema bloat. The real split between the two patterns is where intermediate tool results live and how multi-step reads travel through the context window.

Direct Tool Calling (one call per turn, raw result enters LLM context)
  Model -> callTool(A) -> [12 KB raw result into context] -> Model -> callTool(B) -> [raw result into context] -> Answer

Code Mode (multiple calls inside sandbox, distilled result enters LLM context)
  Model -> run_script(JS) -> [Sandbox: callTool(A) -> filter -> callTool(B) -> distill] -> [650 B JSON into context] -> Answer
Enter fullscreen mode Exit fullscreen mode

Direct Tool Calling vs. Code Mode at a glance

Dimension Direct Tool Calling Code Mode
Execution loop Model emits one structured tool call per turn; host executes and returns the raw result to context Model writes a short script; sandbox chains callTool() calls and returns one distilled JSON value
Where intermediate data lives Inside the LLM context window (re-read on every following turn) Inside sandbox memory (discarded once the script returns)
Schema loading Either eager (every schema on turn 1) or deferred via ToolSearch / tool_load Two compact meta-tools (search + run_script) stand in for hundreds of schemas
Approval granularity Native per-tool approval in the host CLI Must live inside the tool broker per inner call; outer wrapper approval is too coarse
Images & UI-rendered tools Native support (screenshots, suggestion chips, inline widgets render directly) Poor fit (scripts return distilled JSON and collapse inner calls into one entry)
Best suited for Single-shot actions, external writes needing clear confirmation, screenshots, UI tools Multi-step read-filter-read chains, noisy snapshots, cross-service aggregation

Within Direct Tool Calling, clients further split into eager loading (injecting every MCP tool schema on turn one) and deferred loading (keeping schemas behind an on-demand search tool until the model asks for them).

How 10 coding agent harnesses actually handle MCP tools

Before deciding whether an MCP server or workspace should add Code Mode, it helps to look at what the CLIs themselves already do. Inspecting source code, installed binaries, and documentation across 10 coding agent harnesses (as of late November 2026) shows that 8 of the 10 already avoid eager MCP schema loading by default, split into three groups:

Harness Default MCP mode What else it supports Key detail / constraint
Codex Native Code Mode + deferred (tool_search) Direct MCP calls inside its own exec runtime Already chains tool calls natively; adding an external Code Mode wrapper nests one inside another
OpenCode (2.4.1) Native Code Mode (execute + ~2k-token catalog) Direct exposure via per-server codemode: false in user config Falls back to global search(...) when the catalog overflows; codemode: false cannot be passed over ACP
Pi (1.6.1) Native Code Mode (searchTools()) deferred (tool_search) and direct modes via config/extension Adds only one line per MCP server to the system prompt by default
Claude Code Deferred Direct (ToolSearch) Experimental local Code Mode (CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1, v2.1.323+, interactive terminal only); anthropic/alwaysLoad: true; external MCP Code Mode servers Off by default for local Code Mode; in standard/SDK sessions, only alwaysLoad tools load full schemas on turn one
Grok Build (1.0.92) Deferred Direct (search_tool / use_tool) Always enabled in local mode; injects server instructions summary BM25 top-5 schema search; no alwaysLoad metadata flag
Hermes (0.21.2) Deferred Direct (tool_search: auto) Can be turned off in config.yaml (falls back to eager) Deferred index capped at the smaller of 4,000 tokens or 5% of context
Kiro CLI (3.6.1, V3) Deferred Direct (tool_load / tool_call) Pinning specific tools via toolSearch.neverDefer in user config Loads MCP tool schemas on demand by default; does not read _meta alwaysLoad
Cursor Agent Deferred Direct (get_mcp_tools / call_mcp_tool) Config-file MCP (mcp.json) and ACP session/new Writes tool schema JSON files under the project's MCP folder
Antigravity CLI (1.5.17) Lazy for config files; Eager for ACP session/new call_mcp_tool lazy loading + antigravity/alwaysLoad on mcp_config.json servers ACP servers are forced eager and share a 20,000-token customization-token-budget with skills and subagents; on overflow, it silently drops the largest items first
Kimi Code (0.36.0) Eager Direct Opt-in experimental tool-select (KIMI_CODE_EXPERIMENTAL_TOOL_SELECT) Sends every MCP tool schema on every turn unless the experimental flag and provider capability are enabled

That Antigravity ACP detail is easy to miss until it breaks a live session. Because its shared 20,000-token budget covers skills, workflows, subagents, and MCP servers together, and its truncation routine drops the largest items first, adding a few hundred bytes to parameter descriptions once pushed our core tools over the remaining budget and silently dropped our 12 largest tools (create_task, create_scheduled_task, spawn_task, run_agent, browser_snapshot, list_tasks, and six more) with no error.

Yardlet's MCP Code Mode and what 9 days of measurements showed

In Yardlet (a free, open-source native Mac app that runs these CLIs side by side), a workspace can connect to local and remote MCP services alongside Yardlet's own browser, session, and scheduling tools. Because Anthropic's experimental Code Mode is limited to interactive terminal sessions and does not run in stream-json or desktop-wrapped sessions, and harnesses like Antigravity CLI and Kimi Code lack a native Code Mode altogether, we implemented Code Mode at the MCP server layer (CodeModeToolCatalog.swift and CodeModeRunner.swift):

  • search_yardlet_tools: returns structured JSON ({count, groups, tools}), including full inputSchema whenever 10 or fewer tools match, and compact one-line summaries otherwise.
  • run_yardlet_script: executes model-authored JavaScript inside an isolated macOS JavaScriptCore sandbox with a synchronous callTool(name, args) bridge, no filesystem or network APIs, a 20-call cap, and a 30-second default timeout (60s max).

When Code Mode is active, connector tools are replaced on tools/list by those two meta-tools, while Yardlet's core tools remain directly listed (and callTool() can still reach both core and connector tools).

Turn-one prompt tokens: 90% smaller tools/list, almost 0% turn-one savings

With 9 connected services (Gmail, Calendar, Drive/Docs/Sheets/Slides, Mail, Slack, Linear, Notion, GitHub, and Stripe) totaling 280 connector tools plus 58 core tools, turning Code Mode on cut tools/list from 644.3 KB (~160k to 184k tokens) to 65.3 KB, an 89.9% drop.

Yet when we measured matched sessions before and after turning Code Mode on (deduplicating symlinked transcript paths via realpath), actual first-turn input tokens barely budged:

Harness tools/list size (9 services) Median first-turn input tokens (OFF -> ON) Why
Claude Code 644.3 KB -> 65.3 KB (-89.9%) 62,864 -> 61,482 (-2.2%, cache create 34,825 -> 32,579) Native ToolSearch already withheld 336 of 338 schemas; Code Mode only trimmed deferred name lines
Codex 643.4 KB -> 64.4 KB (-90.0%) 24,568 -> 25,220 (0% savings) Already runs its own native code mode and defers MCP schemas
Antigravity CLI 39.5 KB -> 39.7 KB (+0.5%) No schema reduction Connectors were already folded behind a 2-tool gateway there

This directly matches the 10-CLI audit above: if your host CLI already defers schemas, Code Mode will not give you a dramatic turn-one token win.

Mid-conversation results: 4,459 runs and 5.3x smaller payloads

The real win showed up during conversations, not on turn one. Across 9 days of production transcripts on my Mac Studio (November 24 at 19:35 KST through December 3, deduplicated by realpath and tool_use.id), Code Mode logged 4,459 sandboxed script runs:

Harness (Nov 24 to Dec 3) run_yardlet_script calls search_yardlet_tools calls Sessions using Code Mode
Claude Code 3,548 590 145
Antigravity CLI 911 597 192
Codex 0 0 0

Looking closely at the 3,548 Claude Code runs:

  • 60.0% (2,130 of 3,548) chained two or more callTool() invocations or ran a loop in a single turn (6,577 static inner calls total).
  • Error rate was 2.4% (84 of 3,547 tool results).
  • Mean result payload dropped 81.1% (5.3x smaller): run_yardlet_script returned a mean of 2,278 bytes (median 651 B, p90 6,462 B), compared to a mean of 12,028 bytes (median 178 B, p90 13,328 B) across 79,307 direct mcp__yardlet__* calls in the same window.

One honest caveat on that comparison: direct calls have a tiny median (178 B) because simple actions like clicks or short waits return minimal acknowledgements. Context bloat comes from the heavy tail of browser snapshots, email threads, and Slack histories that pushes the direct mean to 12 KB and p90 to 13.3 KB. Code Mode cuts that tail in half while collapsing multi-step read-filter-read chains into one turn.

Even more telling was which tools Claude Code chose to call inside run_yardlet_script:

Inner tool prefix inside run_yardlet_script Static callTool() count (Claude Code, 9 days)
browser_* 3,129
gmail_* 794
slack_* 742
list_* (tasks, projects, schedules) 662
send_* (inter-task messages) 466
read_* (tasks, terminal) 291
wait_* / linear_* / archive_* / create_* 280 combined

We originally added Code Mode to hide connector schemas. Yet nearly half of all inner script calls were browser_* tools, even though every browser tool stayed exposed directly on tools/list. Given both options, the model spontaneously routed noisy snapshot inspection and multi-tab reads through JavaScript, and left simple single-shot actions on direct calls.

Codex called run_yardlet_script 0 times over the same 9 days, confirming that nesting an MCP Code Mode wrapper inside a harness with its own native code mode adds nothing.

Three structural limits of Code Mode

Shipping Code Mode in production also exposed three constraints that Direct Tool Calling does not face:

  1. Authorization must move inside the broker per inner call. Under Direct Tool Calling, the host CLI distinguishes gmail_read_thread from gmail_send_message and prompts accordingly. Under Code Mode, the host only sees run_yardlet_script. If a user grants session-level approval on a read-only script, the outer CLI can no longer separate later reads from external writes. In Yardlet, every inner callTool() passes through the broker's own authorization: read-only services ask once per task, every external write, schedule change, or credential fill asks on every call (with no blanket session allow), and Plan / :read-only tasks hard-refuse state-changing inner calls even inside a script.
  2. Double-deferral burns extra turns. Initially, search_yardlet_tools and run_yardlet_script were not marked alwaysLoad: true, and category searches returned plain text. Claude Code spent an extra ToolSearch turn just to find the search tool, and scripts expecting JSON got {text: "..."}. Marking both meta-tools alwaysLoad: true and returning structured JSON (with inline inputSchema when 10 or fewer tools match) removed the extra hop.
  3. Images and UI-rendered tools must stay direct. A script bridge that distills output to JSON strips binary images (screenshots) and hides individual calls behind one run_script row. Tools whose direct call draws UI in the transcript, such as task suggestion chips (spawn_task) and inline HTML widgets (show_widget), do not render from inside a script. Yardlet excludes them from search_yardlet_tools and refuses them inside callTool() so the model calls them directly.

Choosing between the two

Neither mode replaces the other:

Situation Better fit
Single-shot action, external write needing clear confirmation, screenshot, or UI-rendered tool Direct Tool Calling
Multi-step read-filter-read chain over noisy snapshots, logs, mail, or Slack threads Code Mode
Host CLI already has native code mode (Codex, OpenCode, Pi) Direct / native (do not nest wrappers)
Host CLI loads MCP schemas eagerly (Antigravity ACP, Kimi Code) or attaches 30+ connector tools on a deferred CLI Code Mode (with per-inner-call broker approvals)

That is why Yardlet's Settings > General > Tasks > MCP Code Mode (CodeModePreference) defaults to Auto instead of a global switch: Off for Codex and Pi, On starting at 30+ connector tools for Claude Code, and On from the first connector for Antigravity and the other harnesses. The implementation is open source in Yardlet (yardlet.app).

Top comments (1)

Collapse
 
paragonaimag profile image
Paragon •

I write about AI measurement for a small publication, and your 89.9% tools/list drop with almost no turn-one savings is the pattern we keep running into — our Dev.to followers went from 5 to 7 over the two-week test, slowly, one measured post at a time.