I left a Claude Code session for lunch and came back to “Compacted while idle, before the prompt cache expired.” The next reply put a query approach I had already dropped back on the table, and my three failing tests had become “a few.”
When Claude Code compacts, it replaces the conversation with a structured summary and reloads a few things from disk; everything else exists only if the summary wrote it down.
On 2.1.328, I gave 12 facts to a test session far smaller than that lunch one and compacted it five times. All 12 came through every time, and who said them made no difference. What blurred was precision: the exact line of a bug Claude had found.
So after a compaction, don’t retype the session. Check the exact values you act on and which files came back; both are in the session log on your disk.
On this page
- What /compact reloads from disk, and what rides on the summary
- Every fact came back, whoever said it; exact values blurred
- The five files that come back are the ones Claude touched last
- Before you compact: put exact values where the summary can’t blur them
- When Claude Code compacts without you
- After it compacts: check the first reply, then read the summary
What /compact reloads from disk, and what rides on the summary
This is the context-window docs’ list, cut to the rows that change what you do. Auto-compact, which fires when the window fills, works the same way as typing /compact.
| What | After compaction |
|---|---|
Project-root CLAUDE.md, .claude/rules/ files without paths: |
Re-injected from disk |
| Auto memory | Re-injected from disk |
| Plan written in plan mode | Re-injected from disk |
SessionStart hooks with the compact matcher |
Run again, output added |
CLAUDE.md in a subfolder, rules with paths: |
Summarized; reloaded when Claude touches a matching file |
| Chat, decisions, tool output, earlier hook output | Only what the summary keeps |
The last two rows hold nearly everything a working session builds: reasons, values, test results, the direction you settled on.
Some instruction files sit there too. A rule file with paths: frontmatter loads only when Claude works on a matching file, and so does a CLAUDE.md in a subfolder. In my runs a rule in billing/CLAUDE.md held only because the summary copied it; Claude Code never reloaded the file. A rule that has to hold belongs in the root file, as the memory docs advise.
Every fact came back, whoever said it; exact values blurred
Losing a reason after compaction feels like the summarizer favors what you typed over what Claude figured out on its own. So the 12 facts went in through four doors:
- things I typed
- things Claude found by reading files when I only asked
- test names and an error code from a test run
- two reversals, one I made with my reason and one Claude proposed that I accepted with “fine”

Data (CSV)CC BY 4.0
Why a fact Claude found survives as well as one you typed
The summary has its own sections for the files, code and errors Claude worked with, next to one for what you typed. So what Claude learned from its tools gets a place, not just your words.
The summarizer reads tool output, not just the chat: in one extra run, Claude’s reply said only that three tests failed, yet the summary listed all three names and the error code. A summary is a report on the whole transcript, and in sessions this size it had room for every fact.
The one thing that blurred: the line number
Claude had traced a refund that was off by a cent to legacy/money.py, rounding half-up at line 42. After most compactions, the file, the function and the cause were still in the summary, but the line was gone.
Asked for it, Claude either gave no line or said it couldn’t vouch for 42. The summary keeps a finding as a sentence about what and where; the exact coordinate is the detail it lets go.
My own losses came in real sessions far bigger than these tests, and they had the same shape. The three failing tests became a count. In a summer session, a cache layer I had rejected survived as “considered caching” without the reason, and the next reply proposed it again.
Nothing disappeared outright; each fact came back as a vaguer version of itself, which is harder to catch than a gap.
The five files that come back are the ones Claude touched last
Right after compaction, Claude Code re-reads up to five files, and the docs say it picks “the ones modified most recently”; a large file comes back as a path without its content.

