YardletBlog

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

Anthropic added experimental Code Mode to Claude Code (v2.1.323), while Codex, OpenCode, and Pi already ship it by default. What Code Mode is, how 10 coding agent CLIs handle MCP tools, and what 4,459 production runs in Yardlet measured.

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.

When a coding agent talks to external tools over MCP (browsers, email, Slack, issue trackers, databases), it now calls them and reads back results in one of two ways: Direct Tool Calling or Code Mode.

Both patterns are usually framed around the same turn-one problem: hundreds of tool schemas crowding out the context window. Auditing how 10 coding agent CLIs load MCP tools and measuring 4,459 sandboxed script runs in production points elsewhere. Most modern CLIs already solve turn-one schema bloat. The practical difference between the two modes is where intermediate tool results live and how multi-step reads move through the context window.

Direct Tool Calling vs. Code Mode at a glance

DimensionDirect Tool CallingCode Mode
Execution loopModel emits one structured tool call per turn; host executes and returns the raw result to contextModel writes a short script; sandbox chains callTool() calls and returns one distilled JSON value
Where intermediate data livesInside the LLM context window (re-read on every following turn)Inside sandbox memory (discarded once the script returns)
Schema loadingEither eager (every schema on turn 1) or deferred via ToolSearch / tool_loadTwo compact meta-tools (search + run_script) stand in for hundreds of schemas
Approval granularityNative per-tool approval in the host CLIMust live inside the tool broker per inner call; outer wrapper approval is too coarse
Images & UI-rendered toolsNative support (screenshots, suggestion chips, inline widgets render directly)Poor fit (scripts return distilled JSON and collapse inner calls into one entry)
Best suited forSingle-shot actions, external writes needing clear confirmation, screenshots, UI toolsMulti-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 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:

HarnessDefault MCP modeWhat else it supportsDetail / constraint
CodexNative Code Mode + deferred (tool_search)Direct MCP calls inside its own exec runtimeAlready 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 configFalls 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/extensionAdds only one line per MCP server to the system prompt by default
Claude CodeDeferred 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 serversOff 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 summaryBM25 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 configLoads MCP tool schemas on demand by default; does not read _meta alwaysLoad
Cursor AgentDeferred Direct (get_mcp_tools / call_mcp_tool)Config-file MCP (mcp.json) and ACP session/newWrites tool schema JSON files under the project's MCP folder
Antigravity CLI (1.5.17)Lazy for config files; Eager for ACP session/newcall_mcp_tool lazy loading + antigravity/alwaysLoad on mcp_config.json serversACP 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 DirectOpt-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:

Harnesstools/list size (9 services)Median first-turn input tokens (OFF -> ON)Why
Claude Code644.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
Codex643.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 CLI39.5 KB -> 39.7 KB (+0.5%)No schema reductionConnectors were already folded behind a 2-tool gateway there

That matches the 10-CLI audit above: when the host CLI already defers schemas, Code Mode saves almost nothing on turn one.

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

The savings showed up during conversations instead. 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 callssearch_yardlet_tools callsSessions using Code Mode
Claude Code3,548590145
Antigravity CLI911597192
Codex000

Across 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 caveat on that comparison: direct calls have a tiny median (178 B) because simple actions like clicks or short waits return short 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.

The inner tool breakdown shows what Claude Code chose to run inside run_yardlet_script:

Inner tool prefix inside run_yardlet_scriptStatic 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 added Code Mode to hide connector schemas, yet nearly half of all inner script calls were browser_* tools even though every browser tool stayed on tools/list. Given both options, the model routed noisy snapshot inspection and multi-tab reads through JavaScript and left single-shot actions on direct calls.

Codex called run_yardlet_script 0 times over the same 9 days. 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 refuse state-changing inner calls even inside a script.
  2. Double-deferral burns extra turns. At first, 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:

SituationBetter fit
Single-shot action, external write needing clear confirmation, screenshot, or UI-rendered toolDirect Tool Calling
Multi-step read-filter-read chain over noisy snapshots, logs, mail, or Slack threadsCode 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 CLICode 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).