Within about two weeks this summer, three teams that rarely agree on anything shipped the same feature. OpenAI put it in GPT-5.6 when the model went generally available on July 9. Anthropic had already productized it for Claude. Pydantic built the open-source version. They gave it different names — programmatic tool calling, code mode — but it is one idea, and it is worth understanding as one idea before you pick a flavor.
The one idea#
Normal tool use is a conversation of interruptions. The model wants to call a tool, so it emits a JSON blob and stops. Your code runs the tool, hands back the result, and the model resumes — one full inference pass per call. For an agent that touches twenty tools to answer a question, that is twenty round trips, and every intermediate result those tools return gets stuffed back into the model's context whether it matters or not.
Code mode replaces the conversation with a program. Instead of one call per turn, the model writes a short script that calls all the tools it needs — with loops, conditionals, and parallelism — inside a sandbox. The tools run. The script filters their output down to the few lines that matter. Only that distilled answer comes back to the model. The twenty round trips become one, and the kilobytes of line-items the model never needed to read never enter its context.
The win isn't cleverness. It's arithmetic: every tool definition and every bulky result that round-trips through the model costs a token and an inference pass. Code mode stops the round-tripping.
Anthropic's numbers make the arithmetic concrete: on a 75-tool project-management agent, turning the feature on cut billed input tokens by roughly 38% with no change in accuracy. Across production traffic, requests carrying 10 to 49 tool definitions see typical savings of 20–40%. As a rule of thumb, calling ten tools directly costs about ten times the tokens of calling them in code and returning a summary.
Where the three differ#
If the idea is shared, the engineering is not. Three axes decide which one fits you.
Language. GPT-5.6 writes JavaScript; Claude and Pydantic CodeMode write Python. This matters only if you want to reuse helper code inside the sandbox or your team reasons better in one language. It does not change the mechanic.
Hosting and lock-in. This is the real fork. OpenAI runs your model's JavaScript in a hosted, isolated V8 runtime with no network access, exposed through the Responses API — convenient, and bound to that API. Anthropic runs the Python in a managed code-execution sandbox it operates for you; you keep your ordinary tool definitions and mark which the sandbox may call. Pydantic's CodeMode wraps all your tools into a single run_code tool and runs the model's Python inside Monty, a Rust interpreter you host yourself, with microsecond startup and no container orchestration to bill against. The first two are managed convenience with a vendor attached. The third is portable: Monty runs against any model, so the same efficiency win survives a model switch.
The sandbox is walled on purpose. OpenAI's V8 has no network; Monty exposes only the functions you explicitly pass it. In every case the model's code can reach your tools and nothing else — which is the security story that makes running model-written code tolerable in the first place.
What you give up — the same thing, everywhere#
All three share one cost, and it is easy to miss until an eval breaks. Intermediate tool results never enter the model's context. That is precisely where the token savings come from — and precisely what your tracing and trajectory evals used to read. If your eval harness grades the sequence of tool calls an agent made, it is now grading a summary the code produced, not the observations the model saw. Re-instrument at the sandbox boundary, not at the model.
For the full mechanics of the Claude implementation — including allowed_callers and the models that support it — see our companion piece, Programmatic Tool Calling, Explained. For the deeper pattern this all descends from, see MCP code execution vs. direct tool calls.
The decision, in one breath#
Already single-vendor on OpenAI or Anthropic? Use their native version — it is the least code you will write, and the savings are free. Running more than one model, or unwilling to weld your agent to one company's runtime? Pydantic AI CodeMode buys you the same collapse of round trips without the lock-in, because the sandbox is yours.
And if your agent makes one tool call per task, ignore all of it. Code mode pays off with the count of tools and the size of the data you throw away. For a single lookup, plain tool calling is simpler, faster, and — still — the only version you can fully watch.



