ClaudeAgentSDK.Streaming.Session (claude_agent_sdk v0.17.2)

Copy Markdown View Source

GenServer managing a persistent Claude streaming session.

Real sessions run on ClaudeAgentSDK.Runtime.CLI, which itself runs on the shared core session API. The in-memory mock mode remains local so tests can drive streaming behavior deterministically without a subprocess.

Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the session.

Returns the current Claude session id if one has been observed.

Sends a message to the session and returns a lazy event stream.

Starts a new streaming session.

Types

state()

@type state() :: %ClaudeAgentSDK.Streaming.Session{
  accumulated_text: String.t(),
  active_subscriber: reference() | nil,
  message_buffer: String.t(),
  mode: :runtime | :mock,
  options: ClaudeAgentSDK.Options.t(),
  runtime_event_tag: atom() | nil,
  runtime_projection_state:
    ClaudeAgentSDK.Runtime.CLI.ProjectionState.t() | nil,
  runtime_ref: reference() | nil,
  runtime_session: pid() | nil,
  runtime_session_monitor_ref: reference() | nil,
  runtime_transport: pid() | nil,
  runtime_transport_monitor_ref: reference() | nil,
  session_id: String.t() | nil,
  stderr_buffer: String.t(),
  stop_reason: String.t() | nil,
  subscriber_monitors: %{optional(reference()) => reference()},
  subscriber_queue: [{reference(), String.t()}],
  subscribers: %{optional(reference()) => pid()}
}

subscriber_pid()

@type subscriber_pid() :: pid()

subscriber_ref()

@type subscriber_ref() :: reference()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(session)

@spec close(pid()) :: :ok

Closes the session.

get_session_id(session)

@spec get_session_id(pid()) :: {:ok, String.t()} | {:error, :no_session_id}

Returns the current Claude session id if one has been observed.

send_message(session, message)

@spec send_message(pid(), String.t()) :: Enumerable.t()

Sends a message to the session and returns a lazy event stream.

start_link(options \\ nil)

@spec start_link(ClaudeAgentSDK.Options.t() | nil) :: GenServer.on_start()

Starts a new streaming session.