All answers

Claude Code, Codex and Cursor

What does Claude Code forget when it compacts a conversation?

Alexandru Lupascu, CTO & Co-founder · Updated

When Claude Code compacts, it replaces the conversation history with a summary, so details that lived only in the chat can be lost, while the system prompt still applies and the project-root CLAUDE.md and auto memory are reloaded from disk. According to Anthropic's Claude Code docs, the summary "keeps your requests and key code snippets, but detailed instructions from early in the conversation may be lost". After the summary, Claude Code re-reads up to five of the files Claude read or edited, most recently modified first. Anything else, such as earlier tool output or a rule you typed in chat, survives only as far as the summary kept it.

What survives compaction and what does not?

Content loaded from disk comes back; content that lived in the conversation is summarized. The Claude Code context window docs list each mechanism:

ContentAfter compaction
System prompt and output styleStill apply
Project-root CLAUDE.md and unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
Plan written in plan modeRe-injected from disk
Path-scoped rules and nested CLAUDE.md filesReloaded only when Claude touches a matching file again
Files Claude read or editedUp to five re-read; a file over 5,000 tokens returns as a path only
Invoked skillsRe-injected, capped at 5,000 tokens per skill and 25,000 in total
Context added earlier by hooksSummarized with the conversation

When does Claude Code compact automatically?

Claude Code compacts automatically as the conversation approaches the context limit, so a full window does not end the session. According to Anthropic's model configuration docs, models with a native 1M-token window compact at about 967K tokens by default, and Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary. You can compact earlier with /autocompact 500k, the autoCompactWindow setting or the CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable. Compaction itself costs tokens: the Claude Code cost docs note that /compact reads the whole conversation it summarizes, while /clear "costs nothing" when you want a fresh start instead of continuity.

How do you keep important context through compaction?

Move anything that must survive out of the chat and into files or hooks:

  1. Put standing rules in the project-root CLAUDE.md, and remove paths: frontmatter from any rule that must persist.
  2. Add a "Compact instructions" section to the project-root CLAUDE.md; Anthropic's example is "When you are using compact, please focus on test output and code changes".
  3. Before a long new task, run /compact with a focus, such as /compact focus on the auth bug fix.
  4. Add a SessionStart hook with the compact matcher in .claude/settings.json. Claude Code adds the hook's output, for example from git log --oneline -5, to the compacted context.
  5. Put the most important lines at the top of each SKILL.md, because truncation keeps the start of the file.
  6. To compact only part of the conversation, run /rewind, pick a message and choose Summarize from here.

Is there an alternative to summarizing one long session?

Compaction is a summary, so some loss is built in. Anthropic's engineering post on context engineering warns that "overly aggressive compaction can result in the loss of subtle but critical context whose importance only becomes apparent later", and Anthropic's context window docs say that as token count grows, accuracy and recall degrade, a pattern called context rot. elephant.broker, a pluggable runtime for AI agents, works per turn instead of per session: on every turn elephant.broker assembles a working set from one graph and vector store, keeps current, verified context, drops stale or duplicate facts, and writes decisions, corrections and outcomes back to that store for the next turn. elephant.broker adds a retrieve and rerank step to every turn. For short sessions, Claude Code's own compaction plus a well-kept CLAUDE.md is enough.

Sources

Product details come from each vendor's public documentation as viewed on 2026-10-28 and may have changed. Product names are trademarks of their respective owners; elephant.broker is not affiliated with them.