In short.
Programmatic tool calling is an Anthropic guide for Claude agent developers handling many tool calls, but adoption adds container coordination and data retention of up to 30 days. Claude writes Python that calls application tools and filters their results before returning selected output to the model. The strongest fit is many independent lookups or large responses that can be reduced in code; small sequential workflows may cost more. Published performance figures are Anthropic's claims, exact pricing is absent, and the examples were not executed.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete selected page at [https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling.md], including its examples, availability table, compatibility restrictions, pricing references and data-retention notices. All linked pages are excluded. No code or API requests were executed, and benchmark claims were not independently reproduced. Numeric pricing, redistribution rights and changes after the capture remain unknown.
The overview
Identity
This is Anthropic's implementation guide for programmatic tool calling in Claude's Messages API, available at [https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling.md]. It teaches an API feature through request examples, response formats, lifecycle rules, troubleshooting and architectural alternatives.
The feature lets Claude generate Python that coordinates custom tools inside an Anthropic-managed code execution container. Your application still supplies the requested tool results; the container handles orchestration and processing.
Assessment
The guide is useful when an agent repeatedly retrieves data that can be filtered, compared or aggregated using code. It clearly distinguishes fewer model turns from fewer underlying tool calls: your application may still handle many requests, while Claude sees only the script's final output.
Its practical tradeoff is additional container and continuation handling in exchange for possible token and latency savings. A few small responses, workflows requiring fresh model reasoning after every result, and calls needing immediate user feedback are weaker fits. Runtime reliability and application-specific savings are not assessed.
Users
The main audience is developers building Claude agents for research, retrieval, database analysis or repeated operational lookups. Beginners can use the worked request and response sequence to understand the interaction, but implementation requires familiarity with API messages, JSON tool schemas and application-side tool handlers.
Experienced developers get details on asynchronous Python functions, caller identifiers, container reuse, schema restrictions and error handling. Examples cover cURL, a CLI and several programming languages; the orchestration code Claude generates is Python.
Capabilities
Claude can compose tool calls using loops, conditions, early termination and parallel operations through asyncio.gather. It can parse JSON responses, aggregate records and print only the information needed for its final answer.
Tools exposed to the code are asynchronous Python functions. Each accepts one dictionary of arguments and returns the text of the supplied tool result as a string. Intermediate results stay outside the model's context; the final code output enters it. Tool definitions can allow direct calls, programmatic calls or both.
Using it
Requirements
The page requires code_execution_20260120 or a later code execution tool version and a supported Claude model. It lists Messages API availability on the Claude API, Claude Platform on AWS and Microsoft Foundry deployments hosted on Anthropic. Managed Agents is listed as unsupported.
The documentation directs developers to check capabilities.code_execution.supported through the Models API. It specifically says Claude Haiku 4.5 does not support programmatic tool calling even though it accepts the relevant code execution tool versions. An application must also implement its custom tools and return their results in the required format.
Mechanism
Claude writes and runs Python in a sandboxed container. When that code calls a custom tool, execution pauses and the API returns a tool_use block. Its caller identifies code execution, and caller.tool_id links it to the originating execution block. After your application returns the result, the script resumes without a fresh model turn for that intermediate result.
A continuation must include the conversation history, container ID and the same tools array. Its user message must contain only tool_result blocks, with a result for every pending programmatic call. Tool-result content must be text.
Containers expire 30 days after creation, but a pending tool call times out after about four minutes. The paused response's expires_at value is not the pending call's deadline.
Setup
Include the code_execution tool in the Messages API request, define each custom tool with its input_schema, and add code_execution_20260120 to its allowed_callers array. Describe the output format and field types clearly so Claude can parse the returned text, typically as JSON.
Omitting allowed_callers defaults to direct calling. The page recommends choosing either direct or programmatic calling for each tool to give clearer guidance. The caller values code_execution_20260120 and code_execution_20260521 are interchangeable, while response caller fields always use code_execution_20260120.
Implement the continuation loop so it preserves container state, dispatches requested tools and returns correctly matched results until code execution completes.
Example
The page illustrates expense compliance across 20 employees. Instead of asking the model to inspect every expense response separately, one script performs the lookups, compares spending with limits and returns only employees who exceeded them. The benefit comes from keeping detailed line items out of the model's context and avoiding repeated model turns.
The API quick start uses a custom query_database tool to compare sales across three regions. This demonstrates tool definitions and orchestration, rather than supplying a working database integration. A database handler is still required. Neither example was executed, and no measured outcome is established here.
Assessment & evidence
Limitations
Programmatic calling does not support tools with strict: true, forcing a particular programmatic tool through tool_choice, or disable_parallel_tool_use: true. Recursive input schemas containing reference cycles are rejected for programmatic tools, although the same schemas can be used with direct calling.
MCP connector tools and the documented computer-use and browser-use toolsets cannot be called programmatically. Results answering programmatic calls must contain text; image, document and other content block types are rejected.
allowed_callers guides Claude and participates in request validation, but is not a hard API security boundary. Clients must be prepared for direct tool calls even when a tool is presented as programmatic. External results also require validation because interpreting returned strings as executable code can introduce code injection.
Reasoning
The proposed efficiency gain follows from moving repeated control flow and data reduction into Python. This helps when the script can determine the next step from data without asking the model to reason again. It offers less benefit when every result requires a new model decision.
Anthropic reports roughly 38 percent fewer billed input tokens with unchanged accuracy on a 75-tool project-management benchmark. On τ²-bench, with one or two sequential calls per turn, it reports unchanged scores and roughly 8 percent higher cost. It also reports typical token savings of 20 to 40 percent for production requests containing 10 to 49 tool definitions.
For BrowseComp and DeepSearchQA, the page reports an average 11 percent performance improvement and 24 percent fewer input tokens when programmatic calling was added to basic search. These are vendor-reported figures. Full evaluation configurations and raw results are absent, and the linked research was not assessed. The figures do not establish savings for a particular application.
Alternatives
Ordinary direct tool calling remains a practical option for a few small responses, tools with unsupported schemas, or workflows that need model reasoning or user feedback between calls. It avoids the programmatic execution overhead described by the page.
The guide also describes implementing the pattern on your own infrastructure. Running generated code locally gives control over the environment but exposes that environment to untrusted code. A self-managed sandbox adds isolation while requiring container infrastructure and a protocol for tools outside the sandbox. Anthropic's managed option handles execution and container communication, subject to its platform, compatibility and retention restrictions.
Evidence
The evidence is the complete documentation page captured from [https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling.md]. Its supplied source revision is sha256:6e4a534c488e79f08e5fe60fb5682654b117b9cda71ce3eb5143823099bb4be9.
This is first-party documentation supporting the described interface, restrictions and vendor claims. Linked pricing, model documentation, blog posts, papers and other pages are outside the evidence. The code and API examples were not executed, so runtime correctness, reliability, latency and application-specific costs are not assessed.
Access & freshness
Costs
The page says programmatic tool calling uses code execution pricing, but supplies no numeric rates. Exact charges and total operating cost are unknown. The referenced pricing page is [https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#usage-and-pricing]; its contents are outside the supplied evidence.
Intermediate programmatic tool results do not count toward input/output token usage; the final execution output and Claude's response do. Container startup and script generation add overhead, so lower tool-result token usage does not guarantee lower total cost. Each underlying tool call still counts individually toward rate limits. Charges for external tools are unspecified.
Rights
The supplied page does not establish a redistribution licence for its documentation or examples, ownership terms for generated artifacts, or the service's commercial terms. Those rights remain unknown from this evidence.
The data-handling notice states that container data, including execution artifacts and outputs, is retained for up to 30 days. The feature is listed as ineligible for zero data retention and HIPAA. These restrictions matter when deciding which data a workflow can send through the container.
Freshness
The supplied capture is dated 2026-11-15T00:06:08.482Z and labels the feature stable. No publication date, last-modified date or changelog is supplied.
Model availability, platform support, tool versions and retention notices describe that captured page. Subsequent changes are unknown. The page's model capability check is especially relevant because accepting a code execution tool version does not by itself establish programmatic calling support.
Actions
Before implementation, confirm support for the intended model and hosting platform, check the tool schemas against the documented restrictions, and determine whether retention of container data for up to 30 days fits the workload.
Compare direct and programmatic calling on representative requests, especially those with many independent lookups or large responses. Measure billed tokens, total cost, latency and answer accuracy rather than assuming the published savings apply.
Log tool calls, caller identifiers and container IDs. Verify continuation formatting, timeout handling and structured-result parsing, and validate external results before code processes them. These are recommended implementation steps; their outcomes remain unassessed.
