Skip to main content
The Claude Agent SDK provides powerful session management features including conversation continuity, session listing, message history, and file checkpointing.

Understanding Sessions

Each interaction with Claude creates a session. Sessions store:
  • Conversation history (user and assistant messages)
  • Tool usage and results
  • File changes and checkpoints (when enabled)
  • Cost and usage information
  • Session metadata (title, branch, working directory)
Sessions are stored in ~/.claude/projects/<project-dir>/ as JSONL files.

Continuing Conversations

You can continue previous conversations using the continue_conversation option or by resuming a specific session.

Continue Last Conversation

Resume a Specific Session

Session Forking

Create a new session starting from a previous session’s state:
Session forking creates a new session with a new ID while preserving the conversation history from the resumed session. This is useful for exploring different approaches without modifying the original session.

Listing Sessions

List sessions for a project or across all projects:

List All Sessions

Limit and Filter Sessions

Session Metadata

SDKSessionInfo provides:

Reading Session Messages

Retrieve conversation history from a session:

Pagination

Search All Projects

File Checkpointing

File checkpointing tracks changes to files during a session, allowing you to rewind files to their state at any point in the conversation.

Enable File Checkpointing

Rewind Files

Restore files to their state at a specific user message:
File checkpointing only tracks files that are modified through Claude’s tools (Write, Edit, MultiEdit). Manual changes outside of the session are not tracked.

Use Case: Exploring Alternatives

Session Isolation

Control which settings sources are loaded:
Setting sources:
  • user - User-level settings (~/.claude/)
  • project - Project-level settings (.claude/)
  • local - Local settings (Git-ignored configurations)

Working Directory Management

Sessions are organized by working directory:
Sessions are stored in ~/.claude/projects/<sanitized-cwd>/. The working directory path is sanitized to create a valid directory name.

Complete Session Management Example

Best Practices

The first prompt becomes the session summary. Make it clear and descriptive for easier session identification.
When experimenting with different approaches, enable file checkpointing to easily rewind changes.
Use session forking to explore alternatives without modifying the original conversation.
Sessions accumulate in ~/.claude/projects/. Periodically remove old sessions to save disk space.
Keep working directories organized by project for easier session management and discovery.