Why Agentic Coding Burns Hundreds of Millions of Tokens a Day
This article explains why a single agentic coding task can consume millions or even hundreds of millions of tokens while producing a surprisingly small amount of code. It shows that most of the cost comes from resending context on every step, that total input grows roughly quadratically with the number of steps, and that one tool call usually means two model requests. It also clears up the common misconception that a 1M context window means 1M tokens in total, explains what teams actually get in return for this spend, and outlines four engineering approaches to cut cost: context compression, externalized memory, subtask isolation, and observability with budget governance.
1. The Question: Where Do the Tokens Go?
As agentic coding becomes a mainstream way of working, a question comes up constantly: why does a single task consume millions or even hundreds of millions of tokens when the resulting code volume looks nowhere near proportional? The answer is not about how much code was generated, but about how much history the model was forced to reread in order to generate it.
The core conclusion fits in one sentence: the bulk of token spend is consumed by the context itself. Every decision the model makes depends on everything that happened before it, and the only way to carry that dependency forward is to send the history again.
2. The Context Accumulation Model: Why Cost Grows Quadratically
Assume a task takes N steps, and each step consists of three pieces of information: model output, tool call, and tool result. Because an autoregressive model’s inference is stateless, the input at step k must contain everything from the previous k-1 steps. Total input is therefore approximately:
Total ≈ Σ(k=1..N) [S + k * c] ≈ S*N + c*N*(N+1)/2
Here S is the fixed overhead of the system prompt and tool definitions, and c is the new content added per step. As the step count grows, total cost grows as O(N²), not O(N).
Put intuitively: by step 200, the content from step 1 has already been resent 199 times. That is why “one command running 200 steps” is entirely feasible from an engineering standpoint and quite expensive on the bill.
3. The Real Bill for a Single Tool Call
Take a typical tool-driven request. Its context evolves as follows (illustrative):
Call 1 input: system prompt + tool definitions + user's first messageCall 1 output: output + reasoning + tool callCall 2 input: all of the above + tool result from call 1Call 2 output: output + reasoning + tool callCall 3 input: all of the above + tool result from call 2...
The key thing to understand: one tool call usually corresponds to two model requests (one to decide what to call, one to continue based on the result), so doubling the steps roughly doubles the bill. If the average context is 500K, a single tool call is already about 1M tokens; dozens of tool calls in one prompt is normal, so accumulating tens of millions of tokens is not surprising. Estimate 2M as the baseline for a single task and a hundred-plus tasks per day, and a daily consumption in the hundreds of millions is an arithmetic result, not an anomaly.
4. Clearing Up a Common Misconception: a 1M Context Is Not 1M Total
Many people read “1M context window” as “1M tokens consumed from start to finish.” That is wrong.
- The context window describes the input limit a single API call can carry;
- Actual cumulative consumption is the sum of the input across every call;
- If context grows linearly from 0 to 1M, the average per call is about 500K, and cumulative consumption is number of calls × average context.
Once this is clear, “window size” and “cost scale” can be discussed as two separate dimensions.
5. What the Tokens Buy: Memory Is Capability
This spend is not pure waste. It buys consistency across steps: remembering the goal and its constraints, the changes already made, the approaches that already failed, and the structure of the codebase, which avoids duplicated work and self-contradiction. Without memory, a model can only handle single-turn Q&A; it cannot complete long-chain tasks like refactoring, migration, or bulk fixes.
So the right question is not “how do we eliminate context,” but “how do we maintain equivalent memory with fewer tokens.”
6. Four Engineering Paths to Lower Cost
- Context compression and summarization: periodically fold history into a structured summary (goal, files already changed, open questions), keeping decisions rather than the original text.
- Externalized memory: put long-lived information into files, indexes, or log-like services, and retrieve and inject only the relevant fragments on demand instead of carrying everything.
- Subtask isolation and parallel orchestration: split a large task into small contexts that do not pollute each other, let each converge independently, then merge the results, turning one O(N²) into several O(n²).
- Observability and budget governance: monitor and alert on per-step input volume, tool call counts, and repeated reads; set budget thresholds and circuit-breaking policies so cost is attributable and optimizable.
7. Conclusion
The output of hundreds of millions of tokens is the inevitable price of trading context for continuity. Mature practice is not about cramming more into the window, but about using compression, externalization, splitting, and measurement so that every token is spent on the step that actually moves the task forward.
