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.
Opaque transport reference returned from start_link/1.
Callbacks
Closes the transport and releases any external resources.
Signals end of input stream to the CLI process.
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
Callbacks
@callback close(t()) :: :ok
Closes the transport and releases any external resources.
Signals end of input stream to the CLI process.
This closes stdin to indicate no more input will be sent. Required for non-streaming queries where the CLI waits for stdin to close before processing.
Implementation Notes
- For Port-based transports: Close the stdin pipe
- For erlexec-based transports: Send
:eofsignal - This callback is optional - transports may not support it
Sends a JSON payload to the CLI.
Starts the transport process and establishes the CLI connection.
@callback status(t()) :: :connected | :disconnected | :error
Returns the current connection status for observability/health checks.
Subscribes the given process to receive inbound messages.