GuidesUpdated

Why did Claude Code forget my task after compaction?

Recover a Claude Code task after /compact: check the branch, diff, tests and lost instructions, then give the agent one verified next step.

On this page

After a long Claude Code session compacts, the agent repeats a finished step, forgets a constraint, or asks which branch matters. Compaction summarizes the conversation to save context; it doesn't check that summary against the repository. Rebuild the task from current files and decisions, then give the session a short correction it can verify.

Canopy project context beside coding-agent sessions
Canopy project context beside coding-agent sessions

Find out what was lost before restarting

Ask the session for its goal, branch, last accepted change, tests run and next action. Compare that with the issue, the Git diff and the latest PR commit. A wrong summary is a context problem; an uncommitted file or failing test is a work-state problem.

Canopy keeps the session, repository, project notes and running app together, but the conversation isn't proof that code changed or a test passed. Don't paste the whole original prompt and rerun the same edit.

Pick the evidence that answers the missing part.
What the agent lostCheck nowGive back to the session
Goal or acceptance checkIssue, task brief or product decisionOne current outcome and its pass/fail check
Branch or completed workGit status, diff, commit and PR headCheckout and changed files
Failed commandSaved log or a focused rerunFirst error and command result
Reason for a choicePR discussion or decision noteAccepted choice and why the alternative was rejected
Local app stateLive service output and preview URLProcess, checkout, URL and observed behavior

Check what Claude Code keeps in context

Claude Code's docs say the context window holds messages, files, command output, project memory, skills and other instructions. Long sessions clear older tool output and summarize the conversation, so early detailed instructions can be lost.

Run `/context` to see what's using the window, and check the session after `/compact`. `/compact` accepts focus instructions, such as the API change that must carry on. Other CLIs compact and resume differently.

  • Keep the session if its context is still useful and the task hasn't changed.
  • A context percentage is not a plan limit or a bill.

Restore the missing decision from durable evidence

For a settings-form retry, a useful recovery note gives the intended behavior, branch and commit, files touched, failing request path, test results, and the decision not to change the schema. Link the PR or issue where those were agreed.

Record any failed approach and why it was rejected, or the session may try it again. Leave out customer data, credentials and long transcripts.

  • Separate observed results from the agent's claims.
  • Give one next action, such as reproducing the failed save and inspecting its handler.
  • Name who decides any open product rule or risky deployment change.

Put stable rules where Claude reloads them

Anthropic says a project-root `CLAUDE.md` is re-read after compaction; a chat-only instruction can disappear. Nested and path-scoped rules reload when matching files are read. Put lasting conventions there: run command, test naming, rules for future tasks.

Keep today's branch and transient errors in a task note or PR. Claude's memory guide warns that oversized instruction files use context and reduce adherence, so keep the file short. Canopy's shared project notes help the next session find current state.

  • Use a PR, issue or task note for changing state and decisions.
  • Test a new instruction in a fresh or compacted session.

Resume with a check, not a memory test

Give Claude Code the recovery card and ask it to inspect the cited branch, diff and failing path before editing. Have it restate the acceptance check and name the first action that would prove the remaining problem. Then let it take one bounded step.

If it proposes redoing work already in the PR, point to the commit. Another CLI doesn't inherit Claude Code's transcript, so give it the same evidence. Update the task note afterwards, so the next compaction has an anchor outside the chat.

  • Check the diff and result after the recovery step.
  • Escalate a missing product decision instead of asking the agent to infer it.

Copyable resources

After-compaction recovery card

Fill this from current evidence, not only the agent's summary.

Current outcome and acceptance check: [ ]
Issue/PR, checkout, branch and latest commit: [ ]
Changed files and observed behavior: [ ]
Commands/tests run and first failing result: [ ]
Accepted decision; rejected approach and why: [ ]
Service process and preview URL, if relevant: [ ]
Constraint that must survive this task: [ ]
One next action: [ ]
Before editing: inspect the cited files and restate the acceptance check.
After editing: report the new diff, checks run and remaining uncertainty.

Frequently asked questions

Does /compact delete my code changes?

No. Compaction changes what the model carries in context. Check Git status, the files and the PR for the real code state.

Will CLAUDE.md survive Claude Code compaction?

Anthropic documents that the project-root file is re-read after compaction. Nested or path-scoped files load under their own conditions, so keep task-specific state in a current artifact.

Should I paste the entire old conversation after compaction?

Usually not. Start with the goal, branch, decisions, failing result and one next action. Pull up a specific old message or log only if the question needs it.

Can I hand the compacted Claude task to another coding CLI?

Yes, through repository artifacts and a short handoff. The other CLI has its own conversation and model account, so check its checkout and understanding before it edits.

More questions and answers →

Sources and further reading