
A benchmark record published 2026-11-24, based on three controlled tasks run against a mock MCP server across Claude Code and Codex. This guide restates the experiment, measurements, and recommendations in a revised structure while retaining the reported figures.
1. What Code Mode Actually Changes
Code Mode asks the model to write a short piece of code that calls tools, instead of invoking one tool per turn and loading every returned result into the context window.
Claude Code introduced the feature as an experimental toggle in version 2.1.323. The November 23 release 2.1.331 extended it to more cloud platforms. On the Codex side, the 12 models in the model directory run Code Mode by default.
To measure where the mode saves money, the authors built a mock MCP server and defined three tasks. Within Claude Code, each task was run three times under direct invocation, tool search, and Code Mode; the same tasks were then run with Codex's default configuration. The total was 36 runs, and every run returned the correct answer.
2. Headline Findings from the 36 Runs
Large-result, small-answer task. The task made 21 tool calls, pulled in roughly 270 KB of data, and produced an answer of only 34 items. After Code Mode was enabled in Claude Code, input tokens fell from 169,000 to 90,000, and cost dropped from $0.89 to $0.14 — an 84% saving. Latency fell from 36 seconds to 25 seconds. The request count rose from 4 to 6.
One- or two-call task. With Code Mode, input tokens climbed from 21,000 to 39,000, and cost became 65% higher. The absolute difference was about one cent.
Task exposing 206 tools. Tool search and Code Mode produced nearly identical cost. With tool search disabled and a cold cache, a single run cost $0.63.
How reversible the feature is. Codex's Code Mode is written into the model metadata served from the backend and cannot be turned off with --disable. Claude Code's implementation remains an experimental toggle and works only inside interactive sessions.
The saving in Code Mode comes from keeping intermediate data out of context. It does not reduce the number of requests. In T1, direct invocation wrote 98,000 tokens of tool results into the cache, while Code Mode wrote only 9,500; almost the entire cost gap traces to this difference. Whether to enable the mode should depend on how large the tool results are and how little of them is finally used, not on how many tools are called.
By these figures, Claude Code users should enable Code Mode by default for MCP-based data consolidation: T1 saves $0.75 per run, while T2 costs about one cent more, a ratio of roughly 60x. The real constraint lies elsewhere. The mode works only in interactive sessions; the CI command claude -p cannot use it.
3. The Two Token Overheads Code Mode Addresses
Anthropic's November 2025 engineering post "Code execution with MCP" separates MCP token overhead into two categories. The first is tool definitions: most clients load every definition into context at the start of the session. The second is intermediate results: the return value of every call passes through the model. The proposed treatment turns MCP tools into code APIs, lets the model load definitions on demand, processes data inside the execution environment, and returns only the result. The posted example reduced token usage from 150,000 to 2,000.
Cloudflare proposed a Code Mode-style approach earlier, in September 2025, with a slightly different rationale: the model writes code more reliably than it forms direct tool calls, because real TypeScript appears far more often in training data than tool-call examples do. Cloudflare also notes that the approach pays off most when several calls must be chained together.
Of the two overhead categories, the tool-definition problem in Claude Code is already handled by tool search, which is on by default; the T3 results below confirm this. In today's Claude Code, Code Mode mainly addresses the second category: the intermediate data returned by tools.
Code Mode in both CLIs is no longer limited to MCP. With it enabled in Claude Code, Bash, Read, and Edit are all invoked from within a script; Codex shell commands are likewise called from an exec script. MCP remains the clearest case, because its returns are often large JSON payloads.
4. Experiment Design: Mock Server and Three Tasks
A prior third-party benchmark by José Antonio Garrido on November 21 tested Claude Code's Code Mode, but its Claude Code portion covered a single task with three runs. This study follows that task structure, uses a self-written mock MCP server, and adds Codex to the comparison.
The mock server is implemented on the Python standard library and simulates a code hosting organization: 20 repositories, 320 issues, and 6 read-only tools. Data is generated from a fixed random seed; ground truth is computed in advance by code, and the final answer of each run is judged by code as well.
Three tasks each isolate one scenario:
- T1. Find open bugs with no activity for three weeks across the 20 repositories, list them by repository, and count by assignee. The task needs 21 tool calls.
list_issuesreturns a combined 345 KB, and the answer contains only 34 items. This is the classic Code Mode scenario. - T2. Count open issues in
payments-api. One or two calls suffice; this serves as the control group. - T3. Same as T2, but the server mounts 206 tools whose definitions total 196 KB, to measure the cost of the definitions themselves.
Claude Code was tested under three modes: direct invocation with tool search off (ENABLE_TOOL_SEARCH=false), the default tool search, and Code Mode. Codex was tested only in its default mode, because its system prompt is written around Code Mode; forcing a reverse configuration in the model directory would not produce a fair control. Each mode was run three times per task, for 36 runs total.
4.1 Configuration and Metering
- Claude Code 2.1.331, Opus 5.5. All three modes ran in interactive sessions, which is the only way Code Mode can be switched on. Sessions were driven by tmux so that system prompts stayed consistent. Personal settings, hooks, and plugins were excluded, and only this one MCP server was connected. Built-in tools were reduced to the single one required by each mode: REPL, ToolSearch, or the MCP connection-wait tool. Cost uses the API price estimate recorded by Claude Code itself; subscription users consume quota rather than these billed amounts.
- Codex 0.172.0, GPT-6.2 Sol. Runs use
codex execwith default reasoning effort. Personal configuration, rules, andAGENTS.mdare not loaded, and no skill list is attached. Cost is converted from request tokens at official prices: input $2, cache hit $0.10, and output $10 per million tokens.
The study has four limitations. There is one mock server and three tasks; only MCP tools were measured, while the savings of Code Mode for built-in tools such as Bash and Read were not tested; three runs per cell is enough only to separate order-of-magnitude differences; and the two models carry different unit prices, so cross-vendor comparison should read tokens rather than raw cost.
5. Results
The T1 cost per run, taken as the median of three runs and converted at API prices, breaks down as follows: direct invocation $0.89; tool search $0.91; Code Mode $0.14, an 84% saving; Codex default $0.06, on GPT-6.2 Sol whose unit price is about half.
For T2, a single-tool-call task, Code Mode costs 65% more: $0.030 against $0.018 for direct invocation. For T3 with 206 tools, tool search and Code Mode are effectively tied: $0.055 against $0.054.
5.1 T1: the saving is cache writes; requests increase instead
Under direct invocation, Opus 5.5 works in two request rounds, issuing 10 list_issues calls in parallel each round, for 4 requests in total. The price is that all open issues from the 20 repositories enter context, about 273 KB: 169,000 input tokens, of which 98,000 are cache writes.
Cache writes in the main Claude Code session fall under the one-hour tier. Opus 5.5 prices at $8 per million tokens, roughly 40 times the cache-hit price, so cache write volume carries the weight of that cost gap. Codex's T2 ran at $0.0252 with the same 3-request structure.
5.2 T3: with many tools, tool search is already sufficient
With tool search off, the 206 tool definitions are attached to every request; two requests total 223,000 tokens. A warm cache run costs $0.059; the first run, with a cold cache, costs $0.63.
Tool search and Code Mode each load only the definitions actually used, at $0.054 and $0.055 respectively. Code Mode adds no benefit here, because the tool-definition problem is already solved by tool search.
Garrido measured on the Claude API that, with many tools, programmatic tool calling is the most expensive option because it loads every definition. That conclusion does not hold inside Claude Code: Code Mode also lazy-loads definitions, and shows no penalty on T3.
Codex used 95,000 tokens on T3, nearly twice its T2 usage. The same pattern appeared in all three runs. The model first filters by server-name prefix over ALL_TOOLS, lists all 206 tools at once, and emits about 48,000 tokens, truncated to roughly 10,000, before narrowing the scope. This reflects the setup where all 206 tools sit on one server; in a real deployment tools are spread across several servers, and prefix filtering is more accurate. It also shows that Codex's current tool discovery relies entirely on the model writing its own filter condition.
5.3 Codex's fixed overhead
Each Codex request carries at least 16,000 input tokens from the system prompt and the exec tool descriptions, about 27,000 characters. This portion is identical across the three tasks, so T2's three requests already account for 50,000 input tokens.
Another easy-to-miss overhead is the skill list. In the first test round it was not disabled; all 128 locally installed skills were listed into context. --ignore-user-config does not block this. Each request adds roughly 10,000 tokens, and T2's input rises from 50,000 to 81,000.
On latency, three of Codex's nine runs had the first model response queued server-side for 5 to 7 minutes; the scripts and tools themselves took only seconds. This is server-side fluctuation, so latency is compared only among Claude Code's three modes.
6. Choosing an Invocation Method by Task
The decision rule follows the shape of the tool results rather than the call count:
- Large returned data, only a small fraction used: enable Code Mode; measured saving 84%.
- Only one or two tool calls: leave it off; measured cost increase 65%.
- Many attached MCP tools: the default tool search is enough.
- Running in CI with
claude -p: Code Mode is unavailable.
After the mode is enabled, the model makes more calls to verify its work. In T1 it issued 106 calls, five times the number actually needed.
6.1 Enable Code Mode for data consolidation
Tasks that suit Code Mode share one trait: tool results are large, and only a small portion is finally used. Multi-repository summaries, log filtering, and statistics after batch file reads all fall into this category.
Claude Code users can set CLAUDE_CODE_EXPERIMENTAL_CODE_MODE in the env section of ~/.claude/settings.json; the setting applies to later interactive sessions. Small one- or two-call tasks do not save materially with it on, so there is no reason to toggle back and forth.
6.2 Leave the many-tools problem to tool search
When many MCP servers are connected, the dominant cost is tool definitions, and that is what tool search addresses; it is on by default in Claude Code. Do not set ENABLE_TOOL_SEARCH=false just so the model can "see all tools": a T3 cold-cache run costs $0.63, more than 11 times the equivalent run with tool search enabled.
6.3 Watch call volume and permission review
Code Mode makes tool calls cheaper, and the model then calls tools more often. On pay-per-use or rate-limited APIs, limits should be enforced at the server side; the model cannot be relied on for restraint. In practice, an API gateway such as 4sapi can sit in front of these backends and apply rate limits, quota, and key policy per route, so uncontrolled call volume does not translate directly into billed requests.
Permission review granularity also changes. Auto mode reviews the whole code block and cannot see parameters computed at runtime. Commands that must be blocked should be written as ask or deny rules, or inspected through a PreToolUse hook matched against the REPL.
6.4 Codex users: write clear tool descriptions and manage the skill list
Codex needs no setting; Code Mode is the default. When writing an MCP server, tool names and descriptions should let the model locate a tool with a simple filter condition, because Codex searches ALL_TOOLS from within the script.
A large installed skill list directly raises the fixed overhead of every request. Disable unused skills by name, or set a smaller budget for the skill list with skills.max_context_tokens.
7. Reading the Benchmark Against Your Own Workload
The clearest signal in this data is that Code Mode's value tracks result size, not call count. A task that pulls wide payloads and narrows them down keeps most of its intermediate data on the server side and saves on cache writes; a task that needs a single small response adds script overhead for little return. Tool definitions are a separate problem, addressed by lazy loading through tool search rather than by Code Mode itself.
Before generalizing these numbers, check the three measurement conditions used here: a mock server with fixed data, three runs per cell, and two models with different pricing. Production workloads with large built-in tool sets, long session context, or mixed MCP servers may shift the balance. The next useful measurement for an existing setup is the per-result payload size and the fraction retained in the final answer; those two figures predict the Code Mode outcome more reliably than the call count alone.
Comments
Join the discussionNo comments yet. Be the first to comment.



