skip to content

In a four-hour Claude Code session, Claude ignores a path-scoped rule and an early decision after auto-compaction — what survived, and what do you change?

level: seniorimportance: must knowfreq 15%

answer

  1. loaded from disk or from history
  2. root CLAUDE.md comes back
  3. rules return with matching files
  4. five files, skill token caps

basics

~20 s

Content loaded from disk comes back after compaction: project-root CLAUDE.md, unscoped rules, auto memory and the plan are re-injected. Path-scoped rules, nested CLAUDE.md and chat-only decisions are summarized away, so move what must persist into project-root CLAUDE.md.

solid answer

~50 s

Compaction replaces message history with a summary, so what survives depends on how each piece was loaded. The system prompt and output style still apply. Project-root CLAUDE.md, unscoped rules, auto memory and the plan from plan mode are re-injected from disk, and git status is read fresh. Rules with `paths:` frontmatter and nested CLAUDE.md files entered history when a matching file was read, so they are summarized away and return only when Claude reads such a file again. Claude Code re-reads up to five recently modified files, and a file over 5,000 tokens comes back as a path reference. Invoked skills return capped at 5,000 tokens each and 25,000 in total, oldest dropped first. An early chat decision survives only as summary text. So move durable decisions and must-hold rules into project-root CLAUDE.md or an unscoped rule, and compact with focus text at a natural break.

go deeper

for a junior

Recall that compaction summarizes the chat but reloads CLAUDE.md, so rules written there survive while instructions typed only in chat may not.

for a middle

Explain the disk-versus-history split: root CLAUDE.md, unscoped rules, auto memory and the plan return from disk, while path-scoped rules and nested files reload only with matching reads.

for a senior

Diagnose drift after compaction from the table: the five-file re-read and its 5,000-token cut, the 5,000 and 25,000 skill caps, and when to drop paths: or add a compact SessionStart hook.

for a principal

Decide what earns always-loaded status: moving rules out of path scope makes them survive but costs every request, so balance persistence against window cost and use enforcement layers for true requirements.

## The symptom A long Claude Code session runs well for hours, then after an automatic compaction Claude starts breaking conventions it followed all afternoon: it ignores the API style rule, or reopens an architecture choice you settled in the first hour. Nothing is broken. **Compaction replaced the message history with a summary**, and the pieces that disappeared were the ones that lived only in that history. ## The rule: disk versus history The single question to ask about any piece of context is **how it was loaded**. Content Claude Code reads from disk at startup lives outside the message history and is put back after compaction. Content that joined the conversation as a message is summarized with everything else. | Mechanism | After compaction | |---|---| | System prompt and output style | Both still apply | | Project-root CLAUDE.md and unscoped rules | Re-injected from disk | | Auto memory | Re-injected from disk | | The plan written in plan mode | Re-injected from disk | | Git status snapshot | A fresh one is read from the repository | | Rules with `paths:` frontmatter | Reload as Claude reads files they match | | Nested CLAUDE.md in subdirectories | Reload as Claude reads files in that subdirectory | | Files Claude read or edited | Up to five re-read, most recently modified first | | Invoked skill bodies | Re-injected, 5,000 tokens per skill and 25,000 total; oldest dropped first | | Background commands and background subagents | Keep running; Claude is reminded which are still running | | Context that hooks added earlier | Summarized with the rest of the conversation | | SessionStart hooks matching the `compact` source | Run again; their output is added | ## Reading the scenario against the table - **The path-scoped rule.** A `.claude/rules/` file with `paths:` loaded into history when Claude first read a matching file. Compaction summarized it away, and until Claude reads another matching file the rule is simply not in the window. - **The early decision.** It was a chat message. The summary keeps requests, key concepts, files, errors and pending work, but a constraint stated once, hours ago, can be paraphrased or dropped. - **Large files.** The five re-read files favour recent edits, and a file over 5,000 tokens returns as a path reference, shown as `Referenced file` rather than `Read`, so Claude must read it again to see the content. - **Long skills.** Re-injection keeps the start of each `SKILL.md`, up to 5,000 tokens. If the instruction Claude stopped following sits near the end, truncation removed it. - **Many skills.** The 25,000-token total is filled from the most recently invoked skill backwards, so a skill used once in the first hour can be dropped entirely after a busy afternoon. - **Hook output.** Text a hook injected earlier, such as a formatter's report, is now part of the summary rather than verbatim, so do not rely on it as a standing instruction. - **Background work.** A dev server or a background subagent started before the compaction keeps running, and Claude is reminded of it, so it does not start a duplicate. ## What to change 1. **Move durable decisions into project-root CLAUDE.md** or an unscoped file in `.claude/rules/`. Both are re-injected from disk on every compaction. 2. **Drop `paths:` from a rule that must hold all session**, or move it into the root CLAUDE.md. The trade-off is that it now costs context on every request. 3. **Add a "Compact Instructions" section** to CLAUDE.md so the summary keeps what your team cares about. 4. **Compact yourself at a natural break**, with focus text such as `/compact focus on the payment refactor decisions`, instead of letting the automatic pass fire mid-step. 5. **Put the most important instructions near the top of `SKILL.md`**, since truncation keeps the start. 6. For context that must come back every time, a `SessionStart` hook with a `compact` matcher can re-inject it; its stdout is added after compaction. Remember that all of this is **guidance, not enforcement**. CLAUDE.md being present after compaction makes Claude more likely to follow it; a hard requirement, such as never touching a directory, belongs in permission rules or hooks. ## A quick check After a compaction, run `/context` to confirm which CLAUDE.md and memory files are loaded, and ask Claude to restate the constraints it is working under. A missing one tells you which layer to move it into.

  • Why do Claude Code's path-scoped rules not come back immediately after compaction?
    They load into message history when Claude reads a file their `paths:` pattern matches, so compaction summarizes them away with the rest of the history. They reload the next time Claude reads a matching file. If a rule must hold across compaction, drop its `paths:` frontmatter or move it into the project-root CLAUDE.md.
  • Claude follows a long Claude Code skill until a compaction, then skips its final steps. Why?
    Invoked skills are re-attached after compaction with only the first 5,000 tokens of each, within a 25,000-token total that drops the oldest invocations first. A long `SKILL.md` loses its tail. Put the critical steps near the top, split detail into supporting files, or invoke the skill again.
  • After compaction, how does Claude Code restore a 12,000-token file Claude had been editing?
    It re-reads up to five recently modified files, but a file over 5,000 tokens comes back only as a path reference, shown as `Referenced file`, without its content. Claude has to read it again, ideally a specific range, before editing further.

Compaction is a shift handover. The next shift gets the handover notes, which is the summary, plus the binders on the shelf, which are CLAUDE.md and memory read from disk. A sticky note left on one machine, like a path-scoped rule, is seen again only when someone walks up to that machine.

  • Compaction wipes CLAUDE.md, so project instructions must be pasted in again
  • Path-scoped rules are re-injected right after compaction, like the root CLAUDE.md
  • Every file Claude read is re-read in full after compaction
  • Background commands are stopped when the conversation compacts
  • A rule in CLAUDE.md guarantees Claude obeys it after compaction
  • Invoked skills come back in full however long they are