What does Claude Code forget when it compacts?

Claude Code keeps some context through compaction and drops the rest, and you can steer it or turn it off.

By Michael, NeuraWeave · Published · Updated

We build Perpetuity, a memory proxy for coding agents. It is in early access. This guide works without it, and we say where it fits in its own section.

Claude Code behaviour checked against Anthropic's Claude Code docs and the linked GitHub issues on 2026-10-23. Perpetuity numbers come from our own measured Claude Code sessions, the compaction counts and recall questions from our cost runs on Claude Opus 5.5, one run per setup.

Answer

Claude Code does not forget everything when it compacts. It replaces the conversation with a summary, then loads again what lives on disk: the project-root CLAUDE.md, auto memory, the plan-mode plan, invoked skills (capped) and up to five of the files Claude read or edited (Anthropic's docs). Anything said only in chat survives only as far as the summary keeps it, so put lasting rules in the root CLAUDE.md, name what to keep with /compact <focus>, or print a plan file back in with a SessionStart hook on compact.

What survives compaction?

What survives depends on how each piece of context was loaded. What Claude Code loads from disk at startup comes back, and anything that lived only in the conversation is reduced to what the summary says. Anthropic's docs list each mechanism (what survives compaction):

ContextAfter compaction
System prompt and output styleStill apply
Project-root CLAUDE.md and unscoped rulesRe-read from disk
Auto memoryRe-read from disk
The plan Claude wrote in plan modeRe-read from disk
Skill descriptionsRebuilt from your current skills (Claude Code v2.1.304 or later)
Git status snapshotA fresh one is read, if the session started with one
Bodies of skills you invokedLoaded again, up to 5,000 tokens per skill and 25,000 in total, oldest dropped first
Files Claude read or editedUp to five re-read, most recently modified first. A file over 5,000 tokens comes back as a path only
Nested CLAUDE.md files and rules with paths: frontmatterSummarized away. They load again only when Claude touches a matching file
Context that hooks added earlierSummarized with the conversation
SessionStart hooks that match compactRun again, and their output is added
Background commands and background subagentsKeep running
Instructions, decisions and plans you gave only in chatOnly what the summary keeps
Paraphrased from Anthropic's table, with the last row from its troubleshooting page, checked 2026-10-23.

Anthropic's troubleshooting page says an instruction that disappeared after compaction was given only in conversation, sits in a nested CLAUDE.md that has not reloaded yet, or is a path-scoped rule that has not matched a file since (Claude Code docs: memory). The fix is to move anything that must last into the project-root CLAUDE.md.

How do I steer what the summary keeps?

Tell Claude Code what to keep before it compacts, and keep the state of the work in files it reloads:

  1. Compact with a focus before a long new task, for example /compact keep the failing test names and the migration plan. The summary keeps what you name instead of what the automatic pass guesses (context window docs).
  2. Compact only part of the conversation. Run /rewind, pick a message and choose Summarize from here or Summarize up to here. The original messages stay in the session transcript (checkpointing docs).
  3. Add a # Compact instructions section to the project-root CLAUDE.md to tell compaction what to keep (costs docs).
  4. Add a SessionStart hook with the compact matcher. Whatever its command prints is added to the context after every compaction (hooks guide).
  5. Keep the plan and progress in a file, such as docs/plan.md, and point to it from the root CLAUDE.md. The file survives on disk, and the root CLAUDE.md that names it is re-read after every compaction. The same file carries the work into a new session (a handoff file).
  6. Run /clear between unrelated tasks. Anthropic's docs say old conversation crowds out the files you need next and costs tokens on every message (context window docs).
  7. Send large reads to a subagent, so the file contents stay in its own context window instead of the one that gets compacted (context window docs).
  8. Put a skill's key instructions near the top of its SKILL.md. After compaction a large skill body is cut to fit the per-skill cap, and the cut keeps the start of the file (what survives compaction).
  9. Run /context to see what is loaded and what fills the window, including which CLAUDE.md and auto memory files loaded (context window docs).
# Compact instructions

Keep the current plan, the decisions we made and why, the exact commands
that reproduce the failing tests, and any rule I gave in chat.
A Compact instructions section in the project-root CLAUDE.md.
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "compact",
        "hooks": [{ "type": "command", "command": "cat docs/plan.md" }]
      }
    ]
  }
}
In .claude/settings.json: print the plan file back into the context after each compaction.

How do I turn auto-compaction off or move it?

