← Claude Code Hub
Jun 5, 2026 · 5 min read ✦ Tip #092

/compact in Claude Code: the instructions that vanish without warning (and how to make them survive)

Claude Code compacts on its own as you near the limit, and sometimes a rule quietly stops applying mid-task. Not everything comes back the same from a compaction: here's what's kept and what isn't.

What survives a compaction in Claude Code and what is lost until a file is read again

TL;DR When a session nears the limit, Claude Code compacts on its own, without you typing anything, and summarizes the conversation. But not everything comes back the same: the system prompt, your project-root CLAUDE.md, and auto memory get re-injected from disk; your paths: rules, nested CLAUDE.md, and skill bodies get lost or trimmed. That's why Claude sometimes "forgets" a rule mid-task. Golden rule: anything that must survive belongs in the root CLAUDE.md or at the top of your SKILL.md.

The unsettling part isn't the /compact you run yourself. It's the automatic one: as context nears the limit, Claude Code compacts on its own, mid-task, without you touching anything. And a rule that was governing your edits can quietly stop applying right there.

That limit isn't fixed either, and you don't always decide it: four places can set the auto-compact window and one of them beats the rest without a word. And if instead of compacting you get "Prompt is too long", the end of the message tells you whether /compact can fix it.

How compaction works

Compaction replaces the conversation history with a structured summary. What comes back afterward depends on how each instruction was loaded:

  • Whatever lives outside the history (system prompt, output style) stays intact.
  • Whatever is re-read from disk at startup (root CLAUDE.md, unscoped rules, auto memory) gets re-injected.
  • Whatever entered as a message in the history (paths: rules, nested CLAUDE.md, skill bodies) gets summarized with everything else and only comes back when it's triggered again.

Manual /compact and the automatic pass work the same way. The difference is that you don't choose the automatic one.

What it looks like

# Before: the paths: rule governs your edits
[Loaded .claude/rules/api-conventions.md]   ← applies to src/api/**

# Claude compacts on its own near the limit
⏺ Conversation compacted

# After: the same edit, without that rule
# (it comes back as soon as Claude re-reads a file in src/api/)

What survives and what doesn't

Mechanism After compaction
System prompt and output style Intact (not part of history)
Root CLAUDE.md and unscoped rules Re-injected from disk
Auto memory (MEMORY.md) Re-injected from disk
The plan from plan mode Re-injected from disk
Task list (Ctrl+T) Survives, when your model still saves it
Rules with paths: frontmatter Lost until you read a matching file again
Nested CLAUDE.md in subdirectories Lost until you re-read a file in that folder
Invoked skill bodies Re-injected, but capped at 5,000 tokens per skill and 25,000 total; oldest dropped first
Hooks Not applicable (they run as code, not context)

"Lost" isn't "erased forever": the paths: rules and nested CLAUDE.md come back on their own the moment Claude reads a matching file again. An @ to a file in that folder brings them back too, because every mention re-attaches the file and the CLAUDE.md from its tree, though you pay for the whole thing again. The problem is the window in between, where Claude works without them and never tells you.

If you at least want to know how many times it compacted itself this session, the Prompt cache (main) line in /cost counts those separately, as expected rebuild: it keeps them apart from the cache misses you cause yourself, precisely because you never asked for these.

How to make them survive

1. Rules that can never be missing

If a rule must apply no matter what, don't leave it riding on a paths:. Drop the scope frontmatter or move it to the root CLAUDE.md, which always gets re-injected.

2. Critical instructions at the top of SKILL.md

When a skill is re-injected, truncation keeps the start of the file and drops the end. Put what really matters (the hard rules, the gotchas) in the first lines of SKILL.md, not the last.

3. Compact yourself, with focus, before a long task

Instead of waiting for the auto-compact to fire mid-task, run it yourself at a natural break and tell it what to keep. The break that pays off most is stepping away from your desk: compacting before you leave costs a tenth of compacting when you get back, because the summary is paid for by reading the whole conversation, and that read comes from cache only while the cache is still alive. Habit 3 of how to save tokens covers /compact with instructions. And if you want to compress only the exploratory start and leave the recent work intact, Summarize up to here does it targeted from the Rewind menu, without summarizing the whole session.

This is the flip side of prompt caching: there /compact barely costs you in spend; here the cost is fidelity, what it takes out of your instructions. And to understand what loads at startup (before any compaction), see when Claude Code loads each feature. And if what you notice is Claude performing worse the longer your session runs, that's the context hygiene that keeps your window from filling.

Official docs: Explore the context window

Found this useful? See more of wmedia.es in your Google results.

Add wmedia.es as a preferred source on Google
FREE GUIDE

You don't need Opus every time.

Model and effort are two settings, not one. 8 pages with the settings that actually move your bill, a three-question diagnostic for when something fails, and the price ladder.

  • 1. What "better" means capability, time and money
  • 2. Model who you send
  • 3. Effort how much rope you give
  • 4. Diagnostic three questions when something fails
  • 5. The bill where it comes from
Are you a professional Web developer?

You'll receive the guide by email · Unsubscribe anytime

of 8
#

Wmedia · 8 pages
FREE GUIDE · 8 pages · 2 dials

You don't need Opus every time.

Model and effort are two settings, not one. 8 pages with the settings that actually move your bill, a three-question diagnostic for when something fails, and the price ladder.

Are you a professional Web developer? · Unsubscribe anytime

Using Opus for everything? See when you don't need it.