Original explainer
Claude Code context: preserve constraints before compaction
Use /context, persistent instructions and handoff notes to manage a long task, and distinguish session recovery from file recovery.
When a long task repeatedly reads the same files or misses constraints, inspect what occupies context before choosing compaction or recovery. The intended output is a reviewable handoff note, not a claim that the model context has expanded. You need an existing Claude Code session and project files to inspect. No actual Claude Code session was started for this page.
Action and checking sequence
Inspect usage
Use /context to inspect context rather than inferring the cause from slow responses.[1]
Preserve constraints
Put persistent conventions in project instructions and stage results in a handoff note.[1]
Resume and check
After resuming, check current files, pending work and expected results.[1]
Identify what occupies context
The documentation lists conversation history, file contents, command outputs, CLAUDE.md, auto memory, loaded skills and system instructions as context. Large files or outputs consume the window. Automatic compaction retains requests and key code snippets, but earlier details can be lost. /context helps inspect usage; successful compaction does not mean every original detail remains available.[1]
Write a compact handoff note
- Goal: fix duplicate execution during queue retries; acceptance means one message does not produce repeated writes.
- Decisions: use the message ID as the deduplication key and focus on the two relevant modules.
- Completed: located the files and reproduction input; keep the location of actual test output.
- Pending: implementation and retry checks; label any check that has not run.
- Recovery point: current branch, uncommitted differences and the next concrete command.
This is an original exercise, not a finding from an actual project. Persistent conventions belong in CLAUDE.md, while a handoff note records work state. The documentation allows a focus with /compact and Compact Instructions in CLAUDE.md to describe what should survive compaction.[1]
Check files and conversation on recovery
The documentation distinguishes continuing, resuming and forking: claude --continue or claude --resume reopens the original session, while forking copies history to a new session. After switching branches, the conversation remains but the files belong to the new branch. Check Git state and current differences before following the handoff note; historical discussion is not a snapshot of current files.[1]
File recovery and verification scope
File checkpoints are distinct from Git and session recovery. The documentation says they cover file changes and cannot undo remote actions such as databases, APIs or deployments. This page checked the official workflow and handoff example without running /context, /compact, session recovery or checkpoint restoration. After adoption, compare actual output and current files rather than declaring consistency because a session resumed.[1]
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.