Home / Errors / Claude Code / auto-compact-memory-loss

Claude Code Forgot Everything After Auto-Compact

Claude Code Easy 10-20 minutes to re-prime a degraded session Last verified Jul 17, 2026
The fix  Do not let auto-compact fire mid-task. Watch the context indicator and run /compact yourself around 60 to 70 percent, at a logical breakpoint, with instructions about what to preserve. Keep durable state in files (a plan doc plus CLAUDE.md), and after any compaction, have Claude re-read both before it continues, because CLAUDE.md is not automatically re-injected after /compact.

Symptoms

  • Hours into a session, Claude Code silently 'compacts' the conversation.
  • Afterward it forgets key architectural decisions and re-asks questions you already answered.
  • It loses track of skills and CLAUDE.md instructions.
  • It keeps working on the degraded summary and undoes or breaks code it just wrote, because it no longer remembers writing it.
  • Users describe losing the effective value of 4-hour sessions.

Why it happens

Compaction is lossy by design

When the context window fills, Claude Code summarizes the conversation to free space. Nuanced decisions, the why behind choices, active skill state, and even CLAUDE.md project instructions get flattened or dropped (issues #13112, #13919, #24460).

It fires silently and the agent keeps going

Compaction triggers mid-task without a pause, and the agent auto-continues on the degraded summary (issue #21925), sometimes undoing work it no longer remembers doing.

Adjacent compaction bugs make it worse

Auto-compact can fail to trigger at 100 percent so the session just stops (issue #66144), and compaction errors can corrupt context tracking (issue #3274).

How to fix it

  1. Compact manually before it compacts youWatch the context indicator or statusline and run '/compact <instructions about what to preserve>' yourself at a logical breakpoint, around 60 to 70 percent usage. A compaction you schedule keeps what you tell it to keep; one that fires mid-task keeps whatever the summarizer guesses matters.
  2. Write durable state to files before long tasksKeep a plan and progress doc in the repo and record decisions in CLAUDE.md. Context that lives on disk can be rebuilt after any compaction; context that lives only in the chat cannot.
  3. Re-prime after every compactionAsk Claude to re-read CLAUDE.md and the plan doc before it continues. CLAUDE.md is not automatically re-injected after /compact (issue #24460), so the agent that resumes is not quite the agent that stopped.
  4. Prefer /clear plus a re-prime for new subtasksRepeated compactions stack lossy summaries on lossy summaries. For a new subtask, '/clear' plus a short re-prime gives you a clean context; use '/resume' to pick up prior sessions.
  5. Commit before context fills, and diff after compactionCommit working code before the window gets full so post-compaction confusion cannot destroy verified work. Run 'git diff' after any compaction to catch the agent undoing things it no longer remembers writing.

How to prevent it

  • Break big jobs into multiple shorter sessions instead of one marathon; every compaction you avoid is context you keep.
  • Keep a living plan doc plus decisions in CLAUDE.md so any session can rebuild context from disk.
  • Run /compact yourself at natural breakpoints around 60 to 70 percent context usage, with preserve instructions.
  • Commit at every verified working state.

Frequently asked questions

Why does Claude Code forget everything after auto-compact?

When the context window fills, Claude Code summarizes the conversation to free space, and that summary is lossy. Nuanced decisions, the reasoning behind choices, active skill state, and even CLAUDE.md project instructions get flattened or dropped, which is tracked in issues #13112, #13919, and #24460. The agent then auto-continues on the degraded summary as if nothing happened.

Does Claude Code re-read CLAUDE.md after /compact?

No. CLAUDE.md is not automatically re-injected after /compact, which is tracked as claude-code issue #24460. After any compaction, explicitly ask Claude to re-read CLAUDE.md and your plan doc before it continues working.

Can I stop Claude Code from auto-compacting?

The reliable control is beating it to the punch: watch the context indicator and run /compact yourself at a logical breakpoint around 60 to 70 percent, with instructions about what to preserve. There are also known bugs at the extremes, including auto-compact failing to trigger at 100 percent so the session just stops (issue #66144).

Is /clear better than /compact in Claude Code?

For a new subtask, yes. Running /clear plus a short re-prime from your plan doc gives the model a clean context, while repeated /compact runs stack lossy summaries on top of each other. Use /resume when you want to pick up a prior session.

Sources

Related errors

The Vibe Oops briefing

One email when something ships to production that should not have. New incidents, new error guides, no filler.