Skip to main content

Session

The Session class manages multi-turn conversations with Claude. It matches the official Claude Agent SDK V2 interface.

Creating Sessions

Sessions are created via the client. Connection happens automatically on first send().

Methods

send()

Send a message to Claude. Returns a Promise that resolves when the message is sent. Use stream() to receive the response. Supports both text-only messages and multimodal content (text + images + documents).

Text Message

With Image

With Document (PDF)

Multiple Attachments


stream()

Stream the response after sending a message. Returns an async generator that yields SDK messages.

SDKMessage Types

Example


receive()

Alias for stream() for V2 compatibility.

close()

Close the session and release resources.

Example


on()

Register event handlers.

SessionEventHandlers

Example

Properties

state

Current session state.

sessionId

The session’s unique identifier.

Helper Functions

getAssistantText()

Extract text content from an assistant message.

Example


getResultText()

Extract the result text from a result message.

SDK Message Types

SDKAssistantMessage

SDKResultMessage

SDKSystemMessage

Usage Patterns

Basic Conversation

Resuming Sessions

Error Handling

Using await using (TypeScript 5.2+)