Programmatic tool calling

Build agents
HoneyHive Engineering

Programmatic tool calling lets a model write code that calls your tools, so intermediate results stay out of context. How it works, vendor docs and tradeoffs.

Programmatic tool calling is a pattern where the model writes a short program that calls your tools, rather than asking for one tool per turn. Anthropic’s documentation describes Claude writing code that calls your tools inside a code execution container, which cuts model round trips and lets Claude filter or process data before it reaches the context window. It builds on ordinary function calling and is one way to practice context engineering.

Why it exists

In an engineering post from November 2025, Bin Wu and the Claude Developer Platform team named two problems with plain tool calling: intermediate results consume large token budgets, and every call needs a full model inference pass. Anthropic’s docs give an example: checking budget compliance for 20 employees takes 20 model round trips the traditional way, with thousands of expense line items pulled into context. With a script, one run does all 20 lookups, filters them and returns only the employees over their limit.

How it works on Claude

Anthropic lists the steps:

  1. Claude writes Python that calls the tool as a function, with any preprocessing and post-processing.
  2. The code runs in a sandboxed container through code execution.
  3. When the code calls a tool, execution pauses and the API returns a tool_use block.
  4. Your application supplies the result and the code continues. Intermediate results are not loaded into Claude’s context window.
  5. When the code finishes, Claude receives the final output.

You opt a tool in with an allowed_callers field on its definition, and the code execution tool must be present. Anthropic adds that allowed_callers is not a hard block on direct calls, so your client should still handle them. Each tool_use block carries a caller field that says whether the call was direct or came from code.

What the numbers say

All figures are Anthropic’s own and depend on the task.

  • The engineering post reports average token use on complex research tasks falling from 43,588 to 27,297, a 37% reduction. It says orchestrating 20 or more calls in one code block removes 19 or more inference passes.
  • The docs say that on BrowseComp and DeepSearchQA, adding programmatic tool calling to basic search tools improved performance by an average of 11 percent while using 24 percent fewer input tokens.

When it helps and when it does not

The engineering post says it fits large datasets where only aggregates matter, workflows with three or more dependent calls and parallel work across many items. It is less useful for a single simple call, or when the model needs to reason over every intermediate result, because the model never sees those results. Anthropic’s docs add that on τ²-bench, where each turn makes one or two sequential tool calls, it left scores unchanged and cost roughly 8 percent more.

Other vendors

OpenAI documents the same idea under the same name, with different details.

Anthropic OpenAI
Language the model writes Python JavaScript
Where code runs Sandboxed code execution container Fresh, isolated V8 runtime
Opt in allowed_callers naming a code execution version A programmatic_tool_calling tool in the request, and allowed_callers including programmatic
Reach outside Only through your tools, which pause the code and return to your app Only through tools enabled in the request

Anthropic’s docs list tools that cannot be called this way, including MCP connector tools and the computer use and browser use toolsets. OpenAI says MCP tools can be called from programs, and that its runtime has no Node.js, package installation, subprocesses or state between executions.

Tradeoffs

  • Sandboxing. Generated code is code you did not write. Both vendors run it in a hosted sandbox. See AI agent sandboxing. The sandbox does not cover your own tools, so OpenAI advises checking arguments and permissions for each call and requiring application-level approval for high-impact actions regardless of the caller.
  • Fewer visible steps. Several tool calls now happen inside one model turn, so turn-level records show less. OpenAI recommends measuring token use, latency, cost, model turns, tool calls, retries and whether the intended route ran, and its program items carry a call ID for inspection. See LLM tracing and agent tracing for what to capture.
  • Timeouts and retention. Anthropic’s docs say a pending tool call times out after about 4 minutes and raises a TimeoutError inside the code. The feature is not eligible for zero data retention, and data is retained up to 30 days.
  • Feature gaps. Anthropic states that strict: true tools and disable_parallel_tool_use are not supported, and that tool_choice cannot force a programmatic call.

Anthropic’s docs list the supported Claude models, going back to Claude Opus 4.5 and Sonnet 4.5.

FAQ

What is programmatic tool calling?

It is a pattern where the model writes code that calls tools, instead of making one tool call per turn. Anthropic's docs describe Claude writing code that calls your tools inside a code execution container, so it can filter data before it reaches the context window.

Does programmatic tool calling keep tool results out of the context window?

Intermediate ones, yes. Anthropic says intermediate results are not loaded into Claude's context window, and the model receives the final output of the code.

Which providers offer it?

Anthropic offers it with Claude through its code execution tool, using Python. OpenAI documents a version in which the model writes JavaScript that runs in an isolated V8 runtime.

Is programmatic tool calling safe by default?

The code runs in a sandbox, but your tools still run in your application. OpenAI advises checking arguments and permissions for each call, even when it comes from a hosted program.

Share