Streaming Output from Claude Agent SDK Agents
A practical walkthrough of real-time streaming in the Claude Agent SDK: enabling partial messages, reading StreamEvent text and tool-call deltas, the message flow, and building a streaming UI.
Open the source and read safety notes before installing.
Safety notes
- Streaming changes how output is delivered, not what the agent can do; tool permissions and allowedTools still govern actions.
- Accumulate tool-input JSON deltas and parse the completed JSON; do not act on partial tool input.
- Partial text is incremental and may be interrupted; handle incomplete streams gracefully in your UI.
Privacy notes
- Streamed deltas are the same model output as non-streaming; they are sent from the provider over your connection.
- If you render streamed tool inputs, avoid surfacing sensitive arguments in logs or UI.
- Structured output is not streamed; it appears only in the final result message.
Prerequisites
- The Claude Agent SDK installed for Python or TypeScript.
- An async loop over query() results in your application.
- Configured provider credentials for the SDK.
Schema details
- Install type
- copy
- Troubleshooting
- No
Full copyable content
Use this guide to receive incremental text and tool-call updates from a Claude Agent SDK agent as they are generated, for chat or progress UIs.About this resource
Overview
By default the Agent SDK yields complete AssistantMessage objects after each
response. To receive incremental updates as text and tool calls are generated,
enable partial message streaming. This powers chat UIs and progress indicators.
Enable streaming
Set includePartialMessages (TS) / include_partial_messages (Python) to true.
The SDK then also yields StreamEvent messages (TypeScript:
SDKPartialAssistantMessage with type: "stream_event") carrying raw API events.
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);
}
}
}
Read the deltas
- Text:
content_block_deltaevents wheredelta.typeistext_deltacarry text chunks. - Tool calls:
content_block_start(tool begins),content_block_deltawithinput_json_delta(accumulatepartial_json), andcontent_block_stop(call complete). Parse the accumulated JSON once complete.
Message flow
With partial messages on, you receive message_start, content_block_start,
content_block_delta chunks, content_block_stop, message_delta,
message_stop, then the complete AssistantMessage, and finally a
ResultMessage. Without it, you receive the complete messages but no
StreamEvents.
Build a streaming UI
Track an inTool flag from content_block_start/content_block_stop to show a
status like [Using Read...] while a tool runs, and stream text only when not in
a tool. Print a completion marker on ResultMessage.
Known limitation
Structured output does not stream as deltas; the JSON appears only in the final
ResultMessage.structured_output.
Source
- Stream responses in real-time: https://code.claude.com/docs/en/agent-sdk/streaming-output
Source citations
Signals
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.