r/ClaudeCode • u/vinishkapoor • 7d ago
Tips & Workflows “Autocompact is thrashing” in Claude Code: reproduced it on purpose and tested 4 fixes
If you’ve hit this one, it means a single file or tool output is too big for your context window. Claude Code compacts, the same big content fills the window again, and after 3 rounds it gives up. It’s a circuit breaker, not a crash.
We triggered it for real on v2.1.325, with a 30,000-line fake log and a small auto-compact window (--autocompact 100k, Haiku) to keep the test cheap. Asking Claude to read the whole file thrashed out after 1 minute and 3 seconds without ever answering.
What fixed it:
- Read less. A grep count answered the same question in 5 seconds (889 ERROR lines, which we checked).
- Focused /compact.
/compact keep only my question about counting ERROR linesdropped the Messages row from 36.4k to 9.2k tokens, right after auto-compact had given up. - Subagent. It read 1,500 lines in its own context and returned one number in 19 seconds.
- /clear. It took the Messages row back to 130 tokens.
These numbers are from one session with a forced 100k window. With the default window you need a much bigger file to hit this, but the fixes are the same.
The article also covers “Compaction failed · conversation could not be reduced below the context limit”. We couldn’t trigger that one safely, so that part is explained from the message and the docs.
https://aiparabellum.com/claude-code-autocompact-is-thrashing-compaction-failed-fix/
•
u/AutoModerator 7d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
4
u/Far_Reindeer8428 7d ago
compaction loops get worse the more the agent tries to keep. we cap the summary at the last two decisions and start clean
1
u/omerkaptan 7d ago
Great breakdown! Using subagents for large file analysis seems like the smartest approach.
1
u/FitDonkey6704 7d ago
it means a single file or tool output is too big" is doing a lot of work there, mine was the instruction files getting re-injected after each compact, no big file involved.
1
u/No-Advisor-4882 7d ago
Useful test, thanks. What reduced it most for me: keep the always-loaded context small (lean CLAUDE.md, no huge tool outputs pasted back), and split long jobs so a session has one goal. When a session has to run long, I ask it to write its own short state file (what's done, what's next) so a compact or a fresh session can resume from that instead of re-reading everything.
1
u/m-ritter 7d ago
The instruction-file re-injection detail is the key variable here. I’d make a tiny regression case that runs the same explicit requirement through a couple of compact cycles and checks the outcome, not just token counts; that shows whether the fresh summary preserved the task. That’s the spec-based check loop I built QualityLayer for: https://github.com/maxritter/qualitylayer
0
u/Ragy-ragy 7d ago
Typical behavior with small autocompaction threshold. No matter the harness