How to Cut Your Claude Code Cost (and Codex Cost, and Cursor Cost) Without Slowing Down

By Aakash Ahuja··24 min read

How to Cut Your Claude Code Cost (and Codex Cost, and Cursor Cost) Without Slowing Down

Every token you put into a Claude Code session gets billed again on every turn that follows. Across 74,493 turns of my own sessions, the median token was re-billed 27 times. In sessions past 200 turns, 386 times. That is the whole story of AI coding cost, and it is why a one-line follow-up at hour three can cost more than your first ten messages combined.

This guide shows you how to cut Claude Code cost (and the closely related Codex cost and Cursor cost) in nine concrete moves. Unlike most posts on this topic, the numbers here are measured rather than estimated: I analysed every session file Claude Code wrote to disk over a 35-day period and priced it against current API rates.

This post is for developers from junior to staff level who use AI pair-programmers daily and want to stop overpaying. We'll define what's actually being billed, show where the spend hides, and give you a step-by-step playbook to reduce it.

Quick answer: AI coding cost overruns come from three things: (1) the entire conversation is re-sent and re-billed on every turn, so context is a recurring charge and not a one-off, (2) a handful of runaway sessions account for most of the bill, and (3) the model tier is wrong for the task. Note that the old advice about "keeping the 5-minute prompt cache warm" is out of date: Claude Code now writes 1-hour caches, and the thing that costs you is cache invalidation, not cache expiry.

Table of Contents

  1. What 74,493 turns of real sessions actually cost
  2. What is "Claude Code cost" actually measuring?
  3. Why does one short prompt sometimes cost a fortune?
  4. How does Claude Code cost compare to Codex cost and Cursor cost?
  5. 9 tactics to cut Claude Code cost (in order of impact)
  6. How does prompt caching change the math?
  7. Which model should I default to for routine work?
  8. Common mistakes that quietly inflate AI coding costs
  9. FAQ
  10. Key takeaways

What 74,493 turns of real sessions actually cost

Claude Code writes a full transcript of every session to ~/.claude/projects/ as JSONL, and each assistant turn carries its exact token usage: fresh input, cache writes, cache reads, and output. That makes your own machine the best available dataset on what agentic coding actually costs.

I analysed 35 days of mine: 350 session files (92 main sessions plus 258 subagent runs) across a dozen repositories, on Claude Code versions 2.1.187 through 2.1.222. That is 74,493 assistant turns and 18.6 billion billed input tokens.

Four findings reframe everything below.

1. Output is a rounding error. Context is the bill.

Token categoryVolumeShare of all tokens
Cache reads (context re-sent each turn)18,090 M97.0%
Cache writes477 M2.6%
Fresh input6 M0.03%
Output (all the code it wrote)82 M0.44%
Everything the agent wrote over 35 days, every file, every diff, every explanation, was less than half a percent of the tokens I paid for. Optimising your prompts or asking for terser code is rearranging deck chairs. The only number that matters is how much context is alive when the model runs.

2. Context amplification: the multiplier nobody quotes.

A token added to context on turn 3 is billed on turn 4, and turn 5, and every turn after. Dividing each session's total billed input by its peak context size gives the number of times the average token was charged:

Session lengthMedian amplification
Under 20 turns10.8x
20 to 60 turns23.8x
60 to 200 turns56.6x
Over 200 turns386x
Median across all 335 sessions: 27.3x. Worst single session: 3,905x.

Read that against tactic 4 below. Pasting a 3,000-token stack trace into a long session is not a 3,000-token decision. It is closer to a 1,000,000-token decision.

3. Three sessions were 42% of the bill.

SliceShare of total spend
Top 1% of sessions (3 of 335)42.4%
Top 10% (34 sessions)88.2%
Bottom 50% (168 sessions)1.7%
Median session: $6.51. Mean session: $94.30. The distribution is so skewed that per-prompt frugality is close to pointless. Cost control is about noticing and killing the two or three sessions per month that run away, which is what tactic 9 is for.

4. The 5-minute cache window is no longer the thing to manage.

Of 477 M cache-write tokens, 423 M (89%) were written with a 1-hour TTL, not the 5-minute default that every guide on this topic (including the earlier version of this one) tells you to protect. Claude Code opted into the long TTL. Walking away for lunch no longer costs you the cache.

Methodology and honesty note: dollar figures throughout are API list-price equivalents computed from the recorded token counts at current published rates, not an invoice. I ran most of this on a subscription plan, so I was not charged these amounts. The ratios and multipliers are exact; treat the dollars as "what this workload would cost on metered API access." Total for the 35 days: $21,169 list-price equivalent, against a mix that was 53% Claude Fable 5 and 46% Opus-tier by spend.

