1.7 Session state, resumption, and forking
| Mechanism | Invocation | Purpose |
|---|---|---|
| Named resumption | claude --resume <session-name> / resume: "<id>" (CLI reference, sessions) | Continue a specific prior conversation |
| Forking | fork_session / forkSession: true | Branch independently from a shared baseline |
| Fresh session + summary | new session, summary injected into the prompt | Prior tool results are stale |
| Compaction | /compact | Reduce context mid-session |
Resume vs start fresh
| Prior context is… | Do this |
|---|---|
| Mostly valid | Resume — and explicitly tell the agent which files changed so it re-analyses only those |
| Stale (files rewritten, tool results no longer true) | Start a new session with a structured summary — more reliable than resuming onto stale tool results |
Telling a resumed session "auth/session.ts and auth/tokens.ts changed since your last analysis; re-read those two" gives targeted re-analysis instead of full re-exploration.
Forking for divergent exploration
┌── fork A: "test with in-memory fakes"
baseline ────┤
(codebase └── fork B: "test with containerised deps"
analysis)
Both branches start from the shared analysis; neither pollutes the other. Use it to compare two testing strategies or two refactoring approaches.
Quiz
- Question 1
You resume yesterday’s named session with --resume auth-refactor. Overnight a teammate merged a change that renamed three of the files the agent had analysed and moved the token validator to a new package. The remainder of yesterday’s analysis — the call graph, the failure modes, the migration order — is unaffected. What is the right move?
- Question 2
You are running three long investigations in the same repository — a flaky test hunt, an auth refactor, and a dependency upgrade — switching between them from day to day. You keep losing track of which prior conversation held which investigation. What mechanism addresses this?
- Question 3
You return to a session you left three weeks ago. Since then the repository has taken 200 commits, the module that session analysed has been split into three, and the build system has been replaced. Your conceptual conclusions from that session still hold. What is the better move?
- Question 4
A developer forks a session twice from a shared codebase-analysis baseline to try two refactoring approaches. An hour in, they ask why the second branch does not know about a helper function the first branch extracted. What is the correct explanation?