Save money

How to cut your AI coding bill

Quick answer

An AI agent re-sends your context on every turn, so long sessions pay for the same text many times. Caching bills repeats at 0.05x to 0.1x the input price, batch work is 50% off, and a small model costs a fraction of a big one.

Why your bill is so high

Caching, worked out

Illustrative example, not a promise: 30 turns that each re-send 50,000 tokens of context and get 1,500 back, on Claude Sonnet 5.5 ($2 in, $0.1 cached, $10 out per 1M). The first turn writes the cache at 1.25x.

No caching30 × 50,000 × $2/1M + output$3.45
With caching1 write at 1.25x + 29 reads at $0.1/1M + output$0.72

12 fixes, with the vendor's own docs

  1. 1
    Let prompt caching work

    Cached input costs 0.1x the normal input price on most Claude models and 0.05x on Sonnet 5.5 and Opus 5.5, after a one-time write at 1.25x (Anthropic ↗). OpenAI caches automatically, up to 95% off (OpenAI ↗). Gemini caches implicitly (Google ↗). Keep the start of your prompt the same between turns so it hits the cache.

  2. 2
    Batch anything that can wait

    Batch APIs are 50% off at Anthropic, OpenAI and Google, with results within 24 hours (Anthropic ↗, OpenAI ↗, Google ↗). Good for test generation, docs and bulk reviews.

  3. 3
    Small model for easy steps

    Anthropic suggests Sonnet for most coding, Opus only for hard reasoning and Haiku for simple subagents (Claude Code docs ↗).

  4. 4
    Clear between tasks

    Run /clear when you switch to unrelated work. It costs nothing, while /compact is itself a large request (Claude Code docs ↗). Start a fresh chat in other tools too.

  5. 5
    Keep instruction files short

    CLAUDE.md loads every session: keep it under 200 lines (Claude Code docs ↗). OpenAI's first tip for Codex limits is a smaller AGENTS.md (OpenAI ↗).

  6. 6
    Hide files the AI doesn't need

    A .cursorignore file keeps folders out of Cursor's Agent, Tab and @-mentions, though Cursor says it isn't a guarantee (Cursor docs ↗). Point agents at the two or three files that matter.

  7. 7
    Turn effort down

    Thinking bills as output. In Claude Code, a lower /effort saves tokens (Claude Code docs ↗).

  8. 8
    Ask for diffs, not whole files

    Output costs 5x input on Sonnet 5.5 ($10 against $2 per 1M). A 20-line diff is far fewer output tokens than a 400-line file.

  9. 9
    Plan first, then build

    A short plan you approve stops the agent from writing code you throw away. Fewer rewrites, fewer output tokens.

  10. 10
    Trim tool output and MCP servers

    A Claude Code hook can filter test logs to the errors before Claude reads them (Claude Code docs ↗). Remove MCP servers you don't use.

  11. 11
    Set a spending cap

    Copilot lets you set an extra-usage budget (GitHub ↗), Zed Pro has an optional cap and Kiro alerts at 80% and 100%.

  12. 12
    Use off-peak hours

    DeepSeek's API is half price off-peak (DeepSeek ↗).

Cheap prompts to copy

Savings vary

The example above shows the maths, not what you will save. Your bill depends on your tools, models and habits.

FAQ

Why is Claude Code so expensive?

Each turn re-sends your conversation and files, thinking bills as output, and long sessions or agent teams multiply both. Anthropic's cost docs put the average in enterprise deployments at about $13 per developer per active day.

How do I reduce Claude Code costs?

Run /clear between tasks, keep CLAUDE.md under 200 lines, use Sonnet for most work and Haiku for simple subagents, lower /effort and filter long tool output. All are in Anthropic's Claude Code cost docs.

What is prompt caching?

The provider stores the start of a prompt it has seen recently and bills repeats at a fraction of the input price: 0.1x on most Claude models, up to 95% off on OpenAI.

Does Claude Code use prompt caching?

Yes. Anthropic's docs say Claude Code applies prompt caching and auto-compaction on its own.

Is the Batch API cheaper?

Yes. Anthropic, OpenAI and Google all charge half price for batch requests, which return within 24 hours.