# Useful but Little-Known Features of Claude Agent SDK
๐ Staring at a blank screen while the agent works? Real-time streaming fixes that!
Enable `include_partial_messages` to receive text and tool call chunks as they're generated.
๐ Title: Real-Time Partial Messages
๐ URL:
๐งฉ Overview
Setting `include_partial_messages` (Python) / `includePartialMessages` (TypeScript) to `true` causes the SDK to emit `StreamEvent` messages alongside regular `AssistantMessage` objects. `StreamEvent` contains raw Claude API streaming events โ `text_delta` for text chunks and `input_json_delta` for tool input fragments. This enables responsive UIs with typing-style text display and tool execution status indicators.
๐ How to Use
```python
# Python - Display text chunks in real time
from claude_agent_sdk import query, ClaudeAgentOptions
from claude_agent_sdk.types import StreamEvent
options = ClaudeAgentOptions(include_partial_messages=True)
async for message in query(prompt="Explain how databases work", options=options):
if isinstance(message, StreamEvent):
event = message.event
if event.get("type") == "content_block_delta":
delta = event.get("delta", {})
if delta.get("type") == "text_delta":
print(delta.get("text", ""), end="", flush=True)
```
```typescript
// TypeScript - Stream tool calls with status indicators
import { query } from "
@anthropic-ai/claude-agent-sdk";
let currentTool: string | null = null;
for await (const message of query({
prompt: "Read the README.md file",
options: { includePartialMessages: true }
})) {
if (message.type === "stream_event") {
const event = message.event;
if (event.type === "content_block_start" && event.content_block.type === "tool_use") {
currentTool = event.content_block.name;
process.stdout.write(`\n[Using ${currentTool}...]`);
} else if (event.type === "content_block_delta" && === "text_delta") {
process.stdout.write(
} else if (event.type === "content_block_stop" && currentTool) {
console.log(" done");
currentTool = null;
}
}
}
```
๐ Integration into Production Systems
- Append `text_delta` chunks to message bubbles in chat UIs for typing-style rendering
- Detect tool names from `content_block_start` (type: `tool_use`) events and show "running..." spinners
- Track message boundaries with `message_start`/`message_stop` events
- Text deltas must be accumulated manually โ prepare an accumulator buffer
๐ก Use Cases
๐ฌ Implement ChatGPT-style real-time typing display in custom UIs
๐ง Show the currently active tool name and progress in a status bar
๐ Start displaying long analysis results before the full response is complete
โ ๏ธ Caveats
- `StreamEvent` events are raw Claude API events, not accumulated text โ you must concatenate text deltas yourself
- Structured output (`structured_output`) is not sent as streaming deltas; it only appears in the final `ResultMessage`
- UI state management is needed โ e.g., pause text streaming while a tool is executing (track an `in_tool` flag)
โจ No more "Processing, please wait..." screens. Partial messages bring users closer to the agent's work in real time!
#
ClaudeAgentSDK# #
AIAgent#