Session State and Resumption
What a session is
The conversation history the SDK accumulates: your prompt, every tool call, every result, every response. It is written to disk automatically. Sessions persist the conversation, not the filesystem.
Continue, resume, fork
| Want | Use |
|---|---|
| One-shot task | Nothing extra |
| Multi-turn chat in one process | ClaudeSDKClient (Python) or continue: true (TypeScript) |
| Pick up the most recent session in the directory | continue_conversation=True / continue: true |
| Return to a specific session | Capture session_id, pass it to resume |
| Try an alternative without losing the original | Fork: fork_session=True / forkSession: true together with resume |
| Nothing written to disk | persistSession: false (TypeScript) |
- Resume needs the ID; the ID comes from the
session_idon the result message. - Fork creates a new session with a copy of the history; the original is unchanged; the fork gets its own ID.
- Resuming is also how you recover after a limit such as
error_max_turnsorerror_max_budget_usd: resume with a higher limit. - Transcripts live under
~/.claude/projects/<encoded-cwd>/*.jsonlon that machine.
Files can change under you (verified boundary, practical guidance)
Because a session stores the conversation, not files, earlier file reads inside it can be out of date if the files changed. Forking branches the conversation only; edits a forked agent makes are real files visible to every session in that directory. To snapshot and revert file changes, use file checkpointing. Practical rule: after resuming, tell the agent what changed or have it re-read the files that matter.
Resuming elsewhere
Session files are local. For CI workers, containers or serverless: use a session store adapter, move the .jsonl file, or (often most robust) save the results you need as application state and pass them into a fresh session's prompt.
Resuming a subagent
A completed subagent's result includes agentId: <id>. Resume the same session with resume: sessionId and mention the agent ID in the prompt; pass the same agents definition again. Built-in Explore and Plan agents are one-shot and return no agentId.
Exam traps
- Using
continuewhen several users or sessions exist. Useresumewith a tracked ID. - Forking to "undo" file edits. It does not touch files.
- Assuming a resumed session sees current file contents.
- Expecting to resume on another machine with no transfer or store.
References
- Work with sessions — checked Oct 16, 2026
- Subagents in the SDK — checked Oct 16, 2026
Check your understanding
Try OAuth2 without losing the JWT thread: which option?Show answerHide answer
Answer
Fork:resumeplusfork_session; resume the original later for JWT.A run ended with
error_max_turns. How do you continue?Show answerHide answerAnswer
Resume the session with a higher limit.Does a fork revert file edits?Show answerHide answer
Answer
No; use file checkpointing.