DEV Community

amy5193111-svg
amy5193111-svg

Posted on

Cutting Claude Code API Costs: Where the Money Actually Goes

Most developers hit the same wall a week into using Claude Code: the token bill grows faster than the output. Here is where the money actually goes, and the config changes that move the needle.

Where the tokens go

Three buckets dominate:

Bucket Typical share Why
Cache writes 20-35% Every new file in context re-billed
Cache reads 30-50% Cheap per token, but constant
Fresh output 15-25% The only bucket you actually want

The counterintuitive part: context management beats model choice. Switching from a frontier model to a mid-tier one saves less than fixing context bloat.

Three changes that work

1. Set an explicit context ceiling. Auto-compaction helps, but a hard ceiling forces the agent to summarize early rather than discover the limit mid-task.

2. Separate read-heavy from write-heavy sessions. Exploration and implementation have different cost shapes; mixing them means paying cache-write prices for work that never needed repo context.

3. Watch the base URL. If you are routing through a gateway rather than hitting the provider directly, the per-token price may differ from the published rate card.

Measuring it properly

The only honest way to compare is to log input/output/cache tokens separately per session. Aggregate "total spend" hides the structure you need to fix.

I wrote up the full breakdown with the actual numbers, including the config file changes, here: Claude Code monthly cost breakdown and a base URL configuration walkthrough.

The short version: measure the three buckets separately, cap context, and stop switching models hoping it fixes an architecture problem.

Top comments (0)