What happened
AI agents just got dramatically cheaper to run, and the proof is not a marketing slide — it's a measured production log. In November, Anthropic published research on code execution with MCP (Model Context Protocol), showing that letting an agent write and run a script instead of making tool calls one by one can cut a 150,000-token task down to just 2,000 tokens — a 98.7% reduction. Cloudflare had already shipped a similar approach in September, calling it "Code Mode," and later reported turning 1.17 million tokens into roughly 1,000 across more than 2,500 API endpoints.
A smaller AI dev team decided to test the idea against their own real workload instead of taking the headline numbers on faith. They built a script called workflow-triage that scans every automated workflow and cron schedule a system runs, checks which ones are dead, failing, or healthy, and reports back a single summary. Under the hood, that job requires 26 separate API calls: one to list workflows, one to list schedules, and one per-workflow call to pull run history across 24 workflows.
Instead of letting an AI agent make all 26 calls directly — which means all 26 raw JSON responses land in the model's context — the team had the script make the calls itself inside a sandboxed subprocess. Only the final, distilled result ever reaches the agent. That's the entire trick behind "Code Mode": keep the model out of the data pipeline and only show it the answer.
Why it matters
The numbers here weren't estimated — they were run and measured side by side. The script's real output: 1 call made, a single 25,811-character JSON result, a 13.12-second runtime, and an estimated cost of about $0.02 on Claude Sonnet 5 pricing ($3 per million input tokens).
The raw, one-call-at-a-time equivalent was reconstructed by calling the same underlying methods directly and measuring their actual payload sizes: the workflow list alone returned 16,304 characters, the schedule list returned 72,105 characters, and sampled run-history calls averaged 3,447 characters per run across 312 sampled runs. Multiplied across the real total of 920 runs recorded that day, the raw path would have pushed roughly 3.26 million characters — about 815,000 tokens — into the agent's context, at an estimated cost of $2.44 or more.
That's a 126x reduction in characters reaching the model, a 99.2% cut in raw data exposure, and a swing from a multi-minute, multi-dollar task to a 13-second, two-cent one. For any business running AI agents at scale — customer support bots, internal ops dashboards, marketing automation — token costs are usually the single biggest line item after model choice itself. A 100x reduction on the highest-volume tasks (bulk lookups, health checks, reporting) changes the math on what's worth automating at all.
How to use it today
You don't need Anthropic's research team or Cloudflare's infrastructure to apply this. The rule of thumb that made the difference here is simple: any time an agent needs to touch 10 or more items, or run a bulk operation across a list, it should write and execute a script rather than make that many individual tool calls. The script does the fetching, filtering, and summarizing in an isolated process; the agent only ever sees the final result.
In practice, this means structuring agent instructions (or system prompts) to explicitly favor "generate code that calls the API" over "call the API repeatedly." Most modern agent frameworks that support code execution sandboxes — including Claude's own tool-use setup — can be configured this way with a short rubric, not a rebuild. If you're experimenting with agent workflows for your own business and want to prototype quickly without standing up custom infrastructure, a set of [free AI tools at mykreatool.com](https://mykreatool.com) is a low-friction place to test automation ideas — from content generation to simple data workflows — before committing engineering time to a full agent pipeline.
The key operational habit: measure before and after. The team behind workflow-triage didn't just assume Code Mode worked — they ran both paths against live data and published the exact character counts, token estimates, and wall-clock times. Any team adopting this pattern should do the same sanity check on their own workloads, since savings will vary by how chatty the underlying API responses are.
Who benefits
The clearest winners are teams running high-frequency, high-volume AI agent tasks: internal tooling teams doing health checks across dozens of services, marketing teams running bulk content or campaign audits, e-commerce operations reconciling inventory or order data across many endpoints, and any SaaS product embedding agents that need to summarize large datasets. For solo founders and small teams, the appeal is more direct — a 100x cost drop makes it economically viable to run agent-based automation continuously (hourly or even every few minutes) instead of rationing runs to control API spend.
Developers building on MCP or similar tool-calling protocols also benefit structurally: the pattern doesn't require a new model or a new API, just a change in how agents are instructed to interact with existing tools.
Risks
Code Mode isn't free of trade-offs. Sandboxed script execution adds an extra layer — the agent has to write correct code, and that code needs a safe, isolated environment to run in, which is more infrastructure than a simple tool call. Debugging failures also gets harder, since a bug now lives in generated code rather than in a single API response the model can reason about directly. And because the raw data never reaches the model, teams lose the ability to have the agent "notice" anomalies in the underlying data unless the summary script is designed to surface them.
There's also a measurement caveat worth repeating: the raw-path numbers in this case were partly extrapolated from sampled data, not a full run of all 920 calls one by one. The direction of the result — dramatically fewer tokens and lower cost — is solid, but exact multipliers will vary by workload, API verbosity, and how many items are actually being processed.
Conclusion
The headline claim — AI agents running 100x cheaper — held up under a real, measured test: 26 tool calls collapsed into one script execution, cutting context usage by over 99% and total cost from an estimated $2.44 down to about $0.02. For businesses running agent-based automation at any scale, the lesson is concrete: stop letting agents make bulk tool calls one at a time, and start having them write scripts that do the fetching and only report the summary. The infrastructure to do this already exists in most modern agent frameworks — the only thing missing on most teams' end is the instruction to actually use it.



Comments 0