/compact loses context: what compaction keeps, what it drops, and how to get the detail back

Published · Updated · Checked against Claude Code 2.1.319

You tell Claude not to touch the billing module, work for another hour, hit a compaction, and it starts editing the billing module. That is the symptom. Compaction replaces the conversation with a summary, so anything the summary leaves out is gone from what Claude can see. The exact words are not gone from disk, because the transcript file still holds the pre-compaction messages.

What compaction does

When the context window fills, Claude Code compacts automatically, and you can trigger it yourself with /compact. Per the how Claude Code works page, the conversation becomes a summary that keeps your requests and key code snippets, but "detailed instructions from early in the conversation may be lost."

The summary is written by the model, so it is lossy in ways you cannot predict. Reports go back a long way. In issue 868, a user on CLI 0.2.80 (April 2025) saw Claude lose track of its task after an automatic compact and start unrelated edits; a maintainer replied in June 2025 that compact and auto-compact had improved, and closed it. In issue 8962 (October 2025, Claude Code 2.0.8) users reported the latest response vanishing after compaction. A stale-issue bot closed that one with no maintainer reply on the thread.

What survives

The context window page has a table, which in short says this:

ContentAfter compaction
System prompt, output styleStill apply
Project-root CLAUDE.md, unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
Files Claude read or editedUp to five re-read, most recently modified first; a file over 5,000 tokens comes back as a path reference only
Invoked skill bodiesRe-injected, capped at 5,000 tokens each and 25,000 total
Rules with paths: frontmatter, nested CLAUDE.mdReloaded on demand, not carried by the summary
Background commands and subagentsKeep running
Everything you said, every tool result, every decisionOnly what the summary kept

The last row is the painful one. "We decided on option B because of the migration" lives only in the conversation, and if the summary drops it, Claude no longer knows it. The docs add that path-scoped rules and nested CLAUDE.md files are loaded into message history, so compaction summarizes them away; a rule that must survive belongs in the project-root CLAUDE.md.

Steering the summary

Three levers are documented. Standing rules go in CLAUDE.md rather than chat, because it is re-injected from disk after every compaction. You can also add a "Compact Instructions" section to CLAUDE.md, or run /compact with a focus, as the docs describe:

/compact focus on the API changes and the open decision about retries

The third is a SessionStart hook whose matcher is compact. The context window page says Claude Code runs those hooks after compaction and adds their output to the compacted context; see re-inject context after compaction.

A manual habit does the same job for free. Before a long task, have Claude write the decisions so far to a file in the repo, and tell it to read that file after compaction.

Reading the transcript before the boundary

Every session is a JSONL file at ~/.claude/projects/<project>/<session-id>.jsonl; where Claude Code stores sessions has the layout.

In one session that had compacted once (Claude Code 2.1.319), a system entry with subtype compact_boundary sat at line 269 of 455, and the 268 lines before it were the original messages. The boundary entry also carries a compactMetadata object with trigger, preTokens and postTokens. Those names were observed, not something documented, and the docs say the entry format is internal and changes between versions. Treat the commands below as a convenience.

This finds the boundary and prints the prompts you typed before it:

f=~/.claude/projects/-Users-me-myapp/<session-id>.jsonl
grep -n '"compact_boundary"' "$f" | cut -d: -f1
n=$(grep -n '"compact_boundary"' "$f" | head -1 | cut -d: -f1)
head -n $((n-1)) "$f" | jq -r 'select(.type=="user") | .message.content | strings' | less

The strings filter keeps plain-text user messages and skips tool results. For what Claude said and ran, list assistant text and tool calls:

head -n $((n-1)) "$f" | jq -r '
  select(.type=="assistant") | .message.content[]? |
  if .type=="text" then .text
  elif .type=="tool_use" then "TOOL \(.name): \(.input|tostring|.[0:200])"
  else empty end'

Once you find the lost decision, paste it into the chat, or into CLAUDE.md if it is a standing rule. You can also give Claude the transcript path and ask it to read the part before the boundary. That is the only route, since a resumed session does not reload what a compaction summarized; the sessions page says those messages "aren't loaded again".

The route has a time limit. Claude Code deletes transcripts older than cleanupPeriodDays, 30 days by default, per the claude-directory page; see Claude Code silently deletes transcripts after 30 days. Sealkeep can extend it. It seals a copy of each session's raw bytes, so the pre-compaction messages outlive the sweep and a deleted or moved file; sealkeep search <query> --content searches inside sealed sessions (run sealkeep index build first), sealkeep mcp install lets Claude Code search the vault itself, and sealkeep recover <id> <dest> restores a file. It does not change what compaction does, cannot push the missing detail back into the live window, and does not summarize or decide what matters. sealkeep fork can start a fresh session from a small pack instead of a long history, which is a different trade from compaction.

Searching one session by hand is fine; for many, see how to search your past Claude Code conversations.

FAQ

Does /compact delete my conversation?

Not from disk. In the session inspected, the messages before the compaction boundary were still in the JSONL file. Claude cannot see them any more unless you show it, and only the retention sweep removes them.

Does auto-compact behave differently from /compact?

The context window page says the automatic pass works the same way. With /compact you can supply a focus.

Why does Claude forget my CLAUDE.md rules after compaction?

Project-root CLAUDE.md is re-injected from disk, so it should not. Rules that arrived another way do get lost: nested CLAUDE.md files, rules with paths: frontmatter, and anything you only typed in chat.

Can I make compaction happen later or earlier?

/autocompact with a token count, such as /autocompact 500k, sets how full the window gets before the automatic pass, per the context window page. Compacting at a point you choose, with a focus, usually beats letting it fire mid-task.

Docs read 10 Nov 2026.