r/ClaudeCode • • 7d ago

Tips & Workflows “Autocompact is thrashing” in Claude Code: reproduced it on purpose and tested 4 fixes

Post image

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 lines dropped 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/

0 Upvotes

15 comments sorted by

•

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/DopBopDeeBeep 7d ago

This is a good way to do it. If you need more context than the last two decisions you can always use something like Context Carwash to help retain specific context for the next chat.

1

u/Far_Reindeer8428 7d ago

context carwash is new to me, does it pick the parts to keep or do you mark them before compaction?

1

u/DopBopDeeBeep 7d ago

It adds a command called /wash and you can be like '/wash make sure to save details related to the cause we identified for the bug' and it writes a handoff brief that summarizes the convo and ensures any detail you want is saved.

1

u/Far_Reindeer8428 7d ago

so it is a manual save point, that beats guessing what the summarizer will keep. thanks, will try it on the next long run

1

u/DopBopDeeBeep 7d ago

exactly. never tried it with agents though so not certain how it would work there but guessing you could have it run wash at a certain context size instead of waiting for auto compaction

1

u/Far_Reindeer8428 7d ago

a size trigger is what we would need, auto compaction always fires at a bad moment. let me know if it works headless

1

u/DopBopDeeBeep 7d ago

I'm not certain but it's open source so you could branch it and have claude make that possible

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/vincent_sch 1d ago

If some of those rules are only for the frontend, you could move them to .claude/rules/ with paths:. Then Claude only loads the rules when it works on a file that matches. If the root CLAUDE.md still has an @ import for that rule, Claude reads it again after a compact.

There's a bit about instruction files in my post on compaction loops.

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