The biggest cost isn't the code the AI writes
It's the code every session has to read first. Agentic coding spends almost all of its tokens on input — repository reading, search, review, and the context re-sent on every turn — so halving the generated code barely moves the bill.

There is a comfortable assumption behind a lot of AI-coding advice: that if the model writes less code, you pay less. Fewer lines, fewer tokens, a smaller bill. It is the natural lesson to draw from a chat window, where the long answer is the thing you watch being typed out and the thing that feels expensive.
Coding agents do not work like a chat window. By the time one of them writes a line, it has read your repository, searched it, inspected dependencies, re-read its own earlier work, and carried all of that context forward into every following turn. Most of the cost is in that reading, and recent research now puts numbers on how lopsided it is.
Cutting how much code an AI writes barely lowers the bill. In agentic coding, generated output is only about 1% of the tokens — the other ~99% is input the agent reads, a measured input-to-output ratio near 154 to 1.
The mental model that’s wrong
Most of us carry a one-line cost model for AI coding:
cost ≈ generated code
Under it, the lever is obvious — generate less, pay less. The model comes straight from chat interfaces, where you send a short prompt and the model returns a long answer. There, output is the bulk of the work, and a shorter answer is cheaper.
An agent works the other way around. It reads far more than it writes, and it re-reads constantly. So the lever you reach for — trimming the output — is attached to the smallest part of the machine.
Input vs. output: where do AI coding tokens actually go?
The clearest measurement comes from a 2026 study, How Do AI Agents Spend Your Money?, by researchers at the University of Michigan, Stanford, MIT, and others. They ran eight frontier models through the OpenHands agent on SWE-bench Verified — real GitHub issues with real repositories — and counted where every token went.
The headline is the ratio of input tokens to output tokens. A single-shot reasoning task spends most of its tokens on output. A multi-turn chat is roughly balanced. Agentic coding is nothing like either:
For agentic coding, the study measured an input-to-output ratio of about 154 to 1 — input is roughly 99% of the token volume. The generated code lives in the sliver on the end. Cut it in half and you have changed half of one percent of the work.
The same study found agentic coding tasks consume on the order of 1,200 times more tokens than a multi-turn chat and 3,500 times more than a single-round reasoning task, averaging 4.17 million tokens per solved issue. Almost none of that is the patch it finally writes.
By the numbers — agentic coding, as measured across these studies:
| Figure | Value | Source |
|---|---|---|
| Input-to-output token ratio | ~154 : 1 | How Do AI Agents Spend Your Money? |
| Input share of total tokens | ~99% | How Do AI Agents Spend Your Money? |
| Tokens per solved issue (average) | 4.17 million | How Do AI Agents Spend Your Money? |
| Costliest stage — Code Review | 59.4% of tokens | Tokenomics |
| Input share of session cost | ~85% | Vantage |
A single task, broken into phases
Reading dominates, but it is worth seeing which reading. The same researchers split each Claude Sonnet trajectory into five phases and measured the token share of each:
-
Setup9.98%
Task planning, environment setup, initial reproduction.
-
Explore30.37%
Code search, file inspection, root-cause analysis — pure reading.
-
Fix33.53%
Code edits, debugging iterations, patch refinement — each round re-reads the context it just changed.
-
Validate16.59%
Testing, regression checks, verification.
-
Closeout9.53%
Final checks, cleanup, summary output.
Exploring and fixing — searching, reading, and re-reading to refine — are about two-thirds of the run. There is no “generate the code” phase that dominates, because writing the patch is the cheap moment between long stretches of reading.
A second 2026 paper, Tokenomics, from Concordia University, reached the same place by a different route. Mapping a multi-agent system across the development lifecycle, it found the Code Review stage alone consumed 59.4% of all tokens, with input running about two-to-one over output overall. Its conclusion, in their words: the primary cost “lies not in initial code generation but in automated refinement and verification.” Coding was the only output-heavy phase they measured.
Why are input tokens so expensive?
The mechanism is simple once you see it. A model call is stateless. To take its next action, the agent has to re-send everything it needs to remember: the system prompt, the files it has opened, the edits it has made, the test output it just read. On turn forty, it is paying to read turn one again — and most of turns two through thirty-nine with it.
Prompt caching softens the price of this, which is why cost and volume tell slightly different stories. The study found that cached reads dominate the cost of every phase even though each cached token is billed far below an output token — there is simply so much accumulated context being re-read that the cheap tokens still outweigh the expensive ones. Vantage’s independent analysis lands in the same neighborhood from the cost side: input made up roughly 85% of the cost of a typical agentic session. It comes out the same whether you count tokens or money.
The hidden cost is tomorrow’s reading
This reframes what unnecessary complexity actually costs. The expensive part of an over-engineered design is not the tokens to generate it once. It is the tokens to understand it on every future session.
Picture the same feature built two ways:
Option A Option B
billing.py billing_service.py
billing_factory.py
billing_interface.py
billing_registry.py
billing_context.py
billing_types.py
Option B might be only a few hundred more lines. Generated once, the difference is trivial. But every future run of Claude Code, Codex, Cursor, or Gemini CLI now has to discover those files, read them, work out how they relate, decide which ones matter for the change at hand, and hold all of it in context while it works. The code is written once. Every later session pays to read it again.
Do more tokens produce a better result?
It would be one thing if all that spending bought quality. It does not, reliably. The same study found a single task could vary by up to 30x in token use from one run to the next, and that accuracy tended to peak at an intermediate cost and then flatten or fall. The most expensive runs were marked by repeated re-viewing and re-editing of the same files — an agent thrashing, not thinking harder. Token efficiency, in other words, is not only a billing concern. It is a rough signal of how cleanly the agent is moving through the problem.
What actually lowers AI coding costs?
If the input side is where the cost lives, that is where the savings are too.
- Shrink the context, not the output. A smaller, simpler repository is cheaper for an agent to read, every single session. This is the one that moves the number.
- Fewer files. Each file is something a future run may have to open, read, and rule in or out. File count is future context.
- Spend abstractions deliberately. An abstraction that solves a real problem earns its keep. One that exists for a hypothetical future need is permanent reading overhead with no payoff yet.
- Make the structure legible. The faster an agent can find the right code, the fewer exploratory searches it runs — and Explore was nearly a third of the bill.
Notice what is not on that list: writing terser code, or asking the model for shorter answers. Those trim the one-percent sliver.
A better question
Instead of “how many tokens did this code cost to generate?”, the question that changes decisions is: how many tokens will every future session spend understanding it?
A little duplication can beat the abstraction that removes it. A single file can be cheaper than a hierarchy of factories and registries — not to write, but to keep re-reading.
Simplicity has always been easier for humans to maintain. Now that an agent reads your repository before it touches it, simplicity is also cheaper to compute against. The structure you leave behind is what every future session pays to read.
If you want to see where your own agentic coding spend goes, CostCompass pulls your metered usage from Anthropic, OpenAI, and the rest into one running total and a forecast — so the input-heavy months show up while you can still act on them, not when the invoice lands. Once you can see it, bringing the bill down is the next step.
Frequently asked questions
- Does generating less code reduce AI coding costs?
- Usually only a little. In agentic coding the generated output is a small fraction of total tokens — the input the agent reads (the repository, search results, prior diffs, and the full context re-sent each turn) dominates. A 2026 study across eight frontier models measured an input-to-output token ratio of roughly 154-to-1 for agentic coding. Halving the code you ask for leaves the other side of that ratio untouched.
- Why do AI coding agents use so many input tokens?
- Every turn re-sends the whole working context — the system prompt, every file the agent has read, every edit it has made, every error it has seen — back to the model as input. Across a long session that compounds. Vantage's analysis of real sessions put a single 50-turn run at roughly a million input tokens against about forty thousand output tokens.
- What actually lowers AI coding costs?
- Reducing the context an agent has to load and reason about. A smaller, simpler repository, fewer files, fewer speculative abstractions, and a clear structure the agent can navigate without exhaustive searching all shrink the input side — which is the side that drives the cost.
- Do more tokens mean a better result?
- No. The same study found a single task could vary up to 30x in token use between runs, and that accuracy often peaked at an intermediate cost rather than the highest. Beyond a point, extra spend reflected redundant re-reading and re-editing, not a better answer.
- How is input-heavy spend different from a normal API bill?
- On a chat or single-shot API call, output is the expensive part — the model reads a short prompt and writes a long answer. Agentic coding inverts that — the model reads enormous context and writes comparatively little. So the instinct to "write less code to spend less" is calibrated to the wrong workload.
- How many tokens does one agentic coding task use?
- On SWE-bench Verified, a solved issue averaged 4.17 million tokens across eight frontier models — roughly 1,200 times a multi-turn chat and 3,500 times a single-round reasoning task, almost all of it input the agent read rather than code it wrote.
- Why track AI coding costs with CostCompass?
- Because the spend is spread across every model and agent you run, and it moves with how much context each session reads — not how much code it writes. CostCompass pulls your metered usage from Anthropic, OpenAI, and the rest into one running month-to-date total and a forecast, so an input-heavy stretch shows up while you can still act on it, with nothing wired into your code.
About the author
Joubert Berger builds CostCompass, a spend-intelligence dashboard that pulls usage from AI and compute providers into one month-to-date total, a forecast, and a per-provider breakdown. This guide reflects how CostCompass reads each provider's own usage API — see the security model for how your keys are handled.
Track what your coding agents actually cost
Connect Anthropic, OpenAI, and the rest once, then pull a single month-to-date total and forecast across every model on demand — nothing wired into your code.