OmniscioGuidesStreaming in the Claude Agent SDK
Claude Agent SDK: streaming responses and follow-up messages
"Streaming" in the Agent SDK means two different things, and they are configured separately. Streaming output is how you watch a reply build up instead of waiting for it. Streaming input is how one session stays open for the next message. This page covers both.
This page owns streaming. The SDK guide owns the options object and a first agent, the sessions guide owns resuming a session after a call ends, and the structured output guide owns the JSON result the stream ends with.
Sources read November 26, 2026. By the Omniscio team. Updated .
Streaming output
Without any option, the SDK yields a complete AssistantMessage for each non-empty content block — a text block or a tool call — once Claude has finished generating that block. That is enough for a script and too slow for a chat window.
Set includePartialMessages: true in TypeScript, or include_partial_messages=True in Python. The SDK then also yields StreamEvent messages carrying the raw API events as they arrive, alongside the complete messages and the final result.
Reading them takes three checks in order: the message is a stream event, its event.type is content_block_delta, and delta.type is text_delta. The chunk you print is delta.text.
for await (const message of query({
prompt: "List the files in my project",
options: { includePartialMessages: true, allowedTools: ["Bash", "Read"] }
})) {
if (message.type === "stream_event") {
const event = message.event;
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}
}The wrapper type is named differently in each SDK: StreamEvent imported from claude_agent_sdk.types in Python, and SDKPartialAssistantMessage with type: 'stream_event' in TypeScript.
What order things arrive in
A reply that contains text and a tool call produces two assistant messages, each carrying its own block, both sharing one message ID. With partial messages on, each message arrives just before its block's content_block_stop, so the sequence runs: message_start, the text block's start, its deltas, the complete text message, its stop, then the same pattern for the tool call, then message_delta and message_stop, then the tool runs, then the next turn streams.
With partial messages off you get everything except the stream events: the system init message, complete assistant messages, the final result, and a compact boundary message when the conversation was compacted.
Streaming tool calls
Tool calls stream the same way. A content_block_start marks a tool beginning, input_json_delta chunks carry its arguments as they are generated, and content_block_stop marks the end — which lets an interface show "reading file" before the arguments are complete.
When a stream is cut off
A stream can end mid-message when a turn is interrupted, a connection drops, or the request falls back to non-streaming. The turn still ends with message_stop, but content_block_stop and message_delta can be missing before it.
Two rules follow. content_block_stop arrives for the block that was open, except when that block is a tool call — so if message_stop arrives while a tool call is still open, treat that call's input as incomplete. And do not wait for message_delta on a cut message: it arrives when you interrupt the turn but can be missing after a drop.
One version floor explains a stuck spinner. Before Claude Code v2.1.290 a cut stream could end a turn without message_stop, so a reply you rendered from stream events could stay "in progress" forever. The TypeScript Agent SDK bundles that version from v0.3.290, and the Python SDK from v0.2.164 — if a reply stays in progress after the turn ends, update the SDK.
Streaming input, and why you want it
A single-shot call passes one prompt string to query() and ends when Claude answers. That fits a serverless function. It does not fit a conversation.
Streaming input keeps the session open so the application can send more than one message while it runs. It is also what lets you attach an image to a message, interrupt a response, or switch the model or permission mode while the session runs. If you only need a follow-up after a call has already ended, the sessions guide covers resuming instead.
In TypeScript you write an async generator of SDKUserMessage objects and pass it as the prompt, waiting between yields for your user's next message. In Python you open a ClaudeSDKClient and pass each message to client.query(); an image goes in as an async generator that yields user message dicts.
async function* messages(): AsyncGenerator<SDKUserMessage> {
yield { type: "user", message: { role: "user", content: "Explain what a message queue does." }, parent_tool_use_id: null };
await firstResponseFinished; // resolved when the result message arrives
yield { type: "user", message: { role: "user", content: "Now shorten it to one sentence." }, parent_tool_use_id: null };
}One answer at a time
To have Claude answer each message in its own response, wait for the previous response's result before sending the next: in TypeScript resolve a promise inside the for await loop when the result arrives, in Python call query() again after the receive_response() loop ends. A message sent while tools are running is different — it reaches Claude after those tools finish, and Claude then answers it together with the earlier message in one response, or starts a new turn for it if the turn ended first.
Reading each response
Every response ends with a result message. In TypeScript the for await loop over query() yields each response's messages in order and ends after the last result once your generator has returned; to match a result to the message it answers, put a uuid on what you send and read the result's user_message_uuids. In Python, start a receive_response() loop for each response, because each loop stops at the next result while the client keeps the conversation's context.
The result's subtype says how the response ended, such as success or error_during_execution. That difference matters in code: in TypeScript, if the last response is an error result the loop yields it and then throws, so wrap the loop in try/catch and resume the session with a new call to continue; an error on an earlier response does not throw while your generator still has messages to send. In Python, receive_response() yields the error result without raising.
Interrupting
Call interrupt() to stop a response partway and keep the session open. In TypeScript, pass an async generator as the prompt, keep the Query object query() returns, and call interrupt() on it; in Python call it on the ClaudeSDKClient, where a running receive_response() loop ends at the interrupted response's result. The interrupted response ends with an error_during_execution result, and any message you sent that Claude had not read yet still reaches it once the response ends.
One limitation worth knowing
With partial messages on, a structured output result streams as a tool call's unvalidated input_json_delta chunks. Only the validated object reaches the final result's structured_output, so render the validated field rather than the chunks.
Sources
Every line on this page rests on one of these. The date beside each one is the day we read it.
- Stream responses in real-time, for partial messages, the delta checks, the type names, the message flow, cut-off streams, tool-call streaming and the structured-output limitation. Read November 26, 2026.
- Send messages to a running agent, for single-shot versus streaming input, sending more messages, reading each response, error results and interrupting. Read November 26, 2026.
No SDK agent was run for this page. Every option, event name, version floor and result field is transcribed from those pages.
Common questions
How do I stream Claude's response in the Agent SDK?
Set includePartialMessages to true in TypeScript or include_partial_messages in Python. The SDK then emits stream_event messages containing raw API events, and you read text from content_block_delta events whose delta type is text_delta.
What is the difference between streaming input and a single prompt?
A single prompt string ends its call after Claude answers. Streaming input keeps the session open so you can send more messages, attach images, interrupt a response or change the model mid-session.
Why do I get two assistant messages for one reply?
The SDK emits an assistant message as each content block completes, so a reply with text and a tool call yields two messages, each carrying its own block and sharing the same message ID.
How do I interrupt a response in the Agent SDK?
Call interrupt() on the running query object in TypeScript or on the ClaudeSDKClient in Python. The response ends with an error_during_execution result and the session stays open; messages Claude had not read yet still reach it.
Does streaming work with structured output?
Yes, with a caveat. The JSON arrives as a tool call's unvalidated input_json_delta chunks, and only the validated object appears on the final result's structured_output field.
Every session, one window
Omniscio runs several agent sessions side by side in one window, each with its own context and its own diff view. Any model, any harness: Claude Code, Codex, OpenCode, Devin, Pi, and Hermes all supported.