ClaudeAgentSDK.Transport behaviour (claude_agent_sdk v0.6.9)

View Source

Behaviour describing the transport layer used to communicate with the Claude CLI.

A transport is responsible for starting and supervising the underlying connection, forwarding JSON control/data frames to the CLI, broadcasting replies to subscribers, and shutting down cleanly when the client stops.

Implementations should be OTP-friendly processes (typically a GenServer) that encapsulate any state required to maintain the connection.

Summary

Types

Binary payload encoded as newline-terminated JSON.

Transport-specific options propagated from Client.start_link/1.

t()

Opaque transport reference returned from start_link/1.

Callbacks

Closes the transport and releases any external resources.

Sends a JSON payload to the CLI.

Starts the transport process and establishes the CLI connection.

Returns the current connection status for observability/health checks.

Subscribes the given process to receive inbound messages.

Types

message()

@type message() :: binary()

Binary payload encoded as newline-terminated JSON.

opts()

@type opts() :: keyword()

Transport-specific options propagated from Client.start_link/1.

t()

@type t() :: pid()

Opaque transport reference returned from start_link/1.

Callbacks

close(t)

@callback close(t()) :: :ok

Closes the transport and releases any external resources.

send(t, message)

@callback send(t(), message()) :: :ok | {:error, term()}

Sends a JSON payload to the CLI.

start_link(opts)

@callback start_link(opts()) :: {:ok, t()} | {:error, term()}

Starts the transport process and establishes the CLI connection.

status(t)

@callback status(t()) :: :connected | :disconnected | :error

Returns the current connection status for observability/health checks.

subscribe(t, pid)

@callback subscribe(t(), pid()) :: :ok

Subscribes the given process to receive inbound messages.