Code Mode and the cost of using tools
Code Mode changes how tools are called and which data reaches the model. I reviewed documentation from Cloudflare, Anthropic, and OpenAI and preprints on context and caching. I did not run a benchmark of my own.
Think of any paginated query. With direct calls, the result of every page goes back to the model. In the programmatic flow, the code uses the cursor, requests the following pages, and returns only an excerpt to the model. The example is conceptual. Cloudflare describes pagination as one of the operations the code can coordinate.

The code-based flow can save calls to the model, but it does not eliminate the external requests needed to get the data: the pages are still requested. The difference lies in which intermediate results reach the context window.
The mechanism
Cloudflare’s article on Code Mode compares two ways of chaining tools. In the first, the responses go back to the model. In the second, the code passes the output of one call straight to the next. The implementation it describes converted the MCP tools into a TypeScript API and gave the model an execution tool. The code ran in an isolate, and the SDK forwarded the calls to the MCP servers. In that prototype, the entire TypeScript API went into the context.
Anthropic’s post on code execution with MCP separates the tokens of tool definitions from the tokens of intermediate responses. It shows three things: selective tool discovery, in which only the definitions needed for the task are loaded; filtering rows before the result goes back to the model; and control loops. The article does not detail a breakdown identical to Cloudflare’s interface count, so the numbers from the two are not directly comparable.
Cloudflare’s catalog count
In Cloudflare’s article describing the API in 1,000 tokens, the Cloudflare API MCP server has two tools, both running on Dynamic Workers. search runs code over a representation of the OpenAPI specification. execute composes the API calls, including for pagination. The full Cloudflare API specification has more than 2,500 endpoints. The two tools add up to about 1,000 tokens, against 1.17 million tokens for an equivalent catalog with all the definitions, measured with tiktoken. The difference in the estimated size of the interfaces is approximately 99.9%. This calculation measures only the tokens of tool definitions. It does not measure price, time, number of calls, or success rate.

Claude Code and OpenAI’s Programmatic Tool Calling
In Claude Code, Code Mode is experimental and off by default. It is available starting with native Claude Code 2.1.323, in an interactive terminal, as long as the requirements in the guide are met. Claude writes JavaScript with tool calls, and Claude Code runs that code in its own session, including with tools such as Bash, Read, and Edit. The Ctrl+O shortcut opens the transcript viewer, where you can expand the Code lines and read the JavaScript.
Every call made in Claude Code’s Code Mode goes through the deny and ask rules and through PreToolUse hooks. MCP tool search in Claude Code is a separate feature: it loads descriptions on demand in compatible configurations.
In OpenAI’s Programmatic Tool Calling, each JavaScript program runs in a fresh V8 isolate, with no JavaScript state persisting between programs and no direct network access. Access to external systems goes through the tools made available. In the Responses API, the application decides which eligible tools can be called directly, from code, or both ways, and it keeps executing the functions that belong to it. For MCP, the require_approval policy can pause the program. The documentation recommends the feature for large results, aggregation, and dependent calls with a predictable data flow. For steps that depend on approval, it recommends direct action as the default.

OpenAI’s Tool Search loads the definitions of tools declared as deferred. In the Responses API, it is a top-level tool. A tool it finds can be called by a later program if that tool allows programmatic calls. On both platforms, then, on-demand search acts on the definitions, and code execution can filter results inside the execution environment.
What the preprints say about caching and context
The preprint Context Has a Price, by Yang et al., published on November 17, 2026, gathers more than 20,000 runs of open models on SWE-bench Verified, SWE-bench, and Loc-Bench. The authors estimated cost from the logged tokens, using relative prices for fresh input, cached input, and output. With no discount for cached input, removing old observations reduced the estimated cost by between 19% and 36%. With cached input costing one tenth of fresh input, the same removal raised the estimated cost by between 38% and 116%. These are costs estimated under relative rates, not a measured API bill, and they refer to the comparison between the arms of a context editing study, not to a Code Mode benchmark. The authors also saw that smaller prompts can change the number of steps the agent takes.
Anthropic’s documentation on context editing says that, in the Claude API, removing old tool results invalidates the cached prefixes and incurs the cost of a new write. The preprint approximates cache reuse without reproducing each provider’s write charges.

Two preprints deal with different things and should not be confused. In Recursive Language Models, by Zhang, Kraska, and Khattab, first published in December 2025, the long input is stored in an external environment, and the model operates on it through code: it reads excerpts, decomposes the problem, and launches model subcalls. In Context Language Models, by Shao et al., published on September 29, 2026, the model itself manages its context as an editable file. Section 5.3 of that work evaluates Suffix Cache Reuse. The authors report 35% less server compute compared with standard SGLang, with equivalent performance in the tested scenario. The number refers to server compute and holds for the hardware and configuration of that evaluation.

How to measure cost and correctness on the same task
This review was based on documents. I read official documentation, vendor technical articles, and preprints, and compared the denominators, prices, and baselines each one publishes. I consulted the sources on November 19, 2026. I did not run a benchmark of my own.
For a future test, OpenAI’s guide advises starting from direct calls and comparing the two flows on representative tasks. The evaluation covers correctness, completeness, evidence, latency, and cost. A fictional query with a reference table makes it possible to define in advance which records and values are expected. In both flows, the model, the tools, and the data need to be comparable.
The catalog count, the cost of a task, and the effect of caching each have their own units and baselines. Cloudflare’s count measures definition tokens. The context editing study shows that the price of cached input can flip the sign of the estimated savings.
Agent draft from the listed sources; reviewed and approved by Lucas Fuad