TechBrosEbooks
CatalogGuidesCartLog in

TechBrosEbooks

Independent, instant-download tech ebooks. Secure checkout via your choice of trusted payment provider.

GuidesAbout UsContact Us
Terms & ConditionsPrivacy PolicyRefund & Cancellation PolicyShipping & Delivery Policy
© 2026 TechBrosEbooks. All rights reserved.
← All guides

Why Your AI Coding Agent Bill Grows With Every Turn (and 7 Ways to Cut It)

4 November 2026 · 7 min read

If you use Claude Code, Cursor or Codex every day, you have probably had one of two surprises: an API bill much larger than you expected, or a "you've hit your usage limit" message halfway through the afternoon. Both have the same cause, and once you see it, most of the fixes become obvious.

An agent resends everything, every time

A chatbot answers one message. A coding agent works in a loop: it thinks, reads a file, runs a command, reads the output, and thinks again. Every step is a separate request to the model, and every request carries the whole context:

Part of the requestTypical sizeSent when
System prompt and tool definitionsThousands of tokensEvery request
Instruction files (CLAUDE.md, AGENTS.md, rules)Hundreds to thousandsEvery request
Conversation historyGrows every turnEvery request
Tool results (file contents, command output)Often the largest partEvery request after they appear

So a one-line question asked in a session that has been open all day still pays for the whole day's conversation.

Why cost grows with the square of session length

Say each turn adds about 5,000 tokens. Turn 1 sends 5k, turn 2 sends 10k, and turn 20 sends 100k. Add it up and a 20-turn session processes roughly 1.05 million input tokens, even though only 100k of them were new.

Here is a quick model of that at illustrative Claude Sonnet 5 list prices ($2 per million input tokens, $0.20 per million for cache hits):

PRICE_IN, PRICE_CACHE_WRITE, PRICE_CACHE_HIT = 2.00, 2.50, 0.20  # $ per million tokens

def session_cost(turns, tokens_added_per_turn, cached=True):
    total_in, new_total = 0, 0
    for t in range(1, turns + 1):
        total_in += t * tokens_added_per_turn  # whole context re-sent
        new_total += tokens_added_per_turn
    if not cached:
        return total_in / 1e6 * PRICE_IN
    reused = total_in - new_total
    return new_total / 1e6 * PRICE_CACHE_WRITE + reused / 1e6 * PRICE_CACHE_HIT

# 10 turns: $0.55 uncached, $0.17 cached
# 20 turns: $2.10 uncached, $0.44 cached
# 40 turns: $8.20 uncached, $1.28 cached

Doubling a session from 20 to 40 turns roughly quadruples the uncached input cost. And that ignores output tokens, which cost about five times as much as input across the Claude line-up.

Subscriptions are not immune. On Pro, Max or Team plans you don't see a per-request bill, but the same tokens drain your usage window.

Seven ways to cut the cost

1. Measure for a week first

You can't cut what you can't see. In Claude Code, /usage shows session tokens by model, cache reads and writes and an estimated cost, and /context shows what is filling the window right now. Track four numbers: cost per session, cost per completed task, the share of input served from cache, and how much of your spend goes to the premium model. Judge every later change by cost per completed task. A cheap model that needs three attempts isn't cheap.

2. One task, one session

This single habit fixes the most common cause of runaway spend. When you switch to unrelated work, start fresh (/clear in Claude Code, a new chat in Cursor or Codex). Clearing costs nothing; carrying yesterday's debugging session into today's feature makes every message pay for both. Use /rename first if you might want to /resume the old session.

3. Default to the mid-tier model

Most daily coding work doesn't need a flagship model. Use a mid-tier model (Sonnet-class) for features, bug fixes and refactors, a small one (Haiku-class) for renames, boilerplate and log summaries, and save the premium tier for architecture and nasty concurrency bugs. A useful pattern: plan with the premium model, then switch with /model to implement. The expensive model spends a few thousand tokens thinking instead of hundreds of thousands editing files.

Thinking is billed as output, the most expensive kind of token. Lower the effort level for routine tasks.

4. Put your instruction file on a diet

CLAUDE.md, AGENTS.md and Cursor rules are loaded on every request, so every line is a recurring cost. Anthropic recommends keeping CLAUDE.md under 200 lines. Apply a simple test to each line: if I delete this, will the agent make a mistake in most sessions? If not, move it out. Multi-step procedures like releases belong in skills or on-demand docs that load only when needed.

Cutting a 400-line file (about 5,000 tokens) to 40 lines saves around 4,500 tokens per request. Over a few hundred requests a day, that's over a million tokens.

5. Keep noisy output out of context

Test runners and build logs can produce thousands of lines, and every line is resent on every later turn. Ask for filtered commands ("run pytest -q and show only failures"), push verbose jobs to a subagent so only a summary comes back, and block generated code, lockfiles and vendored dependencies from being read.

6. Stop breaking the prompt cache

Prompt caching lets the model reuse a context prefix it has already processed at a tenth of the normal input price, and your coding tool usually turns it on for you. But the prefix has to be byte-identical. These habits break it:

  • connecting or disconnecting MCP servers mid-session (tool definitions sit near the start of the prefix)
  • switching models mid-conversation (caches are per model)
  • editing your instruction file during a session
  • coming back to a huge session after a long break, once the cache has expired

/usage reports your cache-hit share. If it drops, one of these is usually why.

7. Use cheap subagents for legwork, but not for everything

A subagent runs in its own context and returns only a summary, which is ideal for searching a codebase or digesting test output. Pin it to a small model and your main context stays small too. But each subagent loads its own instructions and tools, so spawning one for a two-line lookup can cost more than doing it inline. Agent teams multiply this: Anthropic's docs put them at about 7x the tokens of a standard session when teammates run in plan mode.

What normal looks like

For a sense of scale, Anthropic reports that Claude Code averages about $13 per developer per active day across enterprise deployments, with 90% of users under $30. The two usual causes of unexpectedly high spend are exactly the ones above: long sessions that are never cleared, and a premium model left as the default.

Prices and plan limits change often, so check your provider's pricing page before acting on any figure here. The principles don't change: measure, route, trim, cache and guard.

This article is adapted from our ebook Stop Burning Tokens, which covers each technique in depth with configs and scripts, including a hook that filters test output, local-model fallback, spend guardrails, and a 30-day rollout plan.

Cover of Stop Burning Tokens: Cost Engineering for AI Coding Agents

The full guide

Stop Burning Tokens: Cost Engineering for AI Coding Agents

Instant-download PDF · ₹2,100

See the ebook