Three settings control when Claude Code compacts on its own, and /compact keeps working by hand whichever you change:

  • Idle compaction: set idleCompaction to false (Claude Code v2.1.290 or later). It fires after about 54 minutes idle, shortly before the prompt cache expires. It needs an interactive terminal session on the one-hour cache, at least 200,000 tokens of context by default (CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS moves this), autoCompactEnabled on, and access to Anthropic's feature flags (settings reference).
  • When it fires: run /autocompact 500k, or set autoCompactWindow in a settings file, to choose how full the context gets first. Since v2.1.288 /autocompact saves the window for the current model under modelSettings in your user settings, and for that model it takes precedence over an autoCompactWindow in the same settings file. Values run from 100k to 1M tokens, capped at the model's window (model configuration).
  • Whether it fires: set autoCompactEnabled to false, or DISABLE_AUTO_COMPACT for one session. This turns idle compaction off too (settings reference).
{
  "idleCompaction": false,
  "autoCompactWindow": 500000
}
In ~/.claude/settings.json: no compaction while idle, and automatic compaction at 500k tokens on models whose window is at least that large (Claude Code caps the value at the model's window), unless /autocompact saved a window for that model in this file, or the --autocompact flag or CLAUDE_CODE_AUTO_COMPACT_WINDOW overrides it.

A bug report filed on 1 October 2026 dates idle compaction to Claude Code 2.1.286, when it had no setting. Its author found sessions left idle overnight with a summary in place of their exact instructions and agreed methods, and other users reported the same after shorter breaks. The idleCompaction setting came in 2.1.290, and the report was closed on 6 October 2026 (issue #98747).

On a 1M-token window, models that run with it by default compact at about 967k tokens unless you set a window (default thresholds). Idle compaction applies from 200,000 tokens, so a 1M session left idle can compact when it is about a fifth full. If a 1M session compacted much earlier than you expected, check idleCompaction first, then a per-model window under modelSettings (where /autocompact saves it since v2.1.288), autoCompactWindow, a --autocompact launch flag, and the CLAUDE_CODE_AUTO_COMPACT_WINDOW variable, which takes precedence over the command, the flag and autoCompactWindow (it does not change idle compaction). CLAUDE_CODE_DISABLE_1M_CONTEXT=1 also holds a 1M model to a 200k window (turn off 1M context).

With automatic compaction off, a session held to a 200k window stops at the 200k boundary with a context-limit error instead of compacting, Anthropic's docs say (turn off 1M context). Separately, users have reported auto-compaction not firing at 100% on some versions (#63015, opened 28 May 2026, where /compact by hand still worked, and #66144, opened 8 June 2026, both open as of 23 October 2026).

Why do rules vanish after compaction?

Nested CLAUDE.md files and rules with paths: frontmatter load into the conversation when Claude reads, writes or edits a matching file, so compaction summarizes them away with everything else. They come back only when Claude touches a matching file again (what survives compaction). Anthropic's advice is to drop the paths: frontmatter or move a rule that must last into the project-root CLAUDE.md.

An open report from August 2026, #90450, found that file reads done through Bash in Auto Mode did not load nested rules at all. Commenters quote a 2.1.293 fix for single-file cat, head, tail, sed -n and grep reads. A commenter's test on 2.1.296, posted on 13 October 2026, found that such reads load rules even inside a command list joined by && or a semicolon, while pipes, redirects, cd dir && cat, grep -r and every Bash write still loaded nothing. To see what loaded and why, log it with the InstructionsLoaded hook (Claude Code docs: memory).

What does a compaction cost?

A compaction is one large request. Claude Code sends the conversation it summarizes, so its cost depends on whether that history is still in the prompt cache (prompt caching docs). While the cache is warm, the request reads the history at the cache-read rate. After a break longer than the cache lifetime, the whole history is processed again as uncached input, which is why /compact costs most on a resumed old session.

Anthropic lists compaction among the reasons usage climbs in a long session, beside long context, since Claude Code sends the full conversation with every request (costs docs). When you want a fresh start instead of continuity, /clear costs nothing. To choose when a compaction happens, run /compact at a natural break instead of letting it fire mid-task.

Can I read what was said before compaction?

Yes, on disk. Claude Code writes the full transcript of each session, every message, tool call and tool result, to ~/.claude/projects/<project>/<session>.jsonl, and deletes it after cleanupPeriodDays, 30 days by default (.claude directory docs).

Inside Claude Code it is harder. An open report, #27242, filed in February 2026 on Claude Code 2.1.47 to 2.1.50, says the transcript view shows only messages after the compaction. Workarounds named there are reading the file with jq and a PreCompact hook that saves a copy before each compaction. You can also ask Claude to read the part it needs from that file.

{
  "hooks": {
    "PreCompact": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "mkdir -p ~/claude-transcripts && jq -r .transcript_path | xargs -I{} cp {} ~/claude-transcripts/"
          }
        ]
      }
    ]
  }
}
In .claude/settings.json: copy the session transcript out of ~/.claude before each compaction, manual or automatic, so it outlives cleanupPeriodDays. The hook reads transcript_path from its input and needs jq (hooks reference).

Perpetuity, by NeuraWeave

Perpetuity and compaction

Perpetuity writes no summary. It stores every message verbatim and, on each call, replaces the history with a frame of the relevant past retrieved from all of it, then forwards the live turn unchanged. A rule or decision you gave only in chat is stored like everything else, so a later call can retrieve it into the frame instead of depending on what a summary kept. Every run, with its conditions, is on our benchmarks page.