What is "Claude Code cost" actually measuring?

Claude Code is Anthropic's terminal-based AI coding agent that reads your repo, edits files, runs commands, and iterates with you. Its cost, like Codex cost (OpenAI's coding agent) and Cursor cost (the popular AI-first IDE), is measured in tokens, the chunks of text the underlying model processes.

Every API call has two billable sides:

  • Input tokens, everything the model reads: your message, the system prompt, the entire conversation history so far, every file the agent has read, every tool output, every shell log it has captured.
  • Output tokens, everything the model writes: the reply, the code, the tool calls. Output is typically priced 4–5× higher per token than input.

Here's the part most developers underestimate: the conversation is re-sent in full on every turn. The model doesn't "remember" cheaply. Each new message pays for the whole transcript again. That's why a one-line follow-up at hour three can cost more than your first ten messages combined.

Why does one short prompt sometimes cost a fortune?

Three forces compound:

1. Context accumulation. A typical agent session reads files, runs builds, greps directories, fetches URLs, and writes new files. Every one of those results joins the transcript and is re-billed on every subsequent turn. Here is the measured growth curve from my sessions, as median billed input tokens per turn:

Turn numberMedian contextp90 context
1 to 1046,75858,476
41 to 5097,320141,743
91 to 100148,909212,814
191 to 200228,424305,313
291 to 300294,314360,661
It climbs steadily and it does not come back down on its own. By turn 100 you are paying roughly three times per turn what you paid at the start of the session, for the same quality of question. (Anthropic - Pricing)

2. Model tier multiplier. Claude Opus 5 is priced at $5 per million input tokens and $25 per million output, against $3 and $15 for Claude Sonnet 5 and $1 and $5 for Claude Haiku 4.5. Claude Fable 5, the top tier, is $10 and $50. The same conversation costs proportionally more on the bigger model, and most edits, lint fixes, and one-line refactors do not need the top of the range. In my own mix, Fable 5 ran 34% of the turns and took 53% of the spend.

3. Cache economics, which changed. Anthropic, OpenAI, and Cursor all use prompt caching: the unchanged prefix of a recent prompt is stored so repeat calls skip re-processing it. Cached reads bill at roughly 10% of the input price. The commonly repeated advice is to protect a 5-minute window. That is now the wrong thing to optimise: 89% of the cache writes in my sessions used the 1-hour TTL, which costs 2x base input to write instead of 1.25x but survives lunch, a meeting, and most context switches.

What still costs you is invalidation. Prompt caching is a prefix match, so any change to an earlier part of the conversation invalidates everything after it. Switching model mid-session, or changing the tool set, throws the whole cache away regardless of TTL. (Anthropic - Prompt Caching)

In one sentence: a surprise bill is almost never one expensive query. It is full session context, multiplied by 27 turns of re-billing, at a model tier the task did not need.

How does Claude Code cost compare to Codex cost and Cursor cost?

The mechanics are nearly identical across tools, only the price points and packaging differ.

ToolBilling modelWhere cost balloons
Claude CodePer-token API or Pro/Max subscription with usage capsLong sessions at high effort on a top-tier model
Codex (OpenAI)Per-token API or ChatGPT plan with rate limitsReasoning tokens on long traces
CursorSubscription with "fast requests" + paid overage on premium modelsPremium "Max" mode left on auto
One thing that has changed and is worth flagging, because plenty of older guides still warn about it: the 1M-token context window is no longer a premium pricing tier on current Claude models. It is the default window at standard rates. Running a long session is expensive because of re-billed context, not because of a long-context surcharge.

Three cross-tool truths to keep in mind:

  • Reasoning tokens are real tokens. OpenAI's o-series and Anthropic's extended thinking generate hidden chain-of-thought that you pay for, even though you never see it. Long thinking on a routine task is one of the easiest ways to inflate Codex cost. (OpenAI, Reasoning models)
  • "Unlimited" plans aren't unlimited. Cursor's pricing tiers and Claude's Max plan both have soft and hard usage limits; hit them and you get throttled or pushed to overage pricing.
  • Tool calls are conversation turns. Each agent step (read a file, run a test, grep, retry) is a billable round trip with full re-injected context.

9 tactics to cut Claude Code cost (in order of impact)

Ranked by how much each one typically saves on a real-world session.

1. Start fresh sessions for unrelated work

The single biggest lever, and the data says so plainly. The moment you switch from "debug auth" to "write a migration," run /clear (Claude Code) or open a new chat (Codex, Cursor). Carrying 200K of stale context is not free storage: at the measured 27x amplification, every token you decline to clear is a token you buy roughly 27 more times.

