← All posts

Guide

What an AI coding agent actually costs — and how to spend less

What an AI coding agent actually costs — and how to spend less

Nobody budgets for a coding agent the way they budget for a server. You pick a plan or paste an API key, and then one day the invoice arrives, or the lockout does, and you go looking for the knob. There are knobs. Most of them are not the ones people reach for first.

This is the arithmetic: what the two billing models actually cost, where the tokens really go (almost never where you assume), which levers move the number, and how to measure your own spend rather than someone else's blog post. Plus the counter-argument, which is real: an agent that is cheap and wrong costs more than an expensive one that is right.

Every price below was read on 2026-08-02 from the vendor's own pricing page — Anthropic's platform pricing and plan pricing, OpenAI's API pricing, and OpenRouter's fee documentation. Model prices in this category change every few weeks, and one of the rows below has a scheduled change on September 1, 2026. A stale price table is worse than no price table — re-check anything you are about to make a decision on, and use our continuously updated pricing tracker rather than this snapshot if you land here months from now.

Two ways to pay, and the number that decides between them

Every serious coding agent bills one of two ways. A subscription gives you a flat monthly price and a usage ceiling you cannot buy your way past without extra credits. The API gives you no ceiling and no floor: you pay for exactly the tokens you move, forever, including the ones a runaway loop moves at 3am.

Claude planPriceWhat you get
Free$0Claude Code included, small limits
Pro$20 / month, or $17 / month billed annuallyClaude Code included
MaxFrom $100 / month (5x); $200 / month (20x)Larger 5-hour and weekly windows
Team$25 / seat / month, or $20 billed annually (Standard seat)Per-seat allowance shared with chat
API (Claude Opus 5)$5 / MTok in, $25 / MTok outNo ceiling, no included allowance

The crossover between them is a real, computable number, and it is one line of arithmetic:

break-even active days = monthly plan price ÷ list-price cost per active day

"Active day" matters more than "day" — nobody drives an agent 30 days a month. And "list-price cost per active day" is a number you can read off your own machine even if you are already on a subscription: /usage in Claude Code prices your session locally at standard list rates, which is not your bill but is exactly the shadow price this formula wants. More on that below.

Two anchors to calibrate against. The session modelled later in this post — 40 turns, warm cache, Claude Opus 5 — costs $2.86, so three of them is about $8.60 an active day. Anthropic's own documentation reports an enterprise average of about $13 per developer per active day and $150–250 per developer per month, with 90% of users staying under $30 per active day. Those two numbers bracket most real usage:

PlanMonthlyBreak-even at $8.60 / active dayBreak-even at $13 / active day
Pro$202.3 active days1.5 active days
Max 5x$10011.6 active days7.7 active days
Max 20x$20023.3 active days15.4 active days

Read the bottom-right cell twice. At Anthropic's own reported average, Max 20x breaks even at about 15 active days — three working weeks — and their reported $150–250 per developer per month straddles the $200 plan price almost exactly. That is not a coincidence; it is what a plan priced against observed usage looks like. If you code most weekdays, the subscription is cheaper. If you reach for an agent twice a week, the API is.

Two caveats, one in each direction, and neither is small.

Where the money actually goes

Here is the thing almost everyone gets backwards. You think you are paying for the agent's answers. You are paying for the conversation it re-reads in order to produce them.

The Messages API is stateless. Every single turn resends the entire conversation — your prompts, its replies, every file it has read, every diff, every tool result, plus the system prompt, CLAUDE.md and tool schemas. The reply is a thousand tokens. The thing carrying it is tens of thousands, and it grows all session.

Model a realistic session and the split is stark. These are assumptions, not measurements — plug your own numbers in, the shape is what matters:

Line itemNo prompt cacheWarm prompt cache
Prefix re-read, per turn60,000 × $5 / MTok = $0.30058,000 × $0.50 / MTok = $0.029
New input written, per turn(included above)2,000 × $6.25 / MTok = $0.0125
Output, per turn1,200 × $25 / MTok = $0.0301,200 × $25 / MTok = $0.030
Per turn$0.330$0.0715
40-turn session$13.20$2.86
Input share of the bill91%58%
No prompt cache $13.20 $12.00 of resent conversation Warm prompt cache $2.86 same $1.20 of output, 78% less input input / cache reads cache writes output (incl. thinking)
Same session, same output, same model. The only thing that changed is whether the prefix was cached.

