# `ClaudeAgentSDK.Query.ClientStream`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/query/client_stream.ex#L1)

Wraps the `ClaudeAgentSDK.Client` GenServer to provide a Stream interface.

This module enables `ClaudeAgentSDK.query/2` to work with SDK MCP servers
(and other control-protocol features like hooks and permission callbacks)
by using the control client internally while maintaining the same Stream API.

## Why This Exists

SDK MCP servers require bidirectional communication (control protocol) to work.
The simple `Process.stream` approach is unidirectional and cannot handle
`control_request` messages from the CLI. This module bridges the gap by:

1. Starting a Client GenServer (which handles control protocol)
2. Sending the query message
3. Wrapping Client.stream_messages as a Stream
4. Cleaning up the Client when done

## Usage

This module is used internally by `ClaudeAgentSDK.Query` and should not
be called directly. Use `ClaudeAgentSDK.query/2` as normal.

# `stream`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/query/client_stream.ex#L51)

```elixir
@spec stream(String.t() | Enumerable.t(), ClaudeAgentSDK.Options.t(), term() | nil) ::
  Enumerable.t(ClaudeAgentSDK.Message.t())
```

Creates a Stream backed by a Client GenServer.

This function starts a Client, sends the prompt, and returns a Stream that
yields `ClaudeAgentSDK.Message` structs from the client's mailbox. The Client is
automatically stopped after
the stream is exhausted.

## Parameters

- `prompt` - The prompt to send to Claude
- `options` - Configuration options (must contain SDK MCP servers)

## Returns

A Stream of `ClaudeAgentSDK.Message` structs.

---

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