Cost Optimization Secrets
Claude Code's source reveals exactly what you pay — and five engineering tricks that slash the bill. Prompt caching alone saves 87.5% on input tokens. A Haiku-powered compaction costs a tenth of a cent. A 50-message Opus session lands at roughly $2.10. Here is how it all works, extracted directly from modelCost.ts and the surrounding infrastructure.
What does Claude Code actually cost?
The exact numbers live in services/api/modelCost.ts. Select a metric below to compare models. The output column is the one that hurts — Opus costs $75 per million output tokens.
Cache writes cost 25% more than regular input (one-time penalty to prime the cache). After that, every cache read is 90% cheaper. Source: services/api/modelCost.ts
5 Strategies Claude Code Uses to Keep Costs Down
These are not guidelines for users — they are engineering decisions baked into the source. Tap any strategy to see how it works and the actual code behind it.
The Hidden Cost: Cache Misses
The entire caching strategy depends on the static system prompt staying stable. If Anthropic updates it — adding a new tool description, changing a safety instruction, or fixing a bug — every cached entry for every user invalidates simultaneously. The first request after an invalidation pays full price: ~$0.12 on Opus for the 8KB prompt alone. This is why the static portion of the system prompt is engineered to change as rarely as possible. Frequent updates would negate the caching benefit entirely.
Cache TTL: 1 hour · Boundary marker: __SYSTEM_PROMPT_DYNAMIC_BOUNDARY__
Build Your Session Estimate
The defaults below represent a typical 50-message Opus session with active caching. Adjust the counts to match your usage pattern.
Session Cost Calculator
Adjust the counts below to estimate your session spend on Opus 4.6.
Key Source Files (v2.1.88)
services/api/modelCost.tsExact pricing per model, cache multipliers
utils/api.tsCache splitting logic, boundary marker
services/compaction.tsMicrocompaction algorithm, Haiku model choice
services/budget.tsToken budget tracking, status bar display
constants/prompts.tsSystem prompt assembly, static/dynamic split