Your Rules Expire at Compaction. Here's Exactly Which Ones.
When a long session compacts, some of your instructions come back from disk and some silently do not. The split is documented and almost nobody knows it — which is why Claude "forgets your rules" three hours in.
- #claude-code
- #context
- #claude-md
Everyone has had the long session where Claude quietly stops respecting a rule it was following an hour ago. The usual explanation is that the model "got tired" or the context "got noisy". Both are wrong, and the real reason is written down.
When context fills, Claude Code compacts — it replaces the conversation history with a structured summary. Your instructions then survive or die depending on how they were loaded. Not on how important they are.
The split
Re-injected from disk after compaction, so they persist:
- Project-root
CLAUDE.mdand unscoped rules - Auto memory
- System prompt and output style — these were never in message history, so they're untouched
Gone until something triggers them again:
- Rules with
paths:frontmatter — lost until a matching file is read again - Nested
CLAUDE.mdin subdirectories — lost until a file in that subdirectory is read again
That's the whole bug people keep hitting. Path-scoped rules and nested CLAUDE.md files enter the conversation as message history when their trigger file is read. Compaction summarises message history. So they get summarised away with everything else, and only come back when Claude happens to read a matching file again.
Your carefully scoped apps/api/CLAUDE.md was followed perfectly for two hours and then vanished — not because the rule was weak, but because it lives in the layer that compaction eats.
Skills have a budget, and it truncates from the bottom
Invoked skill bodies are re-injected after compaction — but under caps: 5,000 tokens per skill, 25,000 tokens total, and once the total budget is exceeded the oldest invoked skills are dropped first.
The detail that matters most: truncation keeps the start of the file. So the ordering inside your SKILL.md is not cosmetic. Put the instructions you cannot afford to lose near the top; anything at the bottom of a long skill is the first thing to disappear from a compacted session.
I'd treat 5,000 tokens as a hard design budget per skill rather than a limit you occasionally brush against. If a skill is bigger than that, it's really two skills.
Stop diagnosing this by feel
/context gives you a live breakdown by category, with optimisation suggestions and — usefully — which CLAUDE.md and auto-memory files actually loaded. That last part settles a surprising number of "is it even reading my rules?" arguments in about two seconds.
Run it when a session starts misbehaving, before you re-explain anything.
Three moves, in order of preference
- Compact deliberately, before it happens to you.
/compact focus on the auth bug fixkeeps what you chose; the automatic pass keeps what it guesses is important. Same mechanism, better summary — and it's free to run early. /clearbetween unrelated tasks. Old conversation doesn't just sit there; it crowds out the files you need next and costs tokens on every single message.- Delegate large reads to a subagent. The file contents land in its context window instead of yours, and only the summary comes back. This is the one that changes the shape of long sessions rather than just postponing the problem.
If you'd rather have a bigger window than a smaller conversation, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. Worth knowing that compaction works exactly the same way at the larger limit — a bigger window delays this, it doesn't remove it.
Do this today
Open your project and look for any CLAUDE.md in a subdirectory, or any rule file with paths: in its frontmatter. For each one, ask a single question: does this need to hold for the whole session, or only while I'm touching those files?
Anything in the first category is in the wrong place right now. Move it to the project-root CLAUDE.md — that's a two-minute edit that will save you an argument with your own tooling three hours into next week's session.
Sources
Keep reading
More guides like this one.
The Claude Code Commands You Skip Are All the Same Command
There are over 60 built-in slash commands. Most people use four. Sort the ones you are missing by what they actually do and a pattern appears — almost all of them exist to manage one resource, and it is the one quietly wrecking your long sessions.
Dynamic Workflows in Claude Code: 100 Agents, One Answer
Claude Code can now write its own orchestration plan and run hundreds of subagents in parallel. The parallelism is not the interesting part — the refute step is. Here's how to switch it on, when it pays, and the spec skill it quietly demands from you.
What Anthropic's Own Teams Do Differently in Claude Code
Anthropic published how its internal teams actually run Claude Code — and the loudest wins came from lawyers, marketers, and data scientists, not senior engineers. Here are the five habits worth stealing, with the real numbers behind each one.