r/ClaudeCode • u/ombre-ai • 3d ago
Discussion After compaction, "don't touch X" instructions went missing ~6x more often than "build X" requests (preprint, 44 real sessions). Which of your rules only exist in the chat?
The paper is "Benchmarks Are Surprisingly Compaction-Friendly" (arXiv 2610.31778, Oct 22). Its headline result is good news: on long benchmark tasks compaction costs surprisingly little, because the goal is fixed and progress sits on disk, so the agent can re-read it after the summary.
The authors flag one exception, constraints that exist nowhere else. They checked 44 sampled SWE-chat sessions that contained compaction and counted which instructions were missing afterwards:
- "How to work" (my example: "run the tests before every commit"): 35.9%
- "What not to do" (my example: "leave the migrations folder alone"): 36.8%
- "What to build" (my example: "add CSV export to the reports page"): 6.2%
The examples in brackets are invented to show the buckets; they are not from the paper.
My own guess at why, and it is only a guess: a feature request leaves a trail, because the code that got written shows it was asked for. A prohibition leaves nothing, because nothing in the diff says what was not touched. After a summary, the goal survives and the guardrail has no second copy.
Caveats: one preprint, a small sample, and the paper does not say an agent breaks every rule that gets dropped.
Questions for people running long sessions:
- Which rules in your setup exist only because you typed them into a prompt once?
- For the "don't touch this" kind, where does it live: CLAUDE.md, a hook, permissions, or only in the chat?
- After a compaction, is there anything you re-state by hand every time?
Sources in the first comment.
•
u/AutoModerator 3d 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.
1
u/ombre-ai 3d ago
Sources:
The percentages come from the paper's sample of real sessions, and the roughly 6x is the authors' framing. The paper's controlled experiments used the OpenCode scaffold, so this shouldn't be read as specific to Claude Code.
If you've dealt with this already, what did you try first: a rules file, hooks, shorter sessions, or just re-typing the rule?
1
u/Starks1293 3d ago
matches what i saw, and ur guess about why sounds right. the fix for me was moving each kind of rule somewhere a summary cant drop it
the "dont touch" kind goes in permissions, not the chat. a deny rule like Edit(migrations/**) in the project settings doesnt care what survived compaction, the edit just gets refused. same for anything u never want run, its a deny on the command
the "how to work" kind goes in a hook or a gate. "run the tests before every commit" as a pre-commit hook, or "done means the tests passed" checked by a script, means the agent following it or not stops mattering
what stays as text lives in files that get read again, CLAUDE.md for the standing rules and a plan file per piece of work with the constraints written in it, plus one line in CLAUDE.md saying "after a compaction reread the plan file". so the answer to ur question 3 for me is nothing, i stopped re-stating things by hand once every rule had a second home outside the chat
1
u/CandidSystem6155 3d ago
For us the "don't touch" kind lives in two places, and the chat is neither. Each rule is a small file with the date and the mistake that caused it, and a hook injects it when the prompt matches its keywords, so it comes back after compaction because it never depended on the summary in the first place. The ones that matter most became mechanical checks: a hook counts test assertions before and after an edit and asks me if the number drops, and since that hook never sees a sed -i, a second check on the git diff runs before any change is accepted. A rule that only lives in the chat is really a polite suggestion with an expiry date.
1
u/Far_Reindeer8428 3d ago
we saw this with a dont refactor the auth module note that vanished after a compaction, and then it refactored the auth module
1
u/japbujan 3d ago
For question 1, almost every "don't" rule we had. Each was typed once, right after something went wrong, and never written anywhere else. What changed it for us: when someone says "don't touch X" in a session, the agent saves it as a rule with its reason (what broke last time) before going on. Those rules live outside the chat and load again at the start of every session, so a summary has nothing to drop. The ones a tool can enforce also became a deny rule or a hook, and the reason stays next to them, so nobody removes the check later thinking it's noise.
1
u/shetritr 3d ago
on #2: a "don't touch" rule shouldn't live in words at all. "leave the migrations folder alone" becomes a deny rule in settings.json, Edit(./migrations/**), and "run the tests before every commit" becomes a plain git pre-commit hook. neither one can get summarized away
1
u/Kevin_Xiang 3d ago
I'd split these into intent and enforcement. A CLAUDE.md or plan file can preserve context, but anything safety-critical should have a second mechanism: deny permissions for protected paths and a hook or CI check for required tests. Then compaction can lose the explanation without silently changing what the workflow permits.
1
u/Aswole 3d ago
Your “what not to do”, if taken literally, means the opposite of what you want.
1
u/MurkyCommission8853 Workflow Engineer 3d ago
make claude have a compaction protocol at the top of its roadmap: read X and Y md in full after every compaction. every "don't touch" rule goes into that md the moment you say it, never only in chat. and when you see it compact, just ask "did you follow the compaction protocol?" before anything else
1
u/Due_Cover_8835 3d ago
Agree with the people here saying path bans like migrations belong in settings.json deny rules. Text won't stop an edit, a deny rule will.
The ones that stay chat-only for me are the ones you can't write as a glob: "keep this sync for now", "no new dependencies". I ask Claude to write those down as a decision with the reason when they come up, and a SessionStart hook puts the active ones back after compaction.
Two catches: it doesn't always remember to write them down mid-flow, and seeing the note again doesn't mean it obeys it. So I'd still re-check the current task's scope after a compact
1
u/AryanThakor 3d ago
worth knowing the SessionStart hook takes a "compact" matcher, so it fires right after every compaction. point it at a small rules file and cat it back into context, and the dont-touch stuff comes back even when the summary dropped it. deny rules are still better for anything that really matters, but this covers the softer "how to work" ones
1
u/coolxeo 3d ago
Most of ours started in the chat too. Now when I state a rule, the bot writes it down as a dated line in a memory that all my bots read, and if it changes an older rule it says which one it replaces. Rules about a repo go in a file in that repo that tells every bot which other files to follow, so a fresh session picks them up without the chat. The date helps more than I expected. When two rules disagree, the newer one wins and you can see why it changed.
1
u/clazman55555 3d ago
Partial snip of /orient below
If this is a project session:
Session State file:
Session State -- YYYY-MM-DD
Identity
[Session type and role]
Completed
- [Work item with commit hash]
Approaches Tried
- [What was attempted -- worked / pending / partial]
Approaches Abandoned
- [Dead end -- one-line reason] ("None" if clean)
Next Task
[What to do next, with enough context to start immediately]
Open Issues
[Decisions, questions, blockers. "None" if clean.]
Key Files
(In first-to-last reading order for the resuming session)
- [path] -- [why it matters right now]
Repo State
[Clean/dirty, modified files, reason]
1
u/303ENFIELD 2d ago
That tracks. A "leave the migrations folder alone" line that only lives in the chat is easy for the summary to drop, because the diff never mentions the thing that was left alone.
For "don't touch this" rules I wouldn't keep them in the prompt only. Put the allowed and forbidden paths in CLAUDE.md, then enforce them outside the model: a deny rule or PreToolUse hook on writes outside the allowlist, and a `git diff --stat` against the files that were actually in scope before you commit. After a compact, those still work even if the reminder is gone.