ClaudeAgentSDK.Transport.StreamingRouter (claude_agent_sdk v0.6.9)

View Source

Selects streaming transport based on required features.

Decision Algorithm

  1. Check explicit override (preferred_transport)
  2. Detect control protocol requirements
  3. Default to CLI-only for performance

Examples

# Simple streaming → CLI-only
iex> select_transport(%Options{})
:streaming_session

# With hooks → Control client
iex> select_transport(%Options{hooks: %{pre_tool_use: [...]}})
:control_client

# Override
iex> select_transport(%Options{preferred_transport: :cli})
:streaming_session

Summary

Functions

Human-readable explanation of transport choice.

Checks if options require control protocol.

Selects transport implementation.

Types

transport_choice()

@type transport_choice() :: :streaming_session | :control_client

Functions

explain(opts)

@spec explain(ClaudeAgentSDK.Options.t()) :: String.t()

Human-readable explanation of transport choice.

Examples

iex> StreamingRouter.explain(%Options{hooks: %{...}})
"""
Transport: control_client
Reason: hooks detected
Features: [:hooks]
Override: none
"""

requires_control_protocol?(opts)

@spec requires_control_protocol?(ClaudeAgentSDK.Options.t()) :: boolean()

Checks if options require control protocol.

Useful for debugging transport selection.

select_transport(opts)

@spec select_transport(ClaudeAgentSDK.Options.t()) :: transport_choice()

Selects transport implementation.

Returns :streaming_session (CLI-only) or :control_client (full features).

Performance

This is a pure function with no I/O. Typical execution: <0.1ms.