# Let the agent run code over results

> When a task chains many tool calls, the agent can write a short program that calls the tools and returns only the final result, so intermediate results stay out of context. Anthropic and OpenAI call it programmatic tool calling; Pi runs it by default, OpenCode runs its MCP tools through it by default, and Claude Code and Codex have an experimental code mode.

Last checked: 30 Nov 2026, against the vendor's own pages.

Anthropic reported 37% fewer tokens, and no gain on flows of one or two calls. ([source](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling))

Family: Query instead of paging.

## Where it fits
- **Building my own agent**: fits. Programmatic tool calling on the Claude and OpenAI APIs; Pi codemode.
- **Using a coding agent**: partly. Experimental in Claude Code and Codex, on by default in OpenCode.
- **Using an enterprise assistant**: not available. Not offered in enterprise assistants.
- **Using a workflow tool**: not available. Use a code step instead.

## The setting in each harness
- [Claude API and Agent SDK](https://usefewertokens.com/harnesses/claude-api/): code_execution_20260120 with allowed_callers on your tools ([source](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling), read 30 Nov 2026)
- [OpenAI Responses and Agents SDK](https://usefewertokens.com/harnesses/openai/): The programmatic_tool_calling tool, with allowed_callers: ["programmatic"] on your tools ([source](https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling), read 30 Nov 2026)
- [Pi](https://usefewertokens.com/harnesses/pi/): on by default, MCP tools default to codemode exposure: the model calls them from one script instead of one call per tool ([source](https://github.com/earendil-works/pi/blob/4a080252f06caf63a525d7873c5d94d3c23887e0/packages/coding-agent/docs/mcp.md#L195), read 30 Nov 2026)
- [Claude Code](https://usefewertokens.com/harnesses/claude-code/): CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 (v2.1.323 or later, interactive terminal) ([source](https://code.claude.com/docs/en/code-mode), read 30 Nov 2026)
- [Cursor](https://usefewertokens.com/harnesses/cursor/): not offered. Cursor has no code mode for MCP tools ([source](https://github.com/StackOneHQ/mcp-clients-scorecard/blob/main/EVIDENCE.md#cursor), read 30 Nov 2026)
- [Codex](https://usefewertokens.com/harnesses/codex/): [features.code_mode] enabled = true in config.toml ([source](https://learn.chatgpt.com/docs/config-file/config-reference), read 30 Nov 2026)
- [OpenCode](https://usefewertokens.com/harnesses/opencode/): on by default, MCP servers run through Code Mode by default in OpenCode 2; "codemode": false on a server exposes its tools directly ([source](https://opencode.ai/docs/mcp-servers/), read 30 Nov 2026)
- [ChatGPT](https://usefewertokens.com/harnesses/chatgpt/): not offered. ChatGPT has no code mode for MCP tools ([source](https://github.com/StackOneHQ/mcp-clients-scorecard/blob/main/EVIDENCE.md#chatgpt), read 30 Nov 2026)
- [Claude](https://usefewertokens.com/harnesses/claude-ai/): not offered. The Claude app has no code mode for MCP tools ([source](https://github.com/StackOneHQ/mcp-clients-scorecard/blob/main/EVIDENCE.md#claude-app), read 30 Nov 2026)

## Read more
- [MCP code mode: keeping tool responses out of context](https://www.stackone.com/blog/mcp-code-mode-agent-context-architecture/)
- [Code Mode in Claude Code](https://code.claude.com/docs/en/code-mode)
- [OpenAI's Programmatic Tool Calling](https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling)
