Most Claude agents still talk to their tools the slow way: Claude asks for one tool, waits for the answer, reads the whole result, then asks for the next one. Every round trip costs tokens and time, and every tool result lands in the model’s context window whether Claude needs it or not. Anthropic’s programmatic tool calling flips that around. You add one field to a tool definition, and Claude calls your tools as Python functions inside a code execution sandbox — looping, filtering and aggregating in code, and sending only the final answer back to the model. Anthropic’s own documentation now covers the feature in full, and it arrived alongside Claude Code v2.1.334 on 2 December 2026. Here is how it works, how to set it up, and when it is actually worth using.
What programmatic tool calling actually does
In the traditional flow, a tool call is a conversation. Claude emits a tool_use block, your application runs the tool, and you send the result back as a tool_result. Claude reads it, decides what to do next, and the cycle repeats — one model round trip per call, with every intermediate result eating context.
Programmatic tool calling breaks that cycle. When a tool is configured for it, Claude writes Python code that calls the tool as an ordinary function, and that code runs in Anthropic’s sandboxed code execution container. The code can call the tool many times, in a loop, with branches and filters, and only the final output of the script ever reaches Claude’s context window. The intermediate results never do.
Anthropic’s own example makes the difference concrete: checking budget compliance across 20 employees the traditional way needs 20 separate model round trips, pulling thousands of expense line items into context along the way. With programmatic tool calling, a single script runs all 20 lookups, filters the results, and returns only the employees who exceeded their limits — shrinking what Claude needs to reason over from hundreds of kilobytes down to a few lines.
The switch is a single field. Add allowed_callers: ["code_execution_20260120"] to a tool definition, and that tool becomes callable from inside code execution. Nothing else about the tool changes: same name, same description, same input schema.
Set it up in four steps
The setup follows Anthropic’s documented workflow exactly. The code below is illustrative, based on the request shape in Anthropic’s documentation — the field names and the pause-and-resume flow are the documented ones.
Step 1: Add code execution to your tools array
Programmatic tool calling requires the code execution tool, version code_execution_20260120 or later. Include it in the tools array of your Messages API request, alongside your own tools.
Step 2: Mark your tools as callable from code
Add the allowed_callers field to each tool Claude should be able to call from code. There are three modes:
| allowed_callers value | What it means |
|---|---|
["direct"] | Claude calls the tool directly, the traditional way (the default if you omit the field) |
["code_execution_20260120"] | Claude calls the tool only from inside code execution |
["direct", "code_execution_20260120"] | Claude may call the tool either way |
A second version string, code_execution_20260521, is also accepted and is interchangeable with code_execution_20260120 in allowed_callers. Before enabling the feature, check whether your model supports it: read the model’s capabilities.code_execution.supported value from the Models API. Claude Haiku 4.5 accepts the code execution tool version but does not support programmatic tool calling, so do not assume support from the version string alone.
Step 3: Send the request and handle the pause
When Claude decides a tool is needed, it writes Python that calls it, and code execution pauses. The API returns a response with stop_reason: "tool_use", a container ID, and a tool_use block whose caller field identifies the code execution run that made the call. The tool_id in that block is the ID of the code execution server_tool_use block, so you can match each programmatic call to the run that produced it.
Step 4: Return the result and let the code resume
Send the full conversation history plus your tool result. Three details matter on this request, and Anthropic’s documentation is explicit about all three: the user message that carries your result can contain only tool_result blocks — no text, even after the results; you must pass the container ID from the paused response, because the API rejects a continuation with pending programmatic calls and no container ID; and you must send the same tools array as the original request, with the code execution tool still present, so the paused code can resume. The code picks up where it paused, processes your result, and either pauses again with more programmatic calls or completes and hands Claude the final output.
When it saves tokens — and when it does not
Anthropic publishes its own evaluation numbers for the feature, and they are the honest starting point: the gains are real, but they depend entirely on workload shape. All figures below are Anthropic’s own measurements, not independent tests.
| Workload | What Anthropic measured |
|---|---|
| Agentic web search (BrowseComp and DeepSearchQA) | Performance up 11% on average, using 24% fewer input tokens |
| 75-tool project-management agent benchmark | Billed input tokens down roughly 38%, with no change in task accuracy |
| τ²-bench (airline, retail, telecom) | Scores unchanged, cost roughly 8% higher — sequential single-call turns do not benefit |
| Production API traffic, 10–49 tool definitions | Typical token savings of 20–40% |
Anthropic’s rule of thumb in the documentation is striking: calling 10 tools directly uses roughly 10 times the tokens of calling them programmatically and returning a summary. To put the 38% figure in concrete terms, take a support agent whose tool results run to about 1,000,000 billed input tokens a month: at the benchmark’s saving rate that workload would fall to roughly 620,000 tokens, a saving of about 380,000 tokens a month. That arithmetic is ours and illustrative — your saving depends on how much of your token bill is tool results rather than reasoning — but it shows why the feature matters most to agents with many tools and large results.
The same documentation is equally clear about the other side. Programmatic calling trades a small fixed overhead — container startup and script generation — for large savings on tool-result tokens and model round trips. On strictly sequential workflows, where each call depends on Claude reasoning over the previous result, the script cannot skip the model round trip, and the overhead can exceed the savings. Anthropic’s advice is to measure billed input tokens with and without allowed_callers on a representative sample of your traffic before enabling it broadly.
The limits to know before you ship
Programmatic tool calling is not a switch you flip on every tool. The documentation lists hard limits that will break a request if you ignore them:
- Not every model supports it. Supported models include Claude Fable 5.2, 5.1 and 5, Mythos 5.2, 5.1, 5 and Mythos Preview, Opus 5.5 down to Opus 4.5, Sonnet 5.5, 5 and 4.6, and Haiku 5.5. Claude Haiku 4.5 accepts the tool version but does not support programmatic calling.
- Strict structured outputs are out. Tools with
strict: trueare not supported with programmatic calling, and you cannot force programmatic calling of a specific tool throughtool_choice— naming a tool whoseallowed_callersomits"direct"intool_choicereturns a 400 error. - Some tools can never be called this way. Tools provided by an MCP connector, and the computer use and browser use toolsets, accept only
"direct"inallowed_callers. That matters for MCP-heavy agents: our Canva MCP guide and Runway MCP guide both connect tools through MCP, so those tools stay direct-only unless you connect the MCP server yourself and pass its tools to Claude as your own. - Recursive schemas fail. A custom tool whose input schema contains a recursive
$refcannot be enabled for programmatic calling; the request fails with a 400invalid_request_errorcontaining “Circular $ref detected”. Keep such tools direct-only. - Pending calls time out. If your tool result does not arrive within about 4 minutes, the pending call raises a
TimeoutErrorinside Claude’s running code. Claude usually retries, but keep tool execution fast and break long operations into smaller chunks. - Containers expire. Container data, including execution artifacts and outputs, is retained for up to 30 days. After about 5 minutes of inactivity a container is checkpointed, and sending a request with its ID inside the 30-day window restores it — but do not treat the
expires_attimestamp as your deadline, because it falls after the call times out. The 30-day retention also means this is not the right fit for workloads that need data gone immediately. - Tool results are strings — validate them. Results come back as strings that the running code may interpret, so validate external tool results before use: a tool returning data from an external source can be a code injection vector if its output is run as code. Anthropic’s documentation calls this out explicitly, and it is the single most important safety rule in the whole feature.
Programmatic tool calling vs Claude Code’s Code Mode
If you use Claude Code, you may already have met this idea under a different name. Claude Code’s Code Mode, which our sister site covered in its Code Mode guide, lets Claude execute code in a sandbox from the terminal. Programmatic tool calling is the same underlying pattern — tools as code, executed in a sandbox — exposed at the API level instead.
The distinction is who does the work. Code Mode is a Claude Code feature for people working in a terminal; programmatic tool calling is a Messages API feature for developers building agents, and it is also available through Managed Agents. If you are building an agent with the API, allowed_callers is the switch. If you are working in Claude Code, Code Mode is the switch. They are not two names for one launch — the API feature was in beta from November 2025, with SDK support added in June 2026, and Anthropic’s full documentation and the Claude Code v2.1.334 update both landed on 2 December 2026.
Our take: the three-question fit test
Whether to enable programmatic tool calling comes down to three questions about your workload. Answer them honestly before you change a line of code:
- Are you fanning out? Checking 50 endpoints, looking up 20 records, querying a database many times for one answer — fan-out is where the feature wins, because N round trips become one script.
- Are your tool results large? If results are small, there is nothing to filter and the container overhead eats the saving. If results are large — search results, database rows, document chunks — filtering them in code before they reach Claude is the whole point.
- Does each call depend on Claude reasoning over the last result? If yes, the model round trip is unavoidable and programmatic calling buys you nothing — the τ²-bench result, 8% more expensive with no score change, is the warning label for exactly this shape.
If the first two answers are yes and the third is no, enable it — and measure billed input tokens with and without allowed_callers on a representative sample first, as Anthropic itself recommends. For a multi-tool agent with ten or more tools, that is the default to try. For a one-or-two-call chatbot, skip it: the overhead exceeds the saving, and the simplest architecture is still the direct call. The feature’s real value is not that it makes every agent cheaper — it is that it makes the expensive kind of agent, the one that fans out across many tools with big results, dramatically cheaper. That is also why it pairs naturally with the MCP era: the more tools you connect — our Google Workspace MCP guide walks through eight of them at once — the more a single allowed_callers field is worth, provided the tools are yours to expose and not MCP-connector tools.
FAQ
What is programmatic tool calling in Claude?
It is an Anthropic Messages API feature that lets Claude call your tools as Python functions inside a code execution sandbox. You add allowed_callers: ["code_execution_20260120"] to a tool definition; Claude then writes code that calls the tool, filters or aggregates the results in the sandbox, and returns only the final output to the model, instead of one model round trip per tool call.
Which Claude models support programmatic tool calling?
Claude Fable 5.2, 5.1 and 5, Mythos 5.2, 5.1, 5 and Mythos Preview, Opus 5.5 through Opus 4.5, Sonnet 5.5, 5 and 4.6, and Haiku 5.5. Claude Haiku 4.5 accepts the code execution tool version but does not support programmatic calling — check the model’s capabilities.code_execution.supported value in the Models API before enabling it.
Does programmatic tool calling cost extra?
No. It uses the same pricing as code execution. The saving comes from token use, not a cheaper rate: Anthropic’s own evaluations show roughly 38% fewer billed input tokens on a 75-tool benchmark and typical savings of 20–40% on production traffic with 10–49 tool definitions, with no accuracy change on those benchmarks.
Can I use programmatic tool calling with MCP tools?
Not through Anthropic’s MCP connector: tools provided by an MCP connector cannot be called programmatically, and neither can the computer use or browser use toolsets. Third-party documentation describes a workaround — connect the MCP server yourself and pass its tools to Claude as your own tools with allowed_callers set — but the connector path itself stays direct-only.
How long is my data kept when I use programmatic tool calling?
Container data, including execution artifacts and outputs, is retained for up to 30 days under Anthropic’s code execution infrastructure. Containers are checkpointed after about 5 minutes of inactivity and can be restored by passing the container ID within the 30-day window. If your workload needs data gone immediately, this is not the right fit.
Sources and methodology
Sources: Anthropic — Programmatic tool calling (official documentation); Communeify — AI Daily, 2 December 2026 (Claude Code v2.1.334 release notes); OpenAIMaster.com — How to Use Claude Code Code Mode (2026 Guide); WorkingAgents — Claude’s Advanced Tool Use, 24 February 2026 (background on the feature’s earlier coverage). Method: desk research against Anthropic’s official documentation, read in full on 3 December 2026, cross-checked against the 2 December release notes. All benchmark figures are Anthropic’s own evaluations and are labelled as such; the monthly token arithmetic in the savings section is our own illustrative calculation and is labelled as ours. No hands-on API run was made for this guide — no API key was used — and that is stated plainly. The feature’s beta launch (November 2025) and SDK support date (June 2026) are taken from secondary documentation summaries, not from Anthropic’s changelog directly.
Arva Rangwala covers AI news, AI tools, guides and prompts for OpenAIMaster — what is new, what is worth using, and how to put AI to work.


