# `ClaudeAgentSDK.Transport`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.16.0/lib/claude_agent_sdk/transport.ex#L1)

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.

# `message`

```elixir
@type message() :: binary()
```

Binary payload encoded as newline-terminated JSON.

# `opts`

```elixir
@type opts() :: keyword()
```

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

# `subscription_tag`

```elixir
@type subscription_tag() :: :legacy | reference()
```

# `t`

```elixir
@type t() :: pid()
```

Opaque transport reference returned from `start_link/1`.

# `close`

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

Closes the transport and releases any external resources.

# `end_input`
*optional* 

```elixir
@callback end_input(t()) :: :ok | {:error, term()}
```

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

- The built-in erlexec transport sends an `:eof` signal
- Custom transports should close the stdin pipe or equivalent
- This callback is optional - transports may not support it

# `force_close`
*optional* 

```elixir
@callback force_close(t()) :: :ok | {:error, term()}
```

# `interrupt`
*optional* 

```elixir
@callback interrupt(t()) :: :ok | {:error, term()}
```

# `send`

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

Sends a JSON payload to the CLI.

# `start`

```elixir
@callback start(opts()) :: {:ok, t()} | {:error, term()}
```

Starts the transport process and establishes the CLI connection.

# `start_link`

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

Starts the transport process and establishes the CLI connection.

# `status`

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

Returns the current connection status for observability/health checks.

# `stderr`
*optional* 

```elixir
@callback stderr(t()) :: binary()
```

# `subscribe`

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

Subscribes the given process to receive inbound messages.

# `subscribe`
*optional* 

```elixir
@callback subscribe(t(), pid(), subscription_tag()) :: :ok | {:error, term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
