July 28, 2026

How Much AI Coding Agents Really Cost: I Measured 7.97 Billion Tokens in 35 Days

Photo of Marco Orta Marco Orta | 12 min read
Compartir
A code terminal wrapped in a loop of arrows feeding context back into the model, with coins falling toward a cost gauge
Table of Contents

    A coding agent burns roughly 44 times more tokens per response than a chatbot message. I measured it on my own machine: between June 23 and July 28, 2026 I accumulated 311 Claude Code sessions and 7,969,840,885 billable tokens. At official API prices, that month would have cost $6,146. Without prompt caching, $39,781. On a subscription, $200.

    Those three numbers are the whole article. Below I explain where they come from, why the gap is so brutal, and how to estimate your own case before committing to anything.

    If what you want is how much it costs to call a model API for a chatbot or an integration, I broke that down in the guide to OpenAI, Claude and Gemini API pricing. This article is about the other thing: the agents that write code for you, which are billed the same way but behave nothing alike.

    Why an agent is not billed like a chatbot

    With a chatbot the math is simple: you send a prompt, you get a response, you pay for both. A coding agent — Claude Code, Codex, Cursor in agent mode, Cline — does something very different: it works in a loop.

    You ask it to “fix this bug” and the agent reads files, runs commands, inspects the output, corrects itself, runs again, reads the tests. Each of those steps is a fresh call to the model, and every call drags along everything that came before: the system instructions, its tool definitions, your CLAUDE.md, the files it already read, and the output of every command it already ran.

    Put another way: context is not sent once, it is re-sent on every turn. A twenty-step task does not cost twenty prompts; it costs the sum of a context that keeps growing. That is why the numbers escalate so fast.

    My data shows this clearly. In the same month I had two very different AI workloads running:

    Agentic work (Claude Code)Non-agentic work (API via gateway)
    Model calls35,3011,742
    Tokens per call (average)225,7685,186
    Total tokens for the month7,969,840,8859,034,575

    44 times more tokens per call. 882 times more in total monthly volume. The second workload is a copywriting agent that produces short text: a brief goes in, a paragraph comes out. The first one reads entire repositories. Same technology, same per-token rate, and nothing alike when it comes to budgeting.

    The data: 35 days of real usage

    These are the raw numbers, pulled from local session logs (token counters only — not a single line of code or conversation):

    MetricValue
    PeriodJun 23 – Jul 28, 2026 (34 active days)
    Sessions311
    Model responses35,301
    Billable tokens7,969,840,885
    Equivalent API cost$6,146
    Cost per active day$180.78
    Cost per session (average)$19.76
    Cost per response (average)$0.17

    One important clarification before going further: I did not pay $6,146. That usage ran on a flat-rate subscription, where tokens are counted but never charged. The $6,146 is what the same work would have cost billed per token, calculated with public API prices as of July 2026. That distinction is exactly what the section further down is about.

    The breakdown almost nobody expects

    Chart showing the breakdown of 7,969,840,885 tokens consumed by an AI agent: 97.52% cache reads, 2.09% cache writes, 0.36% output and 0.03% fresh input

    Whenever I show this chart the reaction is the same: only 0.36% is output? Yes. Every line of code the model wrote in 35 days — every diff, every explanation, every script — fits in 28.7 million tokens. The other 99.6% is context coming in.

    And within that context, almost all of it is cache re-reads: 7,771 million tokens the model had already seen, presented to it again on the following turn. That is precisely the loop we were talking about, measured.

    This has a practical consequence that is worth knowing even if you never touch an agent: in agentic work, optimizing output is pointless. Telling the model to be more concise saves you a percentage of 0.36%. What moves the needle is context.

    And the breakdown by model

    ModelResponsesTokens% of tokensEquivalent cost% of cost
    Opus 4.820,6104,717,798,90659.2%$3,846.7562.6%
    Opus 58,3002,178,241,66927.3%$1,537.8425.0%
    Sonnet 53,595723,232,0259.1%$216.783.5%
    Fable 52,099323,187,3484.1%$535.408.7%
    Haiku 4.553323,399,3490.3%$4.470.1%
    Sonnet 4.61373,981,5880.05%$5.200.1%

    Look at the two rows that fall off the diagonal. Fable 5 consumed 4.1% of the tokens but took 8.7% of the cost, because it costs twice as much per token as Opus. And Sonnet 5 did 9.1% of the work for 3.5% of the spend. There it is, in one table: the case for picking a model per task. Same volume, very different bill.

    Caching: 97% of your tokens and 84% of your savings

    Prompt caching is what makes agents economically viable at all. The idea is simple: if the provider already processed that block of context a moment ago, it does not charge you input price for it — it charges you 10% of it.

    According to Anthropic official pricing page as of July 2026, for Opus 5:

    • Regular input: $5 per million tokens
    • Cache write: $6.25 per million (1.25×, or 2× if you ask it to last an hour)
    • Cache read: $0.50 per million
    • Output: $25 per million

    Since 97.52% of my volume was cache reads, the blended rate across all models came out at $0.77 per million tokens. Without caching it would have been $4.99. Translated into money:

    Comparison of the cost of the same month of work: $39,781 without prompt caching, $6,146 with caching and $200 on a Claude Max 20x subscription

    84.5% savings. A factor of 6.5×. And it is not something you have to switch on: serious agents already do it for you. But it is something you can break without realizing, and that is the actionable part.

    Caching invalidates when the beginning of the context changes. If your tool injects the current time into the system prompt, or reshuffles the list of open files, or you attach a new MCP server mid-session, the prefix stops matching and you pay for everything at input price again. In an 80-million-token session, breaking the cache once costs more than all of your output for the month.

    Subscription or API: where the crossover is

    Here is the decision that actually matters, and it comes down to a single calculation.

    Agent tools are paid for in two ways. Flat rate: Claude Code is included in every paid Claude plan (Pro at $20/month; Max from $100; Max 20× at $200), and OpenAI Codex in Plus ($20) and Pro ($200). Cursor and Windsurf run from $20 to $200 depending on the quota. Per token: you plug in your API key and pay exactly what you consume, with no throughput ceiling.

    A flat rate does not give you infinite tokens: it gives you a quota per time window. On Claude those are rolling five-hour windows plus weekly caps, and that quota is shared between the chat and the terminal. When you run out you do not get a charge — you wait for the reset. That is the whole trade: you swap unpredictable money for predictable waiting.

    At my blended rate of $0.77 per million, the break-even for a $200/month plan sits at roughly 260 million tokens per month. Above that, the flat rate wins. I consumed 7.97 billion: thirty times past the crossover.

    Translated into a rule you can apply today:

    • Under ~30 million tokens a month (occasional use, a couple of sessions a week): per-token API beats any subscription, and you pay nothing on the days you do not code.
    • Between 30 and 260 million: an entry plan ($20) is the most economical, unless the caps get in your way.
    • Above 260 million (daily heavy use, long sessions, subagents): the high flat rate is a bargain, no argument.
    • If you need real parallelism — five agents at once, continuous integration, unattended jobs — the API is the only path, because a subscription quota is shared across all of them.

    One warning about the market, because it changed recently: GitHub Copilot moved to usage-based billing on June 1, 2026. Every plan now includes a monthly allotment of AI Credits (1 credit = $0.01) computed over input, output and cached tokens; completions remain unlimited, but chat and agent features draw down that balance. If you picked Copilot precisely because it had a fixed price, it is worth redoing the math.

    Not all sessions cost the same (not even close)

    If you take one chart away from this article, make it this one:

    Distribution of 311 AI agent sessions by tokens consumed: the median uses 6.5 million tokens and the heaviest session 206 million

    The median session consumed 6.5 million tokens: about $5 equivalent. The 90th-percentile session consumed 85.7 million: $66. And the worst of the 311 reached 206 million tokens, nearly $159 in a single session.

    Thirteen times the median at P90, thirty-one times at the max. Agent spend is not an average, it is a long tail. Budgeting by multiplying “average cost per session × sessions per month” will give you a number that looks nothing like reality, because a handful of sessions eats half the budget.

    The operational consequence is direct: do not optimize the average case, cut the tail. Killing a session that is spinning its wheels and starting fresh saves more than any prompt tweak.

    What actually blows up the bill

    After going through the expensive sessions one by one, these are the patterns that repeat:

    1. Never-ending sessions. This is the number one factor by a wide margin. Every turn of a long session drags everything accumulated so far. A three-hour session does not cost triple a one-hour one: it costs far more, because context grows with each step. Open one session per task and close it when you are done.
    2. Parallel subagents. Launching five agents to review five things multiplies spend by five, each with its own full context. Money extremely well spent when the work justifies it, and a hemorrhage when it does not.
    3. Too many MCP servers. Every connected tool adds its schema to the context of every call. Ten MCP servers you barely use are a fixed tax on every turn of every session. Disconnect the ones you do not touch.
    4. The expensive model for dumb tasks. Renaming variables, formatting, writing a commit message: a small model does that for a fraction of the price. In my data, Haiku handled 533 responses for $4.47 equivalent.
    5. Silent retries. When a command fails and the agent tries again, you pay for the failed attempt, the error output, and the new attempt. A test failing in a loop is a token leak.
    6. Reading huge files whole. A 20,000-line .json or a full log enters the context and stays there, charged on every remaining turn of the session.
    7. Breaking the cache by accident. As we saw: any change to the context prefix invalidates the whole cache and multiplies that turn by ten.

    How to estimate your case before paying

    You do not need to measure 35 days like I did. In twenty minutes you can get a decent number:

    1. Measure your base context. Gather everything that goes into every call: your CLAUDE.md (or .cursorrules, or whatever the equivalent is), your MCP server schemas, and any system instructions you can see. Paste it into a token counter. That number is your floor per turn.

    2. Multiply by the shape of the task. A simple task is 10-15 turns; a serious refactor goes past 60. Since context grows, a conservative rule is: tokens ≈ base_context × turns × 1.8.

    3. Apply the blended rate. If your tool caches (every serious one does), use $0.50 to $1 per million tokens for a frontier model. If it does not cache, use the full input price.

    4. Multiply by your real monthly sessions and add 40% for the long tail.

    5. Compare against the subscriptions. If the result clears $200, a flat rate is almost certainly your answer.

    For steps 1 and 3 I use my own tool, which counts tokens in the browser — your text never leaves your machine — and compares the cost across every model at once:

    Common mistakes when budgeting for agents

    • Estimating in words. Code tokenizes terribly: punctuation, indentation and unusual identifiers push the ratio up. A 300-line file can exceed 4,000 tokens. Measure it, do not eyeball it.
    • Counting only what you write. In my data, fresh input was 0.03% of the total. What you type is statistically irrelevant next to what the agent reads.
    • Assuming the per-token price is the real price. Between cache reads (10%), cache writes (125-200%) and output (500%), the effective cost of a token varies fiftyfold depending on which kind it is.
    • Extrapolating from a small test. The pretty “fix this function for me” demo burns 400,000 tokens. Real work is 30-million-token sessions.
    • Forgetting the days you do not code. A subscription is paid for all 30 days of the month; I had 34 active days out of 35, but if you work three days a week the math changes completely.
    • Ignoring the cost of retries. If your test suite is slow and fails often, the agent will pay to read those failures over and over.

    Conclusion

    Coding with AI agents is neither expensive nor cheap in the abstract: it is a function of the context you re-send, and that part is under your control.

    The three numbers I keep after measuring 35 days are these. 97.5% of what an agent consumes is re-read context, not written code. Caching turns $39,781 into $6,146, and a subscription turns that into $200. And the heaviest 10% of sessions decides your bill far more than any prompt tweak.

    Before you commit to a plan or plug in an API key, run the numbers with your own inputs: measure your base context with the AI token counter and cost calculator, multiply by your turns and your real sessions, and compare against the subscriptions. Twenty minutes there tells you whether your case sits above or below the crossover, which is the only question that needs answering.

    If you want to dig into how these agents work under the hood and what role the MCP protocol plays, I cover it in the guide to agentic AI in 2026. And if the bill you worry about is the other one — fixing what the agent breaks — I have a guide to secure vibe coding.

    Are you rolling AI agents into your team or your product and want the math to work out? I can help you with AI automation and integration for your business. Tell me what you are building.


    Methodology: the data comes from local Claude Code session logs on my machine (June 23 to July 28, 2026), from which only token counters aggregated by model and by session were extracted. Repeated messages were deduplicated by identifier. The equivalent cost was calculated with public Anthropic API prices as of July 2026, applying 0.1× to cache reads, 1.25× to five-minute cache writes and 2× to one-hour writes, plus the introductory Sonnet 5 price in effect during that period. API and plan prices change often: always verify on the provider official page before deciding.

    Compartir

    Search

    Tags