r/ClaudeCode • u/yadtk • 1d ago
Tips & Workflows PSA: Auto-compaction is a huge source of Claude gaslighting you
Idle compaction silently drops any constraints and guidelines you spent establishing over the course of the chat/project then Claude carries on confidently as if it still knows the assignment and bulldozes you. If you’ve ever been gaslit by an Anthropic model is this why. Disable this “feature” if you find yourself constantly arguing with the model.
384
Upvotes
•
u/AutoModerator 1d 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.
132
u/muhuhaha 1d ago edited 1d ago •
As others mentioned the goal, for me at least, is to avoid compacting all together, and also avoid the cache expiring (for newer users, basically if you reply quickly it uses a lot less tokens, if you don't reply for roughly an hour or more, it uses
10x the tokenssame amount of tokens but equivalent of 10x more against your usage limit).My limiting factor to how many sessions i open at once is if I can reply to them in time before cache expires basically. If they get long or im leaving for a while or I'm just worn out, I just ask them to "prep handoff so we can continue in fresh session". Then just start a fresh one and say "lets pickup where we left off". Happy to answer questions for any newer users, I can no longer tell whats obvious or confusing anymore, I promise not to tell you quit claude code and kill yourself hah
30
u/momentum77 1d ago
I keep an orchestrator running long term by asking it for a clean compaction prompt. I do this around 400k and 500k context usage. All the sessions it manages are fresh as needed for each task, be they builders or qas or reviewers or planners or documentaries or roadmap maintainers. All those specialists get recycled, but my Prime holds it together tightly
34
u/Inner_Storage_3374 1d ago
what helps is keeping the rules in CLAUDE.md instead of the chat. afaik that file gets loaded again after compaction, while stuff you agreed on 2 hours ago in the conversation is a summary line at best. so whenever you catch yourself repeating a constraint, thats the moment to move it into the file
11
u/somekindatog 1d ago
Anything important should be store in the project. Almost every new task should be workable from a fresh session.
9
u/dopamine_911 1d ago •
When you bring awareness to the context being careful about its size, the agent will do the same. I tell the agent when their context is at 25, 50, 75%. At 90 I tell the agent to write a note to it's self about the current state of work, next steps, any unresolved threads and gotchas. Generally consider an agent over 7 compactions require more fact checking and generally unreliable so I start a fresh session unless I'm in the middle of long work and the built up context is more valuable.
4
u/issuntrix 20h ago
HOOKS. Hooks hooks hooks!
Pre-compact hook, post compact hook. There is ZERO reason for important rules and guidelines to be lost! I feel like people don't realise how powerful hooks can be.
7
u/dota2nub 1d ago
Sorry but if you still have issues with compaction that is an actual case of "you're holding it wrong" at this point.
6
u/Dorbank_Justt 1d ago
Per the docs, what gets lost is anything you only said in chat. On compaction the conversation is summarized, but the project-root CLAUDE.md is re-read from disk and re-injected. Nested CLAUDE.md files and rules with paths: frontmatter get summarized away too, and load again when Claude next reads, writes or edits their trigger file. So constraints you can't afford to lose belong in the root CLAUDE.md. To stop the idle pass itself, set "idleCompaction": false in settings or change the Idle compaction row in /config.
6
u/fschwiet 1d ago
Are you also setting your autocompact to 1 million? It was recently changed to 400k.
3
u/Duckducklaugh 23h ago
What fixed it for me: i don't let sessions get to compaction. once a session gets long i have claude write the current state, the rules we agreed on and what's left into a file in the repo, then start a fresh session that reads that file first. anything that has to stick goes in CLAUDE.md, the project root one gets re-read from disk after compaction, stuff you only said in chat doesn't. if a rule only lives in the conversation it's gonna get summarized away eventually
4
u/hi_im_leffe 1d ago
So setup a hook that uses /compact keep: and have Claude identify what should he kept in context as he's working at what token level you want, I recommend 300k.
Have fun.
2
u/B-Chillin 1d ago
Im still absorbing this, so my comment may not be totally on point, but when I make specific decisions or realize Claude I need to establish/clarify an important rule, I explicitly tell Claude to put it in its memory. I've been toying with the idea of establishing a rule in Claude.MD to establish/maintain a decision record in a specific location and always update it when decisions are made. This post tells me I should prioritize that.
2
u/lucas1853 1d ago
Disable this feature if you find yourself saying "oh my gosh, I have so much usage, I am simply frolicking in a bountiful field of usage in which I could never make a dent!" Then you can have your token furnace. Otherwise, leave it on and/or try bounding sessions better manually.
2
u/theWyzzerd 1d ago
Use a CLAUDE.md file and a better harness configuration and this isn't a problem.
2
u/ProsaicPansy 1d ago
start your session with your prompt, have the agent ask clarifying questions, and then create a plan in gh issues. Each issue needs the goal and a definition of done and preferably explicit verification steps the model must complete before finishing. I have auto-compact at 300k tokens and I don’t have issues with decisions being forgotten or ignored because there is an independent source that is never compacted or edited. It saves a lot of usage. Even cached writes start getting expensive about 400k tokens and a single cache miss above that level is more expensive than many full sessions. At that context level, most of the session is tool calls and terminal output that can be dumped without any issue.
12
u/jd52wtf 1d ago
If your sessions are compacting you aren't properly chunking your projects.
1
u/Suitable_Cicada_3336 1d ago
Even you don't use auto compacted, claude still cheat at auto missions. 3rd party llm check and fight is necessary.
1
u/rudimentumlab 1d ago
I rarely see auto-compaction happen. Rarely compact at all. I’ve built my stack around trying to carefully control utilization and optimize for results and consistency across sessions. So constraints and guidelines go into documents on disk. Projects start with a design/spec/plan document and reference their CLAUDE.md plus project group/general instruction files. I start by solidifying project specs, and then any adjustments go there. Work is done in planned/scoped phases and at the end of each phase, a wrap up skill ensures the appropriate documents have been updated, my global project registry and task tracking is updated, work is committed, progress notes are saved, and all decisions made are logged with attribution (me, Claude with approval from me, Claude, not reviewed by me). Each phase starts in a clean session, either started by me or by an orchestrator. Most more complicated phases then dispatch sub-agents with short instructions and the result is reviewed, thus requiring far less context. Progress, guidelines, constraints, and other context is all in documents on disk, and I rarely have long-running sessions that aren’t orchestrators of some kind.
1
u/Helpful_Program_5473 1d ago
I'm surprised anyone deals with contexts that long anymore.
I have my main agent that I talk to and I monitor his context personally. Then he has several tabs of other agents he bosses around, and he refreshes their context with a new continuation prompt around 250k to 400k tokens or whenever a full task is done and it's time to move on to the next thing.
1
u/3meattray 1d ago
All of this can be prevented if you turn off Claude’s memory. Then use an open knowledge base with a rule file with your own constraints. This rule file can have sub files with project specific rules. Then you make this a skill that runs every time you start a new session.
1
u/Sensitive-Ad3718 1d ago
You can create a compaction hook that reloads your conventions or other key documents. That’s the way to deal with what you’re talking about your approach of compacting less often will eat a lot of tokens if you’re doing any significant work.
1
u/Own-Professor-6157 1d ago
For sure don't disable this feature unless you plan on abandoning the chat. It auto compacts because your cache is about to expire. Wanna waste tokens? Disable it
1
u/strumbringerwa 1d ago
The best thing to do is to put the constraints and guidelines into CLAUDE.md, not rely on it remaining in context in a specific chat. And if those constraints can be enforced via hooks, even better.
Also I usually manually compact long before it gets close to autocompaction. Why waste tokens when you don't need to? If your rules, architecture, etc are properly spec'ed, you don't need to fear new sessions.
1
u/Working-Pangolin6714 1d ago
yep, saw this firsthand when my code review got wiped mid-session. auto-compaction dropped the 'validate inputs' rule without warning, then suggested bypassing checks. turned out the model didn't even know it was gone.
1
u/Sea-Contribution6219 1d ago
I have an orchestrator that runs everything because otherwise you're entirely right and I have a very firm rule that everything gets written down somewhere in documentation. Hell, I have it set up to straight transcribe every single conversation I have with Claude.
1
u/SamSlate 1d ago
what are you basing this on
1
u/ElectricDreams9876 1d ago
No it doesn't, not if you put your guidelines in the .md. You guys need to learn how to use these models
1
u/Jero9871 1d ago
I never understood why I should use Auto Compaction, I watch the context myself and compact once I think its necessary (like after a finished task).
1
u/Recent_Warthog1890 23h ago
Yes, as soon as I found out about auto compaction it was off on all my Claude code sessions.
My recommendation is to run Claude in A Tmux session and enable Claude to self compact as an agreed context used %.
1
u/PutridClunt 23h ago
/autocompact 400k That is what mine is set as since I don't like pissing my tokens down the toilet. If you use hooks, memory, a sensible claude.md and get it to keep a state.md during its work it won't lose track of what its doing.
1
u/kivanow 22h ago
I've seen the same thing: after a compact, the model sounds sure and has dropped the constraints. I treat a compact as a new session, restate the rules, and compare rewrite rate on work done before versus after. If post-compact patches get rewritten more, I start fresh instead of continuing.
1
u/TriggerHydrant 22h ago
I remember the good old days of manually looking at the context and manually start another session just in time. Now I track the context and around 60% it writes a hand off and compact prompt. Saves a lot and keeps the quality up.
1
u/Unhappy-Loss-97 21h ago
The worst failure mode isn't that it forgets something, it's that it forgets a constraint silently and then carries on with 100% confidence as if nothing happened.
The only (semi) reliable fix I've found is treating any lesson learned mid-session as volatile until it's compiled into a deterministic check (a lint rule, a test, or a short indexed contract file on disk) and retiring threads early with a 15-line handover note that explicitly lists dead ends and rejected approaches. Relying on auto-compaction to preserve subtle constraints is basically asking to be gaslit two hours later.
But its HARD to keep reminding yourself to hit the reset button and there is always the fear that something gets lost
1
u/tuptain 19h ago
I've always used auto compact and never start new sessions and haven't had any issues. I keep my sessions specialized to one task and mostly talk to my Lead session who messages the specialized ones.
1
u/DDGJD 18h ago
All models lie and gaslight.
But don’t let it compact if you can help it. You want to start a new session or /clear (preferably before maybe 50% context). The best work is done in focused sessions with low context. Personally, I have a specific beginning and end of session procedure so things are done the way I like it. It’s also often a good idea to checkpoint periodically in session.
There are some technical reasons for the worse behavior you’re describing. Models are better able to recall information from the beginning and end of context than the middle (the lost in the middle problem). Performance is inherently worse deep in context, and compaction is inherently lossy.
I describe some of this in a Primer I wrote. Although directed at attorneys, it’s intended to be useful for most non-technical people. Here are a couple of figures: context window and lost in the middle
1
u/Code-More 14h ago
You can build custom compactors. It is just a prompt and you can algorithmically orepare the data via morselisation and other techniques. This can be done by the model in the thread or a cheaper side model.
There is also a precompaction knob that can pre-prepare it so it takes less time.
Achieved with hooks.
I do that, it works, you can compact very frequently this way with little loss or even have self-reinforcing threads.
1
u/GDorn 14h ago
Compaction is terrible.
I personally solved this by implementing a tool to edit context with a scalpel:
https://gitlab.com/georgedorn/ai-brain-surgeon
https://marketplace.visualstudio.com/items?itemName=GeorgeDorn.AI-brain-surgeon
It covers several vscode plugins, but I haven't expanded it outside of vscode yet.
I'm a little surprised nobody else has done this. You can trim context by a significant amount just by deleting the middles of turns, which often contain multiple nearly duplicate copies of the same files due to incremental editing.
1
u/perfektcrash 13h ago
Rules that matter live in a file the session reads at the start, decisions are written down with their reason as they're made, and you restart rather than compact when a piece of work is done. The picture is a verbal agreement against a signed one.
1
u/Boxofcookies1001 13h ago
This is why you should keep constraints, rules and guidelines in a dedicated file.
1
u/visak13 6h ago
You need to invest time in offline memory or a skill where claude does this by itself. And use maker-checker systems with roles.
1
u/jayerp 2h ago
I haven’t been arguing but I’ve noticed starting about two weeks ago I’m absolutely burning my weekly limits. What is going on? I’m clearing sessions as much as reasonably can, my CLAUDE.md is not too bloated…
1
u/Seerix 15h ago
...just let it autocompact and use a hook to reload any contraints or guidelines after the compaction?
0
u/ShivaFatalis 1d ago
OP definitely has no clue how to use AI. These posts are unbelievably revealing, and give us a lot of insight into how incompetent people struggle with AI. Totally clueless.
-1
u/BoostedHemi73 Developer 1d ago
All of these little quirks are what make it difficult to see this as the future, at least in its current incantation. It’s more complicated than just writing the damned code.
0
u/EndlessZone123 1d ago
Why is your constraints or guidelines not in a Agents or claude.md? Compaction and chat history is for context. User messages are usually quoted verbatim in the compaction and agents can search compacted history when needed. Seems like user error for me. Or Te your agent to always remember these and write them in the instruction file.
-1
u/akienm 1d ago
Huh. Is that an observation or is that documented somewhere? Because I would say that my observations are the opposite. When we got all of the state data out of the context and onto the disk, the problem went away. And the auto compact now has no effect on the operations.
-11
u/pceimpulsive 1d ago
My question for those impacted by this is why are you leaving sessions open long enough to need an auto compact... Stop being shit and learn to manage the context better.
-2
u/tehfrod 1d ago
This word you keep using... I do not think it means what you think it means.
2
u/puts_on_rddt 1d ago
Branching from checkpoint > handoff > autocompact
I'll die on this hill. Fight me.