Register and share your invite link to earn from video plays and referrals.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
Joined May 2026
286 Following    468 Followers
# 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#
Show more