The annoyance
You spend the morning teaching Claude the frontend conventions. A path-scoped rule in .claude/rules/ does the job. Then the session compacts — automatically, or because you typed /compact — and the next edit ignores those conventions. You assume the model got sloppy.
It did not. The instruction left the window.
What Anthropic actually says
From the official context-window documentation, after compaction:
- Project-root CLAUDE.md and unscoped rules are re-injected from disk.
- Auto memory is re-injected from disk.
- Rules with
paths:frontmatter are lost until a matching file is read again. - Nested CLAUDE.md files in subdirectories are lost until a file in that subdirectory is read again.
The docs are blunt about why. Path-scoped rules and nested CLAUDE.md files load into message history when their trigger file is read, so compaction summarises them away with everything else.
The vendor named the behaviour. Most people still treat it as forgetfulness.
The placement rule
If an instruction must hold for the whole session, it cannot live on a paths: line.
# Wrong for anything that must survive compact
---
paths: src/api/**
---
Never return raw database errors to the client.
# Right: unscoped rule, or a short block in project-root CLAUDE.md
## API errors
Never return raw database errors to the client.Keep path-scoped rules for detail that is safe to rediscover — naming, local file layout, the things that reload the moment Claude opens a matching file. Put invariants in the root.
Re-inject the ones you still want scoped
If you want a rule to stay path-scoped and come back the instant compact runs, use the hook Anthropic already publishes. A SessionStart hook with matcher compact writes stdout back into the fresh window:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{
"type": "command",
"command": "echo 'Invariants: never return raw database errors. Tests before commit. Path rules in .claude/rules/ still apply — re-read a matching file before you edit.'"
}
]
}
]
}
}Swap the echo for cat .claude/reinject.md if you want the list in a file. Keep that file short. Pointers, not essays.
Why the placement works
“Don’t forget my rules” fails the same way “be concise” fails. It is a preference. The check that survives contact with compact is mechanical:
- Does this instruction live in project-root CLAUDE.md or an unscoped rule? It comes back.
- Does it live on a
paths:line or in a nested CLAUDE.md? It is gone until the next matching read. - Did you only say it in chat? It is in the summary, at best.
Test it on purpose. Mid-session, run /compact, then ask Claude to recite the rule you care about. If it cannot, the rule was living in the part of the window that does not survive.
Sources
From idea to operation
Make the next AI decision concrete.
NavAIgate helps leadership teams identify high-value AI opportunities, prove them safely and turn the winners into working systems.
