Programmatic tool calling means the model writes a short program that calls your tools, instead of asking for them one call at a time. The program runs in a sandbox, can loop and branch, and returns one result to the model. OpenAI describes it as letting “a model write and run JavaScript that coordinates its tools.” Anthropic describes Claude writing “code that calls your tools programmatically within a code execution container, rather than requiring round trips through the model for each tool call.”

It builds on tool calling, where the model emits a request and your application runs the tool and sends the result back.

Why it exists

Anthropic’s engineering team names two problems with the standard loop:

  • Context pollution. Every intermediate result enters the context window. Analyzing a 10 MB log file puts the whole file in context, even though only a summary of error frequencies is needed.
  • Inference overhead. Each tool call needs a full model pass, and the model must read the data, compare values and decide what to do next in natural language. A five-tool workflow means five passes.

Anthropic’s example is checking budget compliance across 20 employees. The traditional approach needs 20 separate model round trips and pulls thousands of expense line items into context. With programmatic calling, one script runs all 20 lookups, filters the results and returns only the employees who went over, so the model reasons over a few lines instead of hundreds of kilobytes.

How it works

The loop changes in one place. Instead of the model requesting a tool and waiting for the result, it writes code. That code calls your tools as functions, your application runs each call and hands back the output, and the script continues. Anthropic says the script pauses when it needs results from your tools, and when you return them “they’re processed by the script rather than consumed by the model.”

Because orchestration is code, loops, conditionals, data transformations and error handling are explicit. Independent calls can run in parallel.

How OpenAI and Anthropic differ

OpenAIAnthropic
Enable itAdd the programmatic_tool_calling tool; set allowed_callers to ["programmatic"] on each toolAdd the code execution tool code_execution_20260120 or later; set allowed_callers to that tool version on each tool
Code languageJavaScriptPython, per Anthropic’s description of the generated code
RuntimeFresh, isolated V8 runtime per program; no Node.js, package installs, direct network access, filesystem or subprocessesCode execution container
Tools a program can callfunction, custom, mcp, apply_patch, local and hosted shell, code_interpreterCustom tools you mark with allowed_callers; tools from an MCP connector and the computer use and browser use toolsets cannot be called programmatically
Notable limitsAn already-running program cannot invoke tool searchNo strict: true tools, no forcing it with tool_choice, no disable_parallel_tool_use

OpenAI also notes that for Responses API requests the feature supports Zero Data Retention workflows without a persistent code-execution container, when ZDR is enabled for the organization or project. Check each provider’s page for which models support it before relying on it.

When to use it

OpenAI gives this task-shape guide for its own API; the same split is a reasonable starting point elsewhere:

TaskMode
A single lookup or actionDirect
Several results that code can filter, join, rank, deduplicate, aggregate or validateProgrammatic, when the program can return a smaller structured result
Dependent calls with predictable data flowProgrammatic, when limits and failure behavior are explicit
Adaptive search or semantic evaluationDirect, because each result should shape the next decision
Writes or approval-sensitive actionsDirect by default, to keep a clear authorization boundary

OpenAI’s guidance adds that generic instructions such as “use Programmatic Tool Calling efficiently” do not mark the boundary. It suggests assigning each route to a specific workflow stage and naming the eligible tools and the result shape.

The same idea predates the provider features. In September 2025 Cloudflare wrote that it converts MCP tools “into a TypeScript API, and then ask an LLM to write code that calls that API,” and that “LLMs are better at writing code to call MCP, than at calling MCP directly.” Anthropic’s engineering team reported that having an agent find tools by exploring a filesystem, then calling them from code, cut one example’s token use from 150,000 tokens to 2,000, a 98.7% saving. See the Model Context Protocol page for how MCP tools are exposed, and agent harness for the software that runs the loop around the model.