# Code Mode

> Instead of invoking tools one call at a time, the agent writes code that calls MCP servers exposed as code APIs, so only the definitions and results it actually needs enter context.

- Category: Tools & Protocols
- Stage: Rising
- Also called: Code execution with MCP, Programmatic tool calling
- Canonical: https://www.joelcsaji.com/ai-dictionary/code-mode

## Plain English

The agent writes a small script against your tools instead of trading messages with each one, keeping the middle of the workflow out of the model's view.

## Example

With twenty MCP servers connected, the agent reads a typed github.createIssue stub, writes a loop that calls it fifty times, filters results in the sandbox, and only a one-line summary reaches the model.

## Why it matters

Anthropic measured a 150,000-token workflow shrinking to 2,000 (98.7%) - the current best answer to tool definitions eating the context window.

## Related

- [Model Context Protocol](https://www.joelcsaji.com/ai-dictionary/model-context-protocol)
- [Context Window](https://www.joelcsaji.com/ai-dictionary/context-window)
- [Tool Filtering](https://www.joelcsaji.com/ai-dictionary/tool-filtering)

## Sources

- [Anthropic: Code Execution with MCP](https://www.anthropic.com/engineering/code-execution-with-mcp)
- [Anthropic: Advanced Tool Use](https://www.anthropic.com/engineering/advanced-tool-use)
