A production measurement of 'code mode' — the pattern of running multiple tool calls inside a sandboxed script rather than sequentially in an agent's context. Using a real workflow-triage script that makes 26 underlying API calls, the team measured a ~126x reduction in characters reaching the agent's context (25,811 vs ~3.26M), cutting cost from ~$2.44 to ~$0.02 per run on Claude Sonnet 5. The post details exactly what was measured vs. extrapolated, includes the full script source, and prices the token savings across five current LLM models. The core insight: intermediate tool results that stay inside the execution environment never inflate the model's context window.
Table of contents
What the script doesWhat we measured, liveBeing honest about what's measured vs. estimatedThe code that does itThe mechanism, in one sentenceWhat it's worth across modelsThe one-line takeawaySources and further readingShare this post