Programmatic Tool Calling
Instead of loading every tool definition into context and letting the model call them one at a time, you give it a code execution environment where it writes the script that calls those tools itself. Intermediate results stay in the container: the model only sees what you choose to return. It is Anthropic answer to context bloat in tool-heavy agents, shipped to GA in November 2025. The principle also works without that API feature, and that is often the form you meet it in inside Claude Code: instead of wiring an MCP server whose every response lands whole in context, you give the agent a script that calls the same service, filters the response and hands back only what matters. One script can chain several servers at once. Anthropic puts a number on the gap in one example from its engineering article on code execution with MCP: a workflow dropping from 150,000 to 2,000 tokens, 98.7 percent less. The cost moves, it does not vanish: a script to write, maintain and run in an environment you control.
Strengths
- Isolates tool responses: you decide what comes back into context instead of injecting everything by default
- Roughly 38% fewer billed tokens on a 75-tool benchmark, with no accuracy loss (Anthropic measurement)
- Lets you chain several calls (and several MCP servers) inside one script, in a single round trip
- Backed by Anthropic research: agents do better writing code than chaining raw tool calls
Limitations
- Requires a secure code execution environment (sandbox), not just a plain API call
- Oversized for 2 or 3 deterministic tools: a direct call stays simpler
- Debugging a script that orchestrates several tools takes more discipline than tracing an isolated call
Best for
- Production agents with 10 or more tools, or several MCP servers wired in: that is where token savings show up on the bill
- Workflows where a chatty tool returns large payloads the agent only needs a slice of
- Multi-step tasks where the agent must chain several tools without going back through the model at each step