Save money
How to cut your AI coding bill
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.
- 0.05–0.1xcached input vs normal (Claude)
- 50%batch discount
- 40xOpus vs Haiku input price
- ~$13Claude Code, avg per active day (enterprise)
Why your bill is so high
- Every turn re-sends the chat and files in context, so a long session pays for the same text again and again. Claude Code docs ↗
- Thinking tokens bill as output, the expensive side. Anthropic ↗
- Agent teams use about 7x the tokens of a normal Claude Code session. Claude Code docs ↗
- Every MCP server you connect adds context to each message in Codex. OpenAI ↗
- A top model for small edits: Opus 5.5 input costs 40x Haiku 5.5's on the API.
- Third-party models on Cursor Premium and above bill at API list price on top of the plan. Cursor docs ↗
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 caching | 30 × 50,000 × $2/1M + output | $3.45 |
|---|---|---|
| With caching | 1 write at 1.25x + 29 reads at $0.1/1M + output | $0.72 |
12 fixes, with the vendor's own docs
- 1Let 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.
- 2Batch 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.
- 3Small model for easy steps
Anthropic suggests Sonnet for most coding, Opus only for hard reasoning and Haiku for simple subagents (Claude Code docs ↗).
- 4Clear 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.
- 5Keep 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 ↗).
- 6Hide 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.
- 7Turn effort down
Thinking bills as output. In Claude Code, a lower /effort saves tokens (Claude Code docs ↗).
- 8Ask 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.
- 9Plan first, then build
A short plan you approve stops the agent from writing code you throw away. Fewer rewrites, fewer output tokens.
- 10Trim 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.
- 11Set 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%.
- 12Use off-peak hours
DeepSeek's API is half price off-peak (DeepSeek ↗).
Cheap prompts to copy
- Diff only
Fix the bug in src/cart.ts where totals ignore discounts. Reply with a unified diff only. No explanation, no unchanged code.
Output is the expensive side. A diff is a fraction of the full file.
- Plan first
Before writing code, list the files you will change and the steps, in at most 8 lines. Wait for my OK.
Catches a wrong approach before the agent writes hundreds of lines.
- Read only these files
Only read src/api/user.ts and src/api/types.ts. Do not open other files unless I ask.
Stops the agent from pulling the whole repo into context.
- Short answer
Answer in at most 5 lines. No intro and no summary.
Cuts filler output on simple questions.
- Hand-off summary
Summarise this session in 10 bullet points: goal, decisions, files changed, open issues. I will paste it into a new chat.
Lets you start fresh without re-sending a long history.
- Error triage
Here are the last 30 lines of the failing test output. Name the most likely cause and the smallest fix.
Sends 30 lines instead of the full log.
- Tests only
Write 3 unit tests for formatPrice() in src/money.ts. Return only the new test file.
A clear target and output format means one pass instead of several.
- Bug-only review
Review this diff for bugs only. List at most 5 issues as file:line and the problem. Skip style.
Keeps the review short and on what matters.
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.