How to reduce Claude Code costs
Last verified
Measure before you optimise. Where the money goes is not where people assume:
npx @tknapp/cli agents --days 30 --by session
In a measured session, cache reads were 98% of tokens and 60% of cost, output was 16%, and the text actually typed was a rounding error. Optimising your prompt wording is optimising 0% of the bill. Full breakdown in why Claude Code feels expensive.
Here is what actually moves it, in order.
1. Start a new session for a new task
The biggest lever, and free.
Cost per turn rises with context length, because each turn resends everything before it. A long session carrying three unrelated tasks pays to re-read task one's files while working on task three.
Rule of thumb: when the topic changes, start fresh.
2. Be specific about which files to look at
Reading files is the expensive operation. One 800-line file is ~10,000 tokens in context, permanently, for the rest of the session.
"Fix the auth bug in src/auth/session.ts" costs a fraction of "fix the auth bug", because the second one means reading around to find it first.
3. Use a cheaper model for mechanical work
The rate difference between model tiers is several-fold on both input and output. Renaming things, writing boilerplate, formatting, simple refactors — a smaller model does these fine.
Save the expensive model for work where reasoning quality actually changes the outcome. This is the largest single-step reduction available, and it costs you nothing on tasks that didn't need the capability.
4. Keep tool output small
An unbounded tool result enters the context and stays there. A search returning 200 matches, a test run dumping a full stack trace, a large API response — each one enlarges every subsequent request in the session.
Narrow the search. Ask for a summary rather than a dump. Truncate before it enters context.
5. Install fewer MCP servers
Every connected tool's definition sits in context on every single request. Ten servers with a dozen tools each is a fixed tax on every message you send, before anything happens.
Audit what's connected. Remove what you don't use weekly. Cost tracking for MCP servers.
6. Let the cache work for you
Cache reads cost 0.1× base input — the difference between a usable bill and an unusable one.
Caching matches on a prefix, so anything variable early in the context destroys the hit for everything after it. Keep stable content (instructions, project conventions) stable, and avoid injecting timestamps or changing preambles.
Note the break-even: a 1-hour cache write costs 2× base input and pays back after two reads. A session that writes a large cache and then ends immediately has paid a premium for nothing — another reason not to open a long session for a one-line question.
7. Use subagents for wide reads
Counter-intuitive but real. A subagent that reads twenty files and returns a summary keeps those twenty files out of your main context — where they would otherwise be resent on every subsequent turn.
The subagent's own context is real spend, so this is a trade, not a free win. It pays when the read is wide and the conclusion is narrow.
8. Say when you're done
An agent that isn't told the task is complete may keep verifying, re-reading and double-checking. Each cycle carries the full transcript. Closing the loop explicitly ends the spend.
9. Set a budget you actually see
None of the above helps if nobody notices when a month doubles.
Weekly:
npx @tknapp/cli agents --days 7
And for metered API spend across providers, a threshold checked against daily spend — getting alerted when AI spend spikes.
What doesn't work
Shorter prompts. Fresh input was 331 tokens in a 59M-token session. Optimising your typing is optimising nothing.
Asking the model to be efficient. A system-prompt instruction is a suggestion the model will deprioritise when it is trying to finish a task. Real limits go in code — cost control for autonomous agents.
Disabling caching. It is saving you roughly 85%, not costing you money.
Sources
- Anthropic — Pricing and prompt caching (verified 2026-08-05)
- Claude Code — Manage costs effectively