Streams Claude Agent SDK output to a UI, covering partial messages, stream_event deltas for text and tool input, subagent attribution, and cut-off handling. Useful for building real-time chat or progress UIs.
Ships in agent-sdk. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
By default the Agent SDK yields a complete assistant message per content block. Turn on partial messages to receive raw Claude API stream events as tokens arrive, then render text and tool activity yourself.
Without partial messages you still get a useful stream of whole messages:
| Message | TypeScript check | Python type |
|---|---|---|
| Session init | type === "system" && subtype === "init" | SystemMessage |
| Complete content block | type === "assistant" (content at message.message.content) | AssistantMessage (content at message.content) |
| Final outcome | type === "result" | ResultMessage |
Each non-empty content block arrives as its own assistant message; a response with text and a tool call yields two assistant messages that share a message ID. If one progress line per tool call is enough, you may not need partial messages at all.
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Find all TODO comments in the codebase",
options: { includePartialMessages: true, allowedTools: ["Read", "Grep"] },
})) {
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);
}
} else if (message.type === "result") {
console.log(`\n[${message.subtype}]`);
}
}
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
from claude_agent_sdk.types import StreamEvent
async for message in query(
prompt="Find all TODO comments in the codebase",
options=ClaudeAgentOptions(include_partial_messages=True, allowed_tools=["Read", "Grep"]),
):
if isinstance(message, StreamEvent):
event = message.event
if event.get("type") == "content_block_delta" and event.get("delta", {}).get("type") == "text_delta":
print(event["delta"].get("text", ""), end="", flush=True)
elif isinstance(message, ResultMessage):
print(f"\n[{message.subtype}]")
The wrapper type is SDKPartialAssistantMessage (type: "stream_event") in TypeScript and StreamEvent in Python. Its event field is a raw Claude API streaming event, not accumulated text: you accumulate deltas yourself.
Track content_block_start for tool_use blocks, accumulate input_json_delta.partial_json, and finalize on content_block_stop.
let currentTool: string | null = null;
let toolInput = "";
if (message.type === "stream_event") {
const e = message.event;
if (e.type === "content_block_start" && e.content_block.type === "tool_use") {
currentTool = e.content_block.name;
toolInput = "";
ui.showToolStarted(currentTool);
} else if (e.type === "content_block_delta" && e.delta.type === "input_json_delta") {
toolInput += e.delta.partial_json;
} else if (e.type === "content_block_stop" && currentTool) {
ui.showToolInput(currentTool, toolInput);
currentTool = null;
}
}
Partial JSON is unvalidated until the block completes. Do not act on it.
With partial messages on, the docs describe this order per block: content_block_start, the deltas, then the complete assistant message, then content_block_stop; then message_delta and message_stop, tool execution, more events for the next turn, and finally the result. Render from deltas for responsiveness, but treat the complete assistant message as the source of truth.
Stream events are emitted for the main session only; token-level deltas from subagents are not forwarded, and parent_tool_use_id on stream events is always null. To show subagent progress, use the complete messages, which carry parent_tool_use_id (see sub-agent-delegation).
An interrupted turn, a dropped connection, or a fallback to a non-streaming request can cut a message short. The docs say you still receive message_stop, but content_block_stop (for an open tool call) and message_delta may be missing. If message_stop arrives while a tool block is open, treat that tool input as incomplete, and do not wait for message_delta on a cut message. Older SDK versions could end a turn without message_stop; upgrade if replies stay marked as in progress.
With structured output, the JSON streams as unvalidated input_json_delta chunks of a tool call; only the validated value reaches the final result's structured_output.
message_stop and on the final resultWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
5 skills in this plugin
/agent-sdk-quickstartBuild a first agent with the Claude Agent SDK (TypeScript or Python): install, run query(), read result messages, restrict tools and permissions, add custom tools through an in-process MCP server, and guard tool calls with hooks. Also explains when to pick the Agent SDK, the Client SDK, or Managed Agents.
Use this skill when starting a new agent project, migrating from a hand-written messages.create tool loop, or choosing between the Agent SDK, the Client SDK, and Managed Agents.
Activate when: Claude Agent SDK, @anthropic-ai/claude-agent-sdk, claude-agent-sdk, query(), ClaudeAgentOptions, createSdkMcpServer, build agent, agent SDK quickstart.
/managed-agents-apiUse Claude Managed Agents (beta), where Anthropic runs the agent loop and a per-session sandbox: create a versioned agent once, an environment, then sessions that you drive with events over SSE. Covers the correct object model, tool permission policies, custom tools, outcomes, session budgets, data-retention limits, and when to choose it over the Agent SDK.
Use this skill when building hosted, long-running, or scheduled agents on the Claude API, deciding between Managed Agents and the Agent SDK, or fixing code that puts model or tools on the session or calls agents.create on every run.
Activate when: Managed Agents, Claude Managed Agents, /v1/agents, /v1/sessions, /v1/environments, client.beta.agents, client.beta.sessions, sessions.events.stream, agent_toolset, server-side agent.
/session-lifecycleManage agent sessions correctly in both the Claude Agent SDK (local transcripts with continue, resume, and forkSession) and Claude Managed Agents (server-side sessions with idle, running, rescheduling, and terminated states). Covers capturing session IDs, resuming across processes and hosts, forking to explore alternatives, when to start fresh, and retention.
Use this skill when building multi-turn agents, debugging "my agent forgot the earlier context", choosing between continue, resume, fork, or a new session, or designing session retention.
Activate when: agent session, session resume, continue conversation, forkSession, fork_session, session ID, ClaudeSDKClient, Managed Agents session status, session retention.
/sub-agent-delegationDelegate work to subagents in the Claude Agent SDK: define them with the agents option (AgentDefinition), restrict their tools, pass the right context in the Agent tool prompt, detect subagent messages, resume subagents, and cap depth, concurrency, and spend.
Use this skill when parallelizing research or review across subagents, keeping the main context small, giving a subtask specialized instructions or read-only tools, or debugging why Claude does not delegate.
Activate when: subagent, sub-agent, agents option, AgentDefinition, Agent tool, Task tool, parallel agents, delegate to agent, parent_tool_use_id, CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS.
Other plugins' skills for the same job
/agent-sdk:agent-sdk-streamingfrom agent-sdk
npx claudepluginhub latestaiagents/agent-skills --plugin agent-sdk2 plugins in one repository ship this exact skill · first indexed Nov 5, 2026