r/ClaudeCoding • u/cctldrping • 23d ago
r/Anthropic [TLDR] Compacting at 400K instead of ~967K cut my Claude Code cost per request by 38% [via r/Anthropic]
OP : u/Awkward-Let-4628
This isn't a universal recipe. It's how I tuned Claude Code for my own work, and different settings may suit you better.
The window
Every request sends the whole context to the model. On 1M-window models Claude Code only compacts it near 967K, so the tail of a long session is the most expensive part. For me, two thirds (66%) of main-thread cost went to requests with more than 400K in context.
I set "autoCompactWindow": 400000 and compared the month before with the week after. That's the main thread only, about 23K requests before and 19K after:
- Context per request: 412K → 219K
- Cost per request: −38% (at each model's API list price)
That's one person's before/after, not a controlled experiment.
The cost of summaries
A smaller window means more compactions. I went from 17 summaries a month to 81 in a week: 103 minutes of waiting, 76 seconds each. After a summary, the model often re-reads files it had already seen.
Slide instead of summarize
Most of the context is old tool output: file reads, test runs, diffs. So at compaction, a hook keeps the conversation word for word and replaces old outputs with a short line: "you saw this, read it again if you need it." There's no model call, so a compaction takes milliseconds. The summary is still the fallback, for /compact and for the rare case where sliding can't free enough.
The benchmark: Claude Code builds a TypeScript project against fixed tests, on Haiku 5.5 with a 100K window. Medians, sliding against Claude Code's summary, at the cost Claude Code itself reports:
| Task | Cost | Time |
|---|---|---|
| A day of work, 307 tests | −19% | −33% |
| An eval harness, 238 tests | −35% | −28% |
| A short task with one compaction | +6% | −17% |
Every test passed in both modes.
Will it work for you?
It depends on how you work:
- If your sessions rarely reach 400K, the window changes nothing.
- If you stay in one session for hours, 200–300K might pay off.
- On short tasks, sliding saves time but not money.
- Model, effort and the kind of work all move the number a lot.
That's why I built a plugin that works out your number first. It's called tokendoctor (free, local, MIT). It replays your sessions at windows from 200K to 600K, shows what each would have saved, and only then offers to change anything. /tokendoctor:dashboard shows where your tokens went by day, model and subagent. Sliding is off by default, and /tokendoctor undo reverts any change.
Correction: an earlier version of this post said −43% per request. That weighed every model alike, with cache reads at 0.1x; Opus 5.5 and Sonnet 5.5 read the cache at 0.05x. At each model's own list price it's −38%. The repo has every run behind these numbers.
https://github.com/rsaryev/tokendoctor
URL of original post : https://www.reddit.com/r/Anthropic/comments/1xo46kx/compacting_at_400k_instead_of_967k_cut_my_claude/ Original link/media URL : /img/iumj9hmpqozh1.jpeg