Two conclusions fall straight out of that picture. First: optimising output is optimising the wrong end until your cache is working. Second, and less obvious — once the cache is working, the ratio flips. Output goes from 9% of the bill to 42%, at which point terser replies, lower effort levels and shorter thinking budgets start to matter. The order of operations is not negotiable: cache first, then trim output.

Prompt caching, and why long stable prefixes are the whole game

Prompt caching is priced as a multiplier on the model's base input rate, and the multipliers are the same for every Claude model:

Cache operationMultiplier on base inputValid for
5-minute cache write1.25x5 minutes
1-hour cache write2x1 hour
Cache hit (read)0.1xsame window as the write

The break-even is trivially short. A 5-minute write costs 1.25x and each read costs 0.1x, so 1.25 + 0.1 = 1.35x beats two uncached reads at 2x — one cache hit and you are ahead. The 1-hour write costs 2x, so you need two hits. In an agent session that fires a request every few seconds, you get hundreds.

In dollars, per million tokens, as read on 2026-08-02:

ModelInput5m write1h writeCache readOutput
Claude Fable 5$10$12.50$20$1$50
Claude Opus 5$5$6.25$10$0.50$25
Claude Sonnet 5 (intro, through Aug 31 2026)$2$2.50$4$0.20$10
Claude Sonnet 5 (from Sep 1 2026)$3$3.75$6$0.30$15
Claude Haiku 4.5$1$1.25$2$0.10$5

Caching is a prefix match, and that single fact explains every mistake people make with it. The prompt renders in a fixed order — tools, then system, then messages — and a single changed byte at position N invalidates everything from N onward. Which gives you the rules:

One nuance worth its own line, because it explains a cost pattern people find mysterious. Cache lifetime differs by how you are authenticated. In Claude Code the cache lives an hour on a subscription, drops to five minutes once you are drawing on usage credits, and is five minutes by default on an API key or a cloud provider. That is why the first message after lunch is expensive on an API key and free-feeling on Max: on the API key, your entire context was evicted and gets reprocessed at full price.

The cheap model is the correct model for most turns

Run the identical 40-turn session — same context, same caching, same output — across the ladder, and the spread is almost exactly 1 : 2 : 5 : 10:

ModelCost of the same 40-turn sessionRelative
Claude Haiku 4.5$0.571x
Claude Sonnet 5 (intro pricing)$1.142x
Claude Opus 5$2.865x
Claude Fable 5$5.7210x

Anthropic's own guidance is blunter than most vendors dare to be: Sonnet handles most coding tasks well and costs less than Opus; reserve Opus for complex architectural decisions and multi-step reasoning; use Haiku for simple subagent tasks. Read that as a routing policy, not a hedge. Renaming variables, writing test boilerplate, summarising a log, checking a lockfile — the frontier model is not better at these in any way you will notice, and it is five to ten times the price.

The other side of the table, for anyone running Codex or a mixed fleet — OpenAI's standard rates per 1M tokens, read the same day. Note that every rate has a second, higher long-context tier that kicks in on large requests, which is exactly the shape agent sessions grow into:

ModelInputCached inputCache writeOutput
gpt-5.6-sol$5.00$0.50$6.25$30.00
gpt-5.6-terra$2.00$0.20$2.50$12.00
gpt-5.6-luna$0.20$0.02$0.25$1.20
gpt-5.6-sol (long context)$10.00$1.00$12.50$45.00
gpt-5.6-terra (long context)$4.00$0.40$5.00$18.00
gpt-5.6-luna (long context)$0.40$0.04$0.50$1.80

That long-context tier is a genuine structural difference: Claude 4.6 and later include the full 1M-token window at standard pricing, with no long-context premium, while a long GPT-5.6 session silently crosses into a doubled input rate. Our breakdown of the Sol/Terra/Luna split covers where that cliff sits.

And one footnote that quietly invalidates naive price comparisons: Claude 4.7 and later models use a newer tokenizer that produces roughly 30% more tokens for the same text. The same file is about 30% more tokens on Opus 5 or Sonnet 5 than on Sonnet 4.6. Comparing sticker prices across that boundary understates the newer model's real cost by about a third. The only honest comparison is per-workload, measured — which is what count_tokens and the calculator below are for.

The catch, again: the cheap model has to arrive without throwing the cache away. Switching with /model mid-session does throw it away. Assigning a model per subagent does not, which is why per-subagent routing is the cache-safe way to mix a cheap workhorse with an expensive judge.

The overhead you added yourself

Two things sit at the very front of the prefix — the highest-leverage real estate in the request — and both are things you configured rather than things the model chose.

CLAUDE.md

