Create, resume, list, and manipulate Claude Code conversation sessions from the SDK.
Claude Code persists every conversation as a session — a JSONL transcript stored on disk under ~/.claude/projects/. The session API lets you programmatically create multi-turn conversations, read transcripts, rename or tag sessions, and fork sessions into independent branches.
The unstable_v2_* functions are alpha APIs. Their signatures may change in minor or patch releases. Pin to an exact version when using them in production.
Returns:Promise<SDKResultMessage> — the terminal result message from the agent loop.
const result = await unstable_v2_prompt('What files are here?', { model: 'claude-sonnet-4-6', cwd: '/path/to/project',})console.log(result.result) // final text response
Project directory path. When provided, returns sessions for that project directory and its git worktrees. When omitted, returns sessions across all projects.
Reads metadata for a single session without scanning all project sessions. Returns undefined if the session is not found, is a sidechain session, or has no extractable summary.
async function getSessionInfo( sessionId: string, options?: GetSessionInfoOptions,): Promise<SDKSessionInfo | undefined>
Reads the conversation messages from a session’s JSONL transcript file. Parses the transcript, builds the conversation chain via parentUuid links, and returns user/assistant messages in chronological order.
async function getSessionMessages( sessionId: string, options?: GetSessionMessagesOptions,): Promise<SessionMessage[]>
Forks a session into a new branch with fresh UUIDs. Copies transcript messages from the source session, remapping every message UUID while preserving the parentUuid chain. Supports branching from a specific point in the conversation.
Forked sessions start without undo history — file-history snapshots from the source are not copied.
async function forkSession( sessionId: string, options?: ForkSessionOptions,): Promise<ForkSessionResult>
UUID of the last message to include in the fork. When set, only messages up to and including this message are copied. Use this to branch from a specific point in the conversation.