ClaudeAgentSDK.Query.ClientStream (claude_agent_sdk v0.6.9)
View SourceWraps 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:
- Starting a Client GenServer (which handles control protocol)
- Sending the query message
- Wrapping Client.stream_messages as a Stream
- 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.
Summary
Functions
Creates a Stream backed by a Client GenServer.
Functions
@spec stream(String.t(), ClaudeAgentSDK.Options.t()) :: 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 Claudeoptions- Configuration options (must contain SDK MCP servers)
Returns
A Stream of ClaudeAgentSDK.Message structs.