« All posts

Code Mode Cuts Agent Costs by 99.2%, Measured in Production

A production benchmark shows code-execution-based agent workflows cut token costs by 99.2% versus raw sequential MCP tool calls.

Following Anthropic's November piece on code execution with MCP — giving agents a sandbox and a generated API instead of raw sequential tool calls to cut a 150,000-token task down to 2,000 — and Cloudflare's earlier 'Code Mode' announcement, one engineering team benchmarked the same pattern against its own production workload using a self-written script called workflow-triage.

The script performs 26 underlying API calls (scanning 24 workflows and 60 schedules) entirely inside its own subprocess, returning only a single distilled summary object to the agent: 25,811 characters, ~6,450 tokens, 13.12 seconds — all directly measured. By contrast, the equivalent raw sequential tool calls were estimated at ~3.26 million characters and ~815,000 tokens, roughly 126x more data reaching the model's context, a 99.2% reduction.

The team is explicit about what's measured versus estimated: the raw-path character count comes from sampling actual SDK calls across a range of workflow sizes, computing a measured average characters-per-run, then applying it to the real total run count. The estimated $2.44 cost for the raw path is called a floor, not a ceiling, since a real multi-turn agent loop would re-send that raw data on every subsequent turn, driving actual cost higher.

For engineers, the takeaway is concrete: for bulk or fan-out tasks, routing raw data through a sandboxed script instead of the model's context materially cuts both token cost and latency — and this is now a measured production result, not just a theoretical claim.