Data (CSV)CC BY 4.0
In my first runs, Claude edited seven files and then read some large docs. The five that came back were those docs, as paths, and none of the edits. When the edits were the last thing Claude touched, they came back in full. So don’t assume your edits are in context; check.
Check which files came back in your session
Claude Code keeps one .jsonl file per session under ~/.claude/projects/, in a folder named after your working directory with every slash turned into a dash. A project in /home/me/my-app has its sessions in ~/.claude/projects/-home-me-my-app/, and the session you are in is the newest file there.
Each re-attached file is an attachment line just after the summary: "type":"file" came back with its text, "type":"compact_file_reference" as a path only. Run this right after a compaction, with your own folder name, and read the last lines it prints:
cd ~/.claude/projects/-home-me-my-app
grep -oE '"attachment":\{"type":"(file|compact_file_reference)","filename":"[^"]*"' "$(ls -t *.jsonl | head -1)" | tail -5
If your edited files aren’t in that list, paste git diff --stat into your first message after the compaction.
Before you compact: put exact values where the summary can’t blur them
A keep line, and what it can’t promise
You can add instructions to /compact, and the summary then keeps what you choose instead of what it guesses matters. Mine has been the same line since the summer:
/compact Keep abandoned directions with their reasons, every file path you edited, and the names of failing tests.
In my test sessions it changed nothing. Plain /compact already kept all 12 facts, and the line number slipped with the keep line too. Where it can matter is a long session the summary can’t hold whole, which is where I lost that rejected cache layer’s reason, so I still type it there.
A keep line steers what the summary covers; it doesn’t make the summary exact. A value that has to survive digit for digit goes on disk, in CLAUDE.md or in a comment next to the code it describes. One line per decision in CLAUDE.md has helped me more than any setting.
Fold a flipped session with /rewind first
This fall I had a side-repo session where the query approach changed twice. Before compacting, I opened /rewind, picked my message from the point where the decision was settled, and chose “Summarize from here.”
Everything before that point stayed word for word, so my reason for rejecting the first approach survived and Claude never proposed it again. The failing test names still blurred, and I had to type them again.
When Claude Code compacts without you
Idle compaction: when it fires and how to stop it
Idle compaction is what caught me at lunch. By default, in an interactive session whose context has reached 200,000 tokens (/context shows how full yours is), it fires about an hour after your last request, before the one-hour prompt cache runs out. Two settings control it:
| Setting | What it turns off |
|---|---|
"idleCompaction": false in settings.json, or the Idle compaction row in /config |
Idle compaction only |
"autoCompactEnabled": false |
Idle compaction and auto-compact; /compact still works by hand |
I leave it on, because without it the first message after the cache expires reprocesses the whole long context. What I change is the timing: before a break of 30 minutes or more with work half done, I run /compact with my keep line, so the summary waiting for me is one I timed and asked for.
Auto-compaction: let the disk carry it
For the auto-compactions you don’t time, what works without you is what reloads from disk: the root CLAUDE.md and a SessionStart hook with the compact matcher, whose output came back after every compaction in my runs. In .claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{ "type": "command", "command": "git log --oneline -5" }
]
}
]
}
}
After it compacts: check the first reply, then read the summary
The first reply after any compaction gets three checks from me:
- Does it bring back a dropped direction?
- Does it know which files were edited?
- Can it name the failing tests?
The runs add a fourth, the one that actually slipped: ask for an exact value you’re about to act on, such as a line number, and compare it with the file. When an answer comes back vague, paste git diff --stat and the test names and restate the reason in one sentence.
The summary itself is in the same session file, the newest .jsonl in your project folder. A compact_boundary line marks the cut:
{"type":"system","subtype":"compact_boundary","compact_metadata":{"trigger":"manual", ...}}
The next entry, flagged isCompactSummary: true, is the summary. Search it for the value you care about. If the summary only has the vague version, so does Claude.
Sources
- Research note on loopnotes-lab: both rounds of compaction runs, the summaries, per-fact results and figure data
- Explore the context window: What survives compaction, Claude Code Docs, checked 2026-11-20: survival table, five-file re-read rule, auto-compact and
/compactinstructions - How Claude remembers your project, Claude Code Docs, checked 2026-11-20: rules with and without
paths:, instructions lost after/compact - Settings reference: idleCompaction, Claude Code Docs, checked 2026-11-20: when idle compaction fires,
idleCompactionandautoCompactEnabled - Automate actions with hooks: Re-inject context after compaction, Claude Code Docs, checked 2026-11-20
- Checkpointing: Rewind and summarize, Claude Code Docs, checked 2026-11-20