We already tell every agent in the swarm to prefer a script over N tool calls. We’d never actually measured what that’s worth in tokens, seconds, or dollars — until we ran it live.
Anthropic published a piece in November on code execution with MCP: give an agent a sandbox and a generated API instead of raw tool calls, and a task that would cost 150,000 tokens costs 2,000 instead — a 98.7% reduction, because the raw data never has to pass through the model’s context. Cloudflare shipped the same idea back in September under the name “Code Mode,” and later put a number on it: 2,500+ API endpoints, 1.17M tokens down to about 1,000.
Our first reaction was “we already built this.” Every claude/codex/opencode session in the swarm ships a rubric today — system.agent.context_mode in src/prompts/session-templates.ts — that tells the agent: 10+ items or a bulk fan-out means reach for a script, not N individual tool calls. We didn’t add this for the post. It’s just what the swarm already does, and it’s the same machinery behind Script Workflows.
What we hadn’t done is measure it against Anthropic’s own yardstick, with our own production data. So we did — using a script two of our own agents wrote and ship globally: workflow-triage.
workflow-triage scans every automation the swarm runs — all workflows and all cron schedules — and flags which ones are dead, failing, or fine. Under the hood, that’s 26 separate calls: one workflow_list, one schedule_list, and one workflow_listRuns per workflow (24 of them). Normally, an agent doing this “by hand” would make 26 individual tool calls, and every one of those raw JSON payloads would sit in its context for the rest of the conversation.
Instead, the script makes all 26 calls itself, inside its own sandboxed subprocess, and only the final distilled result — one summary object — ever reaches the agent.
We didn’t estimate this. We ran the script and the underlying calls separately, against the real production catalog (24 workflows, 60 schedules), and measured both sides directly.
The wall-clock and cost of the raw path are the only estimated numbers here, and we want to be upfront about exactly how each was built, because the whole point of this post is “show your work,” not “trust our vibes”:
This is the entire script — not a snippet, the whole thing, id da3b5c7b-b9a6-4f9e-be9e-f682aca48ea0, global scope, callable by any agent in the swarm:
There’s no framework here. It’s a for loop with a concurrency pool of 6, a couple of Date.parse calls, and a sort. The only thing that makes it “code mode” rather than “26 tool calls” is where it runs: inside the script sandbox, not inside the agent’s context. Every ctx.swarm.workflow_listRuns call above returns its (large, sometimes limit-ignoring) payload straight back into the loop variable runs — never into the conversation. The agent that eventually calls this script sees only the return statement at the bottom: one object, 25,811 characters, done.
That’s precisely what runs is doing on line after line above, and precisely why the raw-path column in our table is ~126x bigger than the script column — none of it is a framework trick, it’s just that raw data stopped being handed to the model 24 times in a row.
The table above prices everything at Claude Sonnet 5’s rate, since that’s the model this measurement ran on. The reduction itself is a token-count story, not a pricing story — it holds at the same ~99.2% regardless of which model reads the result. Here’s what the two token counts (~6,450 measured / ~815,000 measured-floor) are worth at five current models’ own direct-provider input rates, pulled from the swarm’s live pricing table (src/be/modelsdev-cache.json, verified 2026-07-08):
Same measured/extrapolated caveats as the table above apply to every row here — the “script” column is a direct conversion of the 25,811-character measured result, the “raw path floor” column is the measured-then-extrapolated ~815,000 token estimate, and both are input-token pricing only, priced once rather than compounding across a real multi-turn session. Rates are each provider’s direct API pricing, not a router or resale price.
workflow-triage, one script call vs. 26 raw tool calls
Each bar is a share of the raw sequential-calls floor (~815,000 tokens, measured then extrapolated — see the methodology above). The ratio is model-invariant: at any model’s own $/token rate, the dollar reduction is the same ~99.2%.
This already ships by default in every claude/codex/opencode session’s system prompt — the decision in front of us isn’t “should we adopt code mode,” it’s “how do we make the rubric sharper now that we have real numbers to back it,” and workflow-triage — 26 calls, one result, 13.12 seconds, ~$0.02 — is the worked example we’ll use to do that.
/ references
Why tool inflation breaks agent accuracy and how we implemented core/deferred tool caching to fix it.
Your agent’s sleep(300) is silently bleeding money. Here’s the Anthropic prompt cache TTL mechanic that turns reasonable defaults into six-figure anti-patterns.
Binary success/failure metrics are killing your debugging velocity. The 10-second rule changes everything about how you interpret agent reliability.
A 7-day free trial on Cloud, or fork it on GitHub. Either way, your agents start compounding today.
Intelligence that compounds. Your agent company OS — open source, MCP-powered.
Built by desplega.shby builders, for builders.