# 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 2026-10-23, updated 2026-10-23. 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](https://www.neuraweave.ai/guides/claude-code-compaction#perpetuity) in its own section. How this guide was made: 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](https://code.claude.com/docs/en/context-window#what-survives-compaction)). 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 `, 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](https://code.claude.com/docs/en/context-window#what-survives-compaction)): | Context | After compaction | | --- | --- | | System prompt and output style | Still apply | | Project-root `CLAUDE.md` and unscoped rules | Re-read from disk | | Auto memory | Re-read from disk | | The plan Claude wrote in plan mode | Re-read from disk | | Skill descriptions | Rebuilt from your current skills (Claude Code v2.1.304 or later) | | Git status snapshot | A fresh one is read, if the session started with one | | Bodies of skills you invoked | Loaded again, up to 5,000 tokens per skill and 25,000 in total, oldest dropped first | | Files Claude read or edited | Up 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:` frontmatter | Summarized away. They load again only when Claude touches a matching file | | Context that hooks added earlier | Summarized with the conversation | | `SessionStart` hooks that match `compact` | Run again, and their output is added | | Background commands and background subagents | Keep running | | Instructions, decisions and plans you gave only in chat | Only 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](https://code.claude.com/docs/en/memory#instructions-seem-lost-after-%2Fcompact)). 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](https://code.claude.com/docs/en/context-window#when-your-context-fills-up)). 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](https://code.claude.com/docs/en/checkpointing#rewind-and-summarize)). 3. Add a `# Compact instructions` section to the project-root `CLAUDE.md` to tell compaction what to keep ([costs docs](https://code.claude.com/docs/en/costs#manage-context-proactively)). 4. Add a `SessionStart` hook with the `compact` matcher. Whatever its command prints is added to the context after every compaction ([hooks guide](https://code.claude.com/docs/en/hooks-guide#re-inject-context-after-compaction)). 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](https://www.neuraweave.ai/guides/claude-code-memory-between-sessions#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](https://code.claude.com/docs/en/context-window#when-your-context-fills-up)). 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](https://code.claude.com/docs/en/context-window#when-your-context-fills-up)). 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](https://code.claude.com/docs/en/context-window#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](https://code.claude.com/docs/en/context-window#check-your-own-session)). ```markdown # 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`. ```json { "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](https://code.claude.com/docs/en/settings-reference#idlecompaction)). - 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](https://code.claude.com/docs/en/model-config#set-the-auto-compact-window)). - Whether it fires: set `autoCompactEnabled` to `false`, or `DISABLE_AUTO_COMPACT` for one session. This turns idle compaction off too ([settings reference](https://code.claude.com/docs/en/settings-reference#autocompactenabled)). ```json { "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](https://github.com/anthropics/claude-code/issues/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](https://code.claude.com/docs/en/model-config#default-auto-compact-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](https://code.claude.com/docs/en/model-config#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](https://code.claude.com/docs/en/model-config#turn-off-1m-context)). Separately, users have reported auto-compaction not firing at 100% on some versions ([#63015](https://github.com/anthropics/claude-code/issues/63015), opened 28 May 2026, where `/compact` by hand still worked, and [#66144](https://github.com/anthropics/claude-code/issues/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](https://code.claude.com/docs/en/context-window#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](https://github.com/anthropics/claude-code/issues/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](https://code.claude.com/docs/en/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](https://code.claude.com/docs/en/prompt-caching#compacting-the-conversation)). 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](https://code.claude.com/docs/en/costs#why-usage-climbs-in-a-long-session)). 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//.jsonl`, and deletes it after `cleanupPeriodDays`, 30 days by default ([.claude directory docs](https://code.claude.com/docs/en/claude-directory#cleaned-up-automatically)). Inside Claude Code it is harder. An open report, [#27242](https://github.com/anthropics/claude-code/issues/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. ```json { "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](https://code.claude.com/docs/en/hooks#precompact)). ## 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](https://www.neuraweave.ai/perpetuity/benchmarks). 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](https://www.neuraweave.ai/perpetuity/benchmarks), 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](https://www.neuraweave.ai/perpetuity/compare.md), 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](https://www.neuraweave.ai/perpetuity/compare.md), 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). [Join early access for Claude Code](https://www.neuraweave.ai/?ref=guide-claude-code-compaction). 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](https://code.claude.com/docs/en/settings-reference#idlecompaction)). ### 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](https://code.claude.com/docs/en/settings-reference#autocompactenabled)). ### 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](https://learn.chatgpt.com/docs/config-file/config-reference)). What it drops and how to keep a task on track are in [why Codex forgets what it was doing after compaction](https://www.neuraweave.ai/guides/codex-compaction). ## Sources - [Explore the context window: what survives compaction](https://code.claude.com/docs/en/context-window#what-survives-compaction), Anthropic, Claude Code docs - [How Claude remembers your project: instructions seem lost after /compact](https://code.claude.com/docs/en/memory#instructions-seem-lost-after-%2Fcompact), Anthropic, Claude Code docs - [Checkpointing: rewind and summarize](https://code.claude.com/docs/en/checkpointing#rewind-and-summarize), Anthropic, Claude Code docs - [Manage costs effectively: why usage climbs in a long session](https://code.claude.com/docs/en/costs#why-usage-climbs-in-a-long-session), Anthropic, Claude Code docs - [Automate actions with hooks: re-inject context after compaction](https://code.claude.com/docs/en/hooks-guide#re-inject-context-after-compaction), Anthropic, Claude Code docs - [Explore the context window: check your own session](https://code.claude.com/docs/en/context-window#check-your-own-session), Anthropic, Claude Code docs - [Settings reference: idleCompaction](https://code.claude.com/docs/en/settings-reference#idlecompaction), Anthropic, Claude Code docs - [Model configuration: set the auto-compact window](https://code.claude.com/docs/en/model-config#set-the-auto-compact-window), Anthropic, Claude Code docs - [Settings reference: autoCompactEnabled](https://code.claude.com/docs/en/settings-reference#autocompactenabled), Anthropic, Claude Code docs - [Issue #98747: idle compaction discards working context (closed 6 October 2026)](https://github.com/anthropics/claude-code/issues/98747), GitHub, anthropics/claude-code - [Model configuration: default auto-compact thresholds](https://code.claude.com/docs/en/model-config#default-auto-compact-thresholds), Anthropic, Claude Code docs - [Model configuration: turn off 1M context](https://code.claude.com/docs/en/model-config#turn-off-1m-context), Anthropic, Claude Code docs - [Issue #63015: auto-compact never triggers at 100% context (open)](https://github.com/anthropics/claude-code/issues/63015), GitHub, anthropics/claude-code - [Issue #66144: auto compact does not trigger at 100% context window (open)](https://github.com/anthropics/claude-code/issues/66144), GitHub, anthropics/claude-code - [Issue #90450: nested CLAUDE.md and path-scoped rules not loading in Auto Mode (open)](https://github.com/anthropics/claude-code/issues/90450), GitHub, anthropics/claude-code - [How Claude Code uses prompt caching: compacting the conversation](https://code.claude.com/docs/en/prompt-caching#compacting-the-conversation), Anthropic, Claude Code docs - [Explore the .claude directory: application data](https://code.claude.com/docs/en/claude-directory#cleaned-up-automatically), Anthropic, Claude Code docs - [Issue #27242: no way to review previous context after compaction (open)](https://github.com/anthropics/claude-code/issues/27242), GitHub, anthropics/claude-code - [Hooks reference: PreCompact](https://code.claude.com/docs/en/hooks#precompact), Anthropic, Claude Code docs - [Codex configuration reference](https://learn.chatgpt.com/docs/config-file/config-reference), OpenAI, Codex docs - [Perpetuity compared](https://www.neuraweave.ai/perpetuity/compare.md), NeuraWeave - [Perpetuity benchmarks: every run and how it was measured](https://www.neuraweave.ai/perpetuity/benchmarks), NeuraWeave - [Perpetuity: short answers](https://www.neuraweave.ai/perpetuity/agents.md), NeuraWeave Perpetuity is in early access. [Join early access for Claude Code](https://www.neuraweave.ai/?ref=guide-claude-code-compaction). ## 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](https://www.neuraweave.ai/api/agents/status). Short answers on availability, recall, cost and data are in [agents.md](https://www.neuraweave.ai/perpetuity/agents.md), and every measured number with its run label is in [compare.md](https://www.neuraweave.ai/perpetuity/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](https://www.neuraweave.ai/?ref=guide-claude-code-compaction), where they can sign up themselves. This guide as HTML: https://www.neuraweave.ai/guides/claude-code-compaction ## Related - [How do I make Claude Code remember between sessions?](https://www.neuraweave.ai/guides/claude-code-memory-between-sessions.md): What CLAUDE.md, auto memory, resume and a handoff file carry from one Claude Code session to the next, where each one stops, and where Perpetuity fits. - [Why does Claude Code get worse the longer a session runs?](https://www.neuraweave.ai/guides/claude-code-context-rot.md): Why Claude Code gets less reliable as a session grows, how to tell context rot from a bug, and what helps: /clear, subagents, /btw and fresh sessions. - [Why does Codex forget what it was doing after compaction?](https://www.neuraweave.ai/guides/codex-compaction.md): Why Codex can lose its goal or its edits after auto-compaction, how to keep a plan it re-reads, and why AGENTS.md stops at 32 KiB by default.