Your CLAUDE.md is loaded into context at session start and re-read on every turn thereafter. Anthropic's own recommendation is to keep it under 200 lines. Say yours has grown to 1,500. At roughly 60 characters and ~15 tokens a line, that is about 22,500 tokens versus 3,000 — a 19,500-token difference sitting in the cached prefix:

19,500 tokens × $0.50 / MTok  = $0.0098 per turn
                × 40 turns    = $0.39 per session
                × 3 sessions × 20 days = $23 / month  (Claude Opus 5)

Twenty-three dollars a month is not the reason to fix it, and anyone telling you a fat CLAUDE.md is bankrupting you is selling something. The real cost is displacement. Those tokens push you toward auto-compaction sooner, and compaction is itself an expensive request that re-reads everything it summarises. Move procedures into skills, which load only when invoked, and keep the file to facts.

MCP servers

Here the common advice is now out of date, and it is worth being precise. In Claude Code, MCP tool definitions are deferred by default — only tool names enter context until Claude actually uses a specific tool. The "every MCP schema rides along in every request" warning you have read a dozen times does not describe current Claude Code behaviour. Run /context to see what is genuinely occupying space rather than guessing.

It does still describe a raw Messages API integration, or any client without deferral. There, every schema renders at position zero of the prefix — present in every request, and, worse, a change to the tool set invalidates tools, system and messages together. The cheapest MCP server is the one you did not install: a CLI the agent can already run (gh, aws, gcloud) adds no per-tool listing at all.

Merely having tools also costs a fixed toll, which is small but worth knowing:

WhatAdded input tokens
Tool-use system prompt, Claude Opus 5286 tokens (auto / none), 406 tokens (any / a named tool)
Bash tool definition (Opus 4.7 and later)325 tokens
Text editor tool definition700 tokens
Computer use beta466–499 tokens of system prompt, plus 735 per tool definition

The line items nobody budgets for

Measuring your own spend — and what each number actually means

Every surface reports something slightly different, and the differences are the sort that make people think they have been overbilled.

SurfaceWhat it reportsWhat it does not
/cost in Claude Code An alias for /usage. Token counts per model, plus a dollar figure computed locally from those counts at standard list rates. Resets when /clear starts a new session. Your actual bill. It ignores promotional pricing and contracted discounts, and on Pro or Max the session dollar figure is not billing-relevant at all — usage is included in the plan.
/usage plan bars On a paid plan: where you stand against the 5-hour and weekly windows, attribution across skills, subagents, plugins and individual MCP servers, and behaviour flags (long context, cache misses) at 10% or more of recent usage. d / w toggles 24 hours vs 7 days. Usage from other machines or from claude.ai — the figures are computed from local session history on that device only.
/context What is occupying the context window right now, as a grid, with the heaviest offenders named. Dollars. It is a space meter, not a money meter — but space is where the money went.
Claude Console usage page The authoritative billing record for API organisations, plus per-user spend on the Claude Code dashboard and via the Analytics API. Subscription usage — that lives in the claude.ai admin console instead.
Team / Enterprise spend report Estimated spend per user and per model, CSV export, updated daily. Usage inside the seat allowance, which is not metered in dollars at all. The report covers usage-credit spend.
OpenTelemetry export Per-user token and cost metrics streamed into your own stack in near real time, on every setup including cloud providers. Nothing much — this is the only option that works everywhere. It just needs a collector.
OpenRouter activity page Complete request history filterable by model, provider and key; every response also carries a usage object with cost, prompt_tokens_details.cached_tokens and cache_write_tokens, counted with the model's native tokenizer. The fees around the edges. Credit top-ups cost 5.5% (minimum $0.80) by card and 5% by crypto, and BYOK requests cost 5% of list after the first 1M per month. Your activity total is genuinely below what left your card.

The practical loop: run a normal week, read the list-price figure off /usage at the end of each session, divide by active days, and put that number into the break-even formula. Then re-run it in a month, because the prices in this post will have moved. If you would rather not do the arithmetic by hand, our cost calculator does the subscription-vs-API comparison across Claude Code, Cursor, Copilot and Codex with the plan prices filled in.

The counter-argument, stated honestly

Everything above optimises cost per token. That is not the metric. The metric is cost per accepted change, and on that measure a cheap model that needs three attempts is not a third of the price — because each attempt resends the whole context, so you pay for the transcript three times, not just the reply.

Which is still, usually, fine. The arithmetic is symmetric and worth stating precisely: a cheap model wins as long as

attempts on the cheap model ÷ attempts on the expensive one  <  the price ratio