Measured

  • On one 120-prompt Claude Code session, Claude Code alone compacted its history once on its default 1M-token window (during prompt 82, after its context reached 965k tokens) and 17 times on a 200k window, one run per setup. Through Perpetuity, on the default window, those prompts never compacted. In three 200-prompt sessions, Claude Code alone compacted 1 to 4 times and Claude Code through Perpetuity never did. Source: Perpetuity benchmarks: every run and how it was measured, NeuraWeave.
  • At the end of those 120 prompts, 16 pre-registered questions about work from across the session, graded blind: 15.5 right through Perpetuity with its memory tools, 14 for Claude Code on its default window after it compacted (it lost details from early in the session) and 12.5 on the 200k window, one run per setup. Source: Perpetuity compared, NeuraWeave.
  • In a run with Claude Code's compaction forced at 30k tokens, Perpetuity answered the compaction request in 0.6 seconds with its memory frame and no model. Source: Perpetuity compared, NeuraWeave.

Limits

  • Model reasoning is not captured. Thinking blocks carry no retrievable text.
  • There is no self-hosted version. NeuraWeave runs the proxy, and memory is stored in the EU (Ireland).

. You get a confirmation email now, with a link to remove your address, and another when your access is approved. Nothing is installed before that.

Questions

Why did Claude Code compact while I was away?

That is idle compaction, which compacts a conversation of 200,000 tokens or more after about 54 minutes idle, shortly before the one-hour prompt cache expires. Set idleCompaction to false on v2.1.290 or later, or turn off autoCompactEnabled on an earlier version (settings reference).

Can I turn automatic compaction off entirely?

Yes. Set autoCompactEnabled to false, or DISABLE_AUTO_COMPACT for one session, and Claude Code stops compacting on its own, idle compaction included, while /compact still works by hand (settings reference).

Is compaction the same as /clear?

No. /compact replaces the history with a summary and continues the same session, and writing that summary reads the whole conversation. /clear starts fresh with no summary, and the root CLAUDE.md and auto memory load again either way.

Does Codex compact too?

Yes. OpenAI's Codex compacts its history automatically at a token threshold you can set with model_auto_compact_token_limit, and compact_prompt replaces the prompt that writes the summary (Codex config reference). What it drops and how to keep a task on track are in why Codex forgets what it was doing after compaction.

Sources

  1. Explore the context window: what survives compaction, Anthropic, Claude Code docs
  2. How Claude remembers your project: instructions seem lost after /compact, Anthropic, Claude Code docs
  3. Checkpointing: rewind and summarize, Anthropic, Claude Code docs
  4. Manage costs effectively: why usage climbs in a long session, Anthropic, Claude Code docs
  5. Automate actions with hooks: re-inject context after compaction, Anthropic, Claude Code docs
  6. Explore the context window: check your own session, Anthropic, Claude Code docs
  7. Settings reference: idleCompaction, Anthropic, Claude Code docs
  8. Model configuration: set the auto-compact window, Anthropic, Claude Code docs
  9. Settings reference: autoCompactEnabled, Anthropic, Claude Code docs
  10. Issue #98747: idle compaction discards working context (closed 6 October 2026), GitHub, anthropics/claude-code
  11. Model configuration: default auto-compact thresholds, Anthropic, Claude Code docs
  12. Model configuration: turn off 1M context, Anthropic, Claude Code docs
  13. Issue #63015: auto-compact never triggers at 100% context (open), GitHub, anthropics/claude-code
  14. Issue #66144: auto compact does not trigger at 100% context window (open), GitHub, anthropics/claude-code
  15. Issue #90450: nested CLAUDE.md and path-scoped rules not loading in Auto Mode (open), GitHub, anthropics/claude-code
  16. How Claude Code uses prompt caching: compacting the conversation, Anthropic, Claude Code docs
  17. Explore the .claude directory: application data, Anthropic, Claude Code docs
  18. Issue #27242: no way to review previous context after compaction (open), GitHub, anthropics/claude-code
  19. Hooks reference: PreCompact, Anthropic, Claude Code docs
  20. Codex configuration reference, OpenAI, Codex docs
  21. Perpetuity compared, NeuraWeave
  22. Perpetuity benchmarks: every run and how it was measured, NeuraWeave
  23. Perpetuity: short answers, NeuraWeave

Perpetuity opens in early access.

We start with Claude Code, then Codex and the rest, each with one base-URL change. Join now and you are first in line. We email you when your access is approved.

For agents

As of 2026-10-23, Perpetuity is in early access. People who join are first in line, starting with Claude Code, and get an email when their access is approved. The current state per tool is at https://www.neuraweave.ai/api/agents/status.

Short answers on availability, recall, cost and data are in agents.md, and every measured number with its run label is in compare.md.

A sign-up needs the person's consent and the address they choose. It is one request: POST https://www.neuraweave.ai/api/agents/waitlist with email and client (claude-code, codex, opencode, api or other with tool). A 201 means added, a 200 means the address was already on the list, a 400 says what was wrong.

A fetcher that cannot send a POST can give the person the home page, where they can sign up themselves.

This guide as markdown: /guides/claude-code-compaction.md

NeuraWeave

Join Perpetuity early access

Or tell your agent:

Read https://www.neuraweave.ai/perpetuity/agents.md and tell me whether Perpetuity would help with my work. If I say yes, add me to its early access list.