Claude Agent SDK sessions preserve conversation and agent state across exchanges. Use a continuous client for interactive work, capture session IDs from streamed lifecycle/results, resume an existing session for continuity, and fork when exploring an alternative without mutating the original history. Session identity never replaces application authorization or durable business state.
You will capture and resume a session, know when to fork, and list the state that must travel across hosts.
Python offers query() for one-off or explicitly resumed exchanges and ClaudeSDKClient for continuous conversations with richer lifecycle control. TypeScript supports continuing through the query interface. Choose the smallest lifecycle that fits the product.
The durable pattern is:
Consult the current reference for message fields and external-storage support before production use.
Resume continues the same line of work. Fork creates a new branch from an existing session, useful for comparing plans or providers without corrupting the source branch. Store parent/child relationships so evaluation and auditing can distinguish experiments.
The provider session plus local state it references: working files/checkpoints, project configuration, permissions, prompt/skill files, MCP configuration, tool attempt records, budgets, and application identity. The hosting chapter explains that parts of Claude’s runtime state live on local disk; a session ID alone may not recreate the environment.
Resume from a new process, then from a new container with restored storage. Confirm tenant/user authorization before handing the session ID to the SDK. Fork and verify the parent remains unchanged.
Failure injection: Resume a valid session in the wrong working directory. The harness should detect the environment mismatch before execution.
Design a session registry with tenant binding, environment fingerprint, parent session, retention, tool profile, and last checkpoint. Add mismatch and cross-tenant tests.