2. Compact long sessions, but know what it costs

When you genuinely need continuity, /compact compresses the transcript into a summary. It works: across 97 compactions in my sessions, median context went from 420,840 tokens to 65,844, an 84% cut.

Two things the docs do not tell you. First, compaction is slow: median wall time 123 seconds, p90 158 seconds, worst case 198 seconds. Second, it does not last. Context regrew 22% within 10 turns of compacting. /compact buys you roughly one more working stretch, not a reset.

The durable pattern is to make context disposable: keep working state in a file on disk, then /clear and have the agent re-read it. Anything the compaction summary drops is gone, but the file survives.

3. Drop to a smaller model for routine work

Most edits, renames, lint fixes, and small refactors do not need the top tier. In Claude Code: /model sonnet. In Cursor: pick the cheaper model in the picker. Claude Sonnet 5 runs at roughly 60% of Opus 5's per-token price and a third of Fable 5's, and on routine work you cannot tell the difference in output quality.

One caveat that is specific to caching: switching model mid-session throws away the prompt cache, because caches are model-scoped. Pick the tier when you start the session rather than flipping back and forth. If you need a cheaper model for one sub-task, delegate it to a subagent instead and leave the main loop where it is.

4. Don't paste large logs, summarize them

Pasting a 200-line stack trace does not just cost tokens this turn. It costs tokens every subsequent turn for the rest of the session. Better:

"The build failed. The error was Cannot find module 'foo' at bar.ts:42."

That is 30 tokens instead of 3,000. And at 27x amplification, the real comparison is 800 tokens against 81,000.

5. Never let an image into a long session

This is the most expensive mistake in the dataset and almost nobody warns about it. Across 4,372 file reads, the median cost 860 tokens. The p99 cost 14,311. The single most expensive read was a screenshot at 80,627 tokens, more than most entire source modules.

Images are dense. A full-resolution screenshot on current models can consume close to 5,000 visual tokens on its own, and a large PNG read off disk costs far more. Then it sits in context and gets re-billed on every remaining turn.

If you need the agent to look at a screenshot, do it in a short dedicated session, or crop and downsample first. Do not drop one into hour three of a debugging marathon.

6. Stop guarding the cache window, start guarding the cache prefix

The advice you will read everywhere, including in the first version of this post, is that prompt cache TTL is 5 minutes so you should work in tight bursts. That is out of date. In my sessions, 89% of cache writes used the 1-hour TTL. Idle gaps are largely a solved problem.

What still burns money is invalidating the prefix, because caching is a prefix match and a change anywhere invalidates everything after it. Concretely, avoid:

  • Switching models mid-session (caches are per-model, so this is a total loss)
  • Editing your CLAUDE.md or system instructions mid-session, which sits at the front of the prefix and invalidates the entire conversation behind it
  • Adding or removing MCP servers and tools mid-session, since tools render before everything else

Do those between sessions, not during one.

7. Be explicit about what files the agent should read

Vague instructions like "fix the auth bug" can trigger an agent to read half the codebase. Specific instructions like "in src/auth/session.ts, the cookie expiry is wrong, make it 7 days" prevent exploratory reads that bloat context permanently.

There is a speed dividend too. In my sessions, 74.9% of tool-calling turns issued exactly one tool call, meaning most of the agent's work is sequential round trips. Naming the files up front lets it batch reads in parallel instead of discovering them one at a time.

8. Tune effort rather than toggling thinking

Reasoning tokens are real tokens you pay for. On current Claude models the lever is no longer an on/off thinking switch but an effort setting that runs low, medium, high, xhigh, and max. Higher effort means deeper reasoning and more tool calls; lower effort means the model scopes its work tightly to what you asked.

For routine work, dropping from the default to medium or low is the cleanest cost saving available, because it reduces both thinking tokens and the number of exploratory tool calls that would have landed in context. Reserve the top settings for genuinely hard problems. 78% of my turns ran at high effort, which in hindsight was the wrong default for a lot of them.

9. Hunt runaway sessions, not expensive prompts

In my 35 days, the top 1% of sessions accounted for 42% of spend, and the top 10% for 88%. The median session cost $6.51 while the mean was $94.30. That gap is the whole problem.

Frugality per prompt cannot fix a distribution that skewed. What fixes it is noticing when a session has gone long and circular, and ending it. Practical trigger: if you have compacted twice, or the agent is re-reading files it already read, the session has stopped paying for itself. Write state to a file, /clear, and start again.

How does prompt caching change the math?

