File: streaming-vs-single-mode.md | Updated: 11/15/2025
Agent Skills are now available! Learn more about extending Claude's capabilities with Agent Skills .
English
Search...
Ctrl K
Search...
Navigation
Guides
Streaming Input
Home Developer Guide API Reference Model Context Protocol (MCP) Resources Release Notes
On this page
The Claude Agent SDK supports two distinct input modes for interacting with agents:
This guide explains the differences, benefits, and use cases for each mode to help you choose the right approach for your application.
Streaming input mode is the preferred way to use the Claude Agent SDK. It provides full access to the agentβs capabilities and enables rich, interactive experiences. It allows the agent to operate as a long lived process that takes in user input, handles interruptions, surfaces permission requests, and handles session management.
How It Works
Environment/File SystemTools/HooksClaude AgentYour ApplicationEnvironment/File SystemTools/HooksClaude AgentYour ApplicationSession stays alivePersistent file systemstate maintainedInitialize with AsyncGeneratorYield Message 1Execute toolsRead filesFile contentsWrite/Edit filesSuccess/ErrorStream partial responseStream more content...Complete Message 1Yield Message 2 + ImageProcess image & executeAccess filesystemOperation resultsStream response 2Queue Message 3Interrupt/CancelHandle interruption
Benefits
Attach images directly to messages for visual analysis and understanding
Send multiple messages that process sequentially, with ability to interrupt
Full access to all tools and custom MCP servers during the session
Use lifecycle hooks to customize behavior at various points
See responses as theyβre generated, not just final results
Maintain conversation context across multiple turns naturally
Implementation Example
TypeScript
Python
Copy
import { query } from "@anthropic-ai/claude-agent-sdk";
import { readFileSync } from "fs";
async function* generateMessages() {
// First message
yield {
type: "user" as const,
message: {
role: "user" as const,
content: "Analyze this codebase for security issues"
}
};
// Wait for conditions or user input
await new Promise(resolve => setTimeout(resolve, 2000));
// Follow-up with image
yield {
type: "user" as const,
message: {
role: "user" as const,
content: [\
{\
type: "text",\
text: "Review this architecture diagram"\
},\
{\
type: "image",\
source: {\
type: "base64",\
media_type: "image/png",\
data: readFileSync("diagram.png", "base64")\
}\
}\
]
}
};
}
// Process streaming responses
for await (const message of query({
prompt: generateMessages(),
options: {
maxTurns: 10,
allowedTools: ["Read", "Grep"]
}
})) {
if (message.type === "result") {
console.log(message.result);
}
}
Single message input is simpler but more limited.
When to Use Single Message Input
Use single message input when:
Limitations
Single message input mode does not support:
Implementation Example
TypeScript
Python
Copy
import { query } from "@anthropic-ai/claude-agent-sdk";
// Simple one-shot query
for await (const message of query({
prompt: "Explain the authentication flow",
options: {
maxTurns: 1,
allowedTools: ["Read", "Grep"]
}
})) {
if (message.type === "result") {
console.log(message.result);
}
}
// Continue conversation with session management
for await (const message of query({
prompt: "Now explain the authorization process",
options: {
continue: true,
maxTurns: 1
}
})) {
if (message.type === "result") {
console.log(message.result);
}
}
Was this page helpful?
YesNo
Python SDK Handling Permissions
Assistant
Responses are generated using AI and may contain mistakes.