Haiku 4.5 is 5x cheaper than Claude Opus 5 on the session shape modelled here. That means Haiku can take five passes at a task for every one Opus takes and still come out even. That is an enormous amount of rope, and it is why "use the cheap model by default" survives contact with reality on the overwhelming majority of turns.

Where it breaks is not where people expect. The failure mode that costs real money is not a cheap model that visibly fails — you notice, you re-run, you have lost forty cents. It is a cheap model that produces something plausible: a refactor that compiles, passes the tests you happen to have, and quietly breaks the case you did not test. The cost of that is review time, debugging time and possibly an incident, none of which appear on any token invoice. The rule that falls out is about detectability, not difficulty: spend on the tasks where being wrong is hard to notice, and economise on the ones where the compiler, the test suite or your own eyes will catch it in seconds.

Keep the scale in view too. At Anthropic's reported $13 per developer per active day, tokens are a low-single-digit percentage of a loaded developer day. Optimising a $13 line item at the cost of twenty minutes of anyone's attention is a bad trade, made daily, by people who think they are being frugal. Fix the cache, route the boring turns to the cheap model, keep sessions scoped, and then stop thinking about it.

The short version

Where Backgrind fits

Backgrind runs your own CLI — your login, your plan, your history — so it does not change what a token costs. Two things it does change are worth naming honestly.

Eco mode injects a terse-output prompt and meters what it saves, with an accrued counter in Settings. In our measurements it cuts output tokens by around 45%. Apply this post's own arithmetic to that claim: output is about 42% of a well-cached session, so Eco is worth roughly 18% of the bill — real, and worth having — and about 4% on a session with a cold cache. If your cache is broken, fix that first; Eco mode is the second-order lever, and we would rather say so than let you believe the headline number applies to your whole invoice.

The other one is less quantifiable and probably larger. The most expensive session is the one still running while you are somewhere else — scheduled tasks firing on their interval, teammates burning context, an agent stuck waiting on a permission prompt nobody is looking at. Backgrind's whole premise is that you should not have to sit in front of the terminal to know that: it floats the session over whatever you are actually doing and pings you when it needs a decision or is done. An agent you can leave alone safely is also an agent that stops when it should.

Frequently asked questions

Is a Claude subscription cheaper than paying per token?

It is a computable crossover: break-even active days = monthly plan price ÷ your list-price cost per active day. On a well-cached Opus 5 workload of about three 40-turn sessions a day (~$8.60/day at list), Pro at $20 breaks even in 2.3 active days, Max 5x at $100 in 11.6, Max 20x at $200 in 23.3. At Anthropic's reported ~$13/developer/active-day average, those become 1.5, 7.7 and 15.4.

Why is my bill almost entirely input tokens?

Every turn resends the whole conversation — transcript, file contents, tool results, system prompt, CLAUDE.md, tool schemas. On the uncached 40-turn Opus 5 session modelled here, input is 91% of the bill. Caching flips it to 58/42.

How much does prompt caching save?

Reads cost 0.1x base input; a 5-minute write costs 1.25x and a 1-hour write 2x — so the short cache pays off after one hit and the long one after two. On the modelled session: $13.20 down to $2.86, a 78% cut.

Does a bloated CLAUDE.md cost real money?

About $0.39 per 40-turn session on Opus 5 for a 1,500-line file versus a 200-line one — roughly $23 a month at three sessions a day. The larger cost is context displacement and earlier compaction, not the cache-read line.

Do MCP schemas ride along in every request?

Not in Claude Code by default — tool definitions are deferred, so only names enter context until a tool is used. On a raw Messages API integration they do, at position zero of the prefix, where a change invalidates the whole cache.

What does /cost actually report?

It is an alias for /usage. The dollar figure is computed locally from token counts at list rates, so it ignores discounts and is not billing-relevant on Pro or Max. It is the list-price shadow price of the session — exactly what the crossover formula needs. Authoritative billing lives on the Console usage page.

Sources

All prices read 2026-08-02. Model, cache, batch, tool, fast-mode and Managed Agents pricing: Anthropic — Pricing. Plan prices: claude.com/pricing and What is the Max plan?. Per-developer cost averages, /usage semantics, cache lifetimes, CLAUDE.md guidance, MCP deferral and agent-team overhead: Claude Code — Manage costs effectively. /cost as an alias of /usage: Claude Code slash-command reference. Caching multipliers and prefix-invalidation behaviour: Anthropic — Prompt caching. GPT-5.6 standard and long-context rates: OpenAI — API pricing. Credit, BYOK and activity-page behaviour: OpenRouter — FAQ and Usage accounting.