Claude Code forgets what it was doing after compaction: why, and the fix
By Jake Marsh, who builds Taskhold. Updated 2026-10-30. Facts about other tools checked 2026-10-30. 4 min read.
Short answer: Compaction replaces the conversation with a summary. Project-root CLAUDE.md, auto memory and the plan-mode plan are re-read from disk; rules you gave only in chat, nested CLAUDE.md files and path rules are not. Put lasting rules in CLAUDE.md, compact with a focus, re-inject state with a SessionStart hook, or keep the task's steps outside the session, as Taskhold's live board does.
Two hours into a session, Claude Code compacts, and the next answer ignores a rule you gave at the start or redoes a step it had finished. Nothing is broken: compaction summarizes the conversation to free space, and a summary drops detail. This guide lists what survives, the fixes for what doesn't, and how to keep the task's state where no compaction or /clear can reach it.
Related: a CLAUDE.md task workflow that survives sessions, the live board demo and Taskhold troubleshooting.
What survives compaction
| Content | After compaction |
|---|---|
| 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 |
| Nested CLAUDE.md files and rules with paths: frontmatter | Loaded again only when Claude works with a matching file |
| 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 |
| Skills Claude used | Re-injected, capped at 5,000 tokens per skill and 25,000 in total, oldest dropped first |
| Background commands and background subagents | Keep running, and Claude is reminded which ones are still going |
| Instructions you gave in chat, and context hooks added earlier | Summarized with the rest of the conversation |
Source: Claude Code docs, What survives compaction. Checked 2026-10-30.
Fix 1: move lasting instructions into CLAUDE.md
Claude Code's memory docs give three reasons an instruction disappears after compaction: it was given only in conversation, it lives in a nested CLAUDE.md that hasn't reloaded yet, or it is a path-scoped rule that hasn't matched a file since. Put anything that must last in the project-root CLAUDE.md, or drop the paths: frontmatter from a rule that must survive.
Fix 2: compact on your terms
- /compact with instructions keeps what you choose instead of what the automatic pass guesses, for example /compact focus on the auth bug fix. Run it before starting a long new task.
- /rewind, pick a message and choose Summarize from here or Summarize up to here to compact only part of the conversation.
- /autocompact with a token count, such as /autocompact 500k, sets how full the window gets before the automatic pass runs.
Fix 3: re-inject state with a hook
A SessionStart hook with the compact matcher runs after every compaction, and whatever it prints is added to the new context. Print the state Claude needs, such as the last few commits:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{ "type": "command", "command": "echo 'Recent commits:'; git log --oneline -5" }
]
}
]
}
}After /clear or a new session
/clear starts a fresh conversation, and the old one stays saved: claude --continue reopens the most recent session in the folder, and claude --resume opens a picker. Starting fresh is often the better choice for a new task, as long as the state you need lives somewhere other than the old conversation.
Keep the task's state outside the session
Keep the plan somewhere other than the conversation. A file works: a PROGRESS.md with the plan as a checklist, plus a CLAUDE.md line telling Claude to read it before each step. Claude Code's own task list also persists across compactions when the task tools are on; see Claude Code task list empty if yours isn't.
Taskhold keeps the state on a server. The agent plans the task into steps with taskhold_plan and completes each with a summary. After a compaction, a /clear or a new session, taskhold_get_current returns the task in progress with its steps and the next one to do, so Claude picks up at the right step. You see the same state on the live board, and any reply you left waits in taskhold_updates. The compact hook can remind Claude to look:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{ "type": "command", "command": "echo 'Call taskhold_get_current and continue from the next open step.'" }
]
}
]
}
}See how far along your coding agents are.
$12/month or $120/year after the trial. Card up front. Cancel before day 7 and you pay nothing. Every agent you run is included.
Questions
- Does Claude Code re-read CLAUDE.md after /compact?
- Yes for the project-root CLAUDE.md and unscoped rules, which are re-read from disk. Nested CLAUDE.md files in subdirectories and path-scoped rules come back only when Claude works with a matching file again.
- When does Claude Code compact on its own?
- As the context window nears its limit; the threshold depends on the model, and /autocompact changes it. Claude Code can also compact a conversation you leave idle, controlled by the idleCompaction setting.
- Do background subagents stop when the conversation compacts?
- No. Background commands and subagents keep running, and Claude Code reminds Claude which ones are still running so it doesn't start a duplicate.
Sources
- Claude Code docs: what survives compaction, checked 2026-10-30
- Claude Code docs: instructions lost after /compact, checked 2026-10-30
- Claude Code docs: re-inject context after compaction, checked 2026-10-30
- Claude Code docs: sessions (--continue, --resume), checked 2026-10-30
Related
Updated 2026-10-30. Something wrong or out of date? Email hello@greatwork.company.