Three ways back into work
| What it does | Use when | |
|---|---|---|
| Resume | Continues a specific session with its full history | Prior context is still mostly valid |
| Fork | Copies a session's history into a new, independent session | You want to try an alternative without losing the original |
| Fresh start + summary | New session seeded with a structured summary | Prior tool results are stale |
A session is the conversation history the SDK accumulates while the agent works: your prompt, every tool call, every tool result, every response. The SDK writes it to disk automatically. Returning to it means the agent has everything it read and decided before — which is exactly why returning to it is powerful, and exactly why it can mislead when the world has moved on.
Choosing how to come back
- Yes, nothing has changedResumecontinue with full history
- Mostly — a few files changedResume + name changestell it which files to re-read
- No — much has changedFresh + summarycarry over only what still holds
- Yes, but try an alternativeForkbranch; original stays intact
Resuming and forking in practice
In Claude Code, --resume continues a named or chosen session. In the Agent SDK you capture session_id from the result message and pass it back as resume; setting fork_session (Python) or forkSession (TypeScript) alongside it creates a branch with its own new id, leaving the original untouched.
| Where | Resume | Fork / branch |
|---|---|---|
| Agent SDK | resume=session_id; or continue_conversation=True / continue: true for the most recent | resume + fork_session=True / forkSession: true |
| Claude Code CLI | claude --continue, claude --resume <name or id> | /branch in a session, or --fork-session with --continue / --resume |
| Naming | claude -n <name> at start, /rename during | A branch gets its own session id |
The session id is on every result message, including error results — so a run that stopped at error_max_turns can be resumed with a higher limit. Name sessions you expect to return to; the Claude Code best-practice advice is to treat named sessions like branches, one per workstream.
# session_id holds an analysis of the codebase
# Branch A: explore one testing strategy in a fork
async for m in query(
prompt="Propose a property-based testing strategy for the parser.",
options=ClaudeAgentOptions(resume=session_id, fork_session=True),
):
...
# Branch B: the original session is unchanged; continue a different path
async for m in query(
prompt="Propose a snapshot-testing strategy for the parser.",
options=ClaudeAgentOptions(resume=session_id),
):
...What a fork copies
Copied into the fork
- The full conversation history
- Every earlier tool call and result
- A new session id of its own
Not isolated by a fork
- Files on disk — edits are visible everywhere
- External systems it writes to
- In the CLI, session permission grants if forked into a new process
The stale-context problem
A resumed session still holds the tool results it gathered earlier — including the contents of files that have since been edited. The agent does not know they changed. Two remedies, and the exam wants you to choose correctly:
- A few files changed: resume, and tell the agent exactly which files changed so it re-reads those rather than re-exploring everything.
- Much has changed: start a new session and inject a structured summary of what still holds. This is more reliable than resuming with a history full of stale results.
The SDK documentation makes a related point about running on different machines: session files live on the machine that created them, and one supported approach is not to rely on resume at all — capture the results you need (analysis, decisions, diffs) as application state and pass them into a fresh session's prompt. It calls this often more robust than moving transcript files around. The alternative is a session-store adapter that mirrors transcripts to your own storage so another host can resume them.
Traps the wrong answers are built from
| Tempting but wrong | Do this instead |
|---|---|
| Resuming after large code changes without saying what changed | Name the changed files, or start fresh with a summary. |
| Exploring an alternative inside the original session | Fork, so the original stays intact. |
| Assuming a fork isolates file edits | Forks isolate history only; use checkpointing for files. |
| Throwing away a valid analysis to try a second approach | Fork from it instead of starting from scratch. |
| Expecting a session id to resume on a different machine | Use a session store, or pass saved state into a fresh session. |
You should now be able to
- Resume named sessions to continue an investigation.
- Fork a session to compare approaches from a shared baseline.
- Choose between resuming and starting fresh with an injected summary.
- Tell a resumed session which files changed for targeted re-analysis.
- Capture and store
session_idso interrupted or capped runs can continue.