Prompt caching is what makes agentic coding affordable at all, and it is worth understanding precisely because the guidance around it has changed.

The mechanics:

  • The provider stores the prefix of a recent prompt: the system prompt, the tool definitions, file contents already read, earlier turns.
  • On the next call, if the prefix matches byte for byte, you pay a deeply discounted rate for the cached portion, roughly 10% of the input price (Anthropic - Prompt Caching).
  • Writing to the cache carries a premium: 1.25x base input for the 5-minute TTL, 2x for the 1-hour TTL.

The break-even maths follows directly. With a 5-minute cache, two requests pay for themselves (1.25x plus 0.1x beats 2x uncached). With a 1-hour cache you need three, but you get an hour of protection instead of five minutes.

Claude Code has already made that trade for you. In my measured sessions, 423 M of 477 M cache-write tokens carried the 1-hour TTL. This is why the cache-read share of my input tokens was 97.0%: almost nothing was ever re-processed cold.

Implication: the old rule about working in tight bursts is largely obsolete. The failure mode to design around is not the clock, it is any edit that changes the front of the prompt. Changing models, editing CLAUDE.md, or adding an MCP server mid-session invalidates the cache instantly, at any TTL.

A useful diagnostic: if your sessions feel expensive, check whether cache reads dominate your input tokens. If they do not, something in your setup is invalidating the prefix on every turn.

Which model should I default to for routine work?

A practical heuristic developers can actually follow:

Current Claude list pricing, per million tokens, gives you the shape of the decision:

ModelInputOutput
Claude Haiku 4.5$1$5
Claude Sonnet 5$3$15
Claude Opus 5$5$25
Claude Fable 5$10$50
Which maps onto tasks like this:

Task typeRecommended tierWhy
Lint fixes, renames, formattingHaiku 4.5Trivial, fast, a fifth of Opus pricing
Single-file edits, small refactorsSonnet 5Near-Opus quality on coding at 60% of the price
Cross-file refactors, debugging tricky bugsSonnet 5 or Opus 5 at higher effortBest quality per dollar on hard work
Long autonomous runs, architecture, novel algorithmsOpus 5Strongest on long-horizon agentic work
The genuinely hardest unsolved problemsFable 5Highest capability, and priced accordingly
Two practical rules. Stay on Sonnet 5 and escalate only when you hit something it cannot handle. And pick the tier at the start of the session, because switching mid-session invalidates your prompt cache and you pay to rebuild the entire context from cold.

Common mistakes that quietly inflate AI coding costs

  • Using the agent as a search engine. "What does this function do?" with a long session attached is far more expensive than reading the file yourself. Use a fresh, narrow session for explanations.
  • Letting the agent run unbounded shell commands. A find / or a recursive grep with no path scope can dump megabytes of paths into context.
  • Ignoring cost dashboards. Anthropic's console, OpenAI's usage page, and Cursor's settings all show real-time spend. Most developers never look until they get a bill.
  • Confusing "fast" with "cheap." Cursor's "fast requests" are a rate-limit term, not a pricing term. Hitting your fast-request quota and falling to slow-mode doesn't save money, it just slows you down.
  • Treating subscriptions as license to spam. Subscription plans (Claude Pro/Max, ChatGPT Plus, Cursor Pro) all have usage caps. Burn through them and you'll either be throttled or pushed onto overage pricing.

FAQ

How much does Claude Code cost per day for a typical developer?

A developer on a Pro or Max subscription pays a flat monthly fee with usage caps. On pay-per-token API access, the variance is enormous and is driven by session hygiene rather than how much you code.

My own measured distribution over 35 days, in list-price equivalents: the median session cost $6.51 and the mean cost $94.30, because a handful of very long sessions dominated. If your sessions stay short and scoped, a few dollars a day is realistic. If you run multi-hour agentic sessions on a top-tier model at high effort, a single session can cost more than a month of light use.

What is context amplification and why does it matter more than prompt length?

Because the conversation is stateless, the full transcript is re-sent on every turn. So a token added to context is billed once per remaining turn in the session, not once in total.

Measured across 335 of my sessions, the median token was billed 27.3 times. In sessions over 200 turns, 386 times. This is why editing your prompts to be shorter saves almost nothing, and why deciding what enters context at all saves almost everything.

Is the Claude prompt cache still only 5 minutes?

No, and this is the most common piece of outdated advice on the topic. Anthropic offers both a 5-minute and a 1-hour TTL, and in my measured sessions 89% of cache writes used the 1-hour option. The 1-hour cache costs 2x base input to write instead of 1.25x, and in exchange your context survives meetings and lunch breaks.

The thing to protect now is the cache prefix, not the clock. Switching models, editing CLAUDE.md, or changing your MCP servers mid-session invalidates everything regardless of TTL.

Does using the 1M context window cost extra?

Not on current Claude models. It is the default context window at standard pricing. Older guidance describing a long-context premium tier above 200K tokens no longer applies. Long sessions are expensive because of re-billed context, not because of a window surcharge.

Is Cursor cost cheaper than Claude Code cost?

Cursor's flat $20/month Pro plan is cheaper than running Claude Code on raw API tokens for most users, until you exceed the fast-request quota or use premium "Max" models. At that point, Cursor's overage pricing tracks the underlying model's API cost. For routine use, Cursor's subscription wins; for heavy agentic work, Claude Code with /compact discipline can be more efficient.

Does Codex cost more than Claude Code cost?

It depends on the model. GPT-5 and the o-series are priced comparably to Claude Opus per output token, but their reasoning-token billing means a hard problem can rack up costs invisibly. For pure code generation without long reasoning chains, Codex on GPT-4.1 is generally competitive with Claude Sonnet.

What's the fastest way to lower my AI coding bill this week?

Three moves: (1) Switch your default to a mid-tier model (Sonnet, GPT-4.1, or equivalent). (2) Run /clear between unrelated tasks. (3) Stop pasting full logs, paraphrase the error. Most developers see a 60%+ drop within a few days.

Do I save money by writing shorter prompts?

Marginally, but not as much as you'd think, your prompt is usually a tiny fraction of the per-turn token count compared to the accumulated history and tool results. Managing the conversation, not the message, is where the real savings live.

Does prompt caching work automatically?

Yes. Claude Code, Codex, and Cursor all enable caching automatically and you do not have to opt in. What you control is whether you keep the prefix stable. If you want to verify it is working, check whether cache reads dominate your input tokens; in my sessions they were 97% of input.

Do subagents make things more expensive?

Less than people assume. In my dataset, subagent runs were 12.1% of all turns but only 3.5% of spend, because each subagent starts with a small fresh context instead of inheriting the parent's accumulated transcript.

That is the actual argument for delegation: it is a way to do work at low context rather than adding to a context you are already paying 27x on. The caveat is that spawning them freely for trivial work still adds up, since each one re-establishes its own context.

Key Takeaways

  • AI coding cost is dominated by context that is re-sent every turn, not by the length of your latest message. Measured across 74,493 turns, the median context token was billed 27 times, and 386 times in sessions past 200 turns.
  • Output is 0.44% of your tokens. Everything the agent writes is a rounding error next to what it reads. Optimise what enters context, not what comes out.
  • Spend is not spread evenly. The top 1% of my sessions was 42% of the bill. Hunt runaway sessions, not expensive prompts.
  • The 5-minute cache rule is obsolete. 89% of cache writes now use the 1-hour TTL. Protect the cache prefix instead: do not switch models, edit CLAUDE.md, or change tools mid-session.
  • /compact costs about two minutes and lasts about ten turns. It cut context 84% in my sessions, then context regrew 22% within 10 turns. Keep state in a file and /clear instead.
  • Never read an image into a long session. The most expensive single file read I measured was a screenshot at 80,627 tokens, and it then re-bills on every remaining turn.
  • Pick the model tier at the start, because switching mid-session invalidates the cache.
  • The same principles cut Codex cost and Cursor cost. The physics of token billing is universal.

Social hook: I measured 74,493 turns of my own Claude Code sessions. Output was 0.44% of the tokens I paid for. The other 99.5% was the same context, bought again, an average of 27 times.


References

  1. Anthropic - Pricing
  2. Anthropic - Prompt Caching documentation
  3. Anthropic - Claude Code documentation
  4. OpenAI - Reasoning models guide
  5. OpenAI - API pricing
  6. Cursor - Pricing and usage
  7. Primary data: 350 Claude Code session transcripts from ~/.claude/projects/, covering 74,493 assistant turns across 35 days on client versions 2.1.187 to 2.1.222. Token counts read from the per-turn usage records; dollar figures are list-price equivalents at current published rates.
AITutorialsApril 29, 2026
Share
Aakash Ahuja

Aakash Ahuja

Enterprise AI, Cybersecurity & Platform Engineering

Aakash writes about secure AI agents, microservices architecture, enterprise platforms, and production engineering. He has 20+ years of experience building and operating software systems across banking, cloud, cybersecurity, AI, and enterprise workflow automation. He is Director of Technology at itmtb Technologies and teaches AI, Big Data, and Reinforcement Learning at top institutes in India.