Skip to main content

Overview

The Claude Agent SDK supports two distinct input modes for interacting with agents:
  • Streaming Input Mode (Default & Recommended) - A persistent, interactive session
  • Single Message Input - One-shot queries that use session state and resuming
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

Benefits

Image Uploads

Attach images directly to messages for visual analysis and understanding

Queued Messages

Send multiple messages that process sequentially, with ability to interrupt

Tool Integration

Full access to all tools and custom MCP servers during the session

Real-time Feedback

See responses as they’re generated, not just final results

Context Persistence

Maintain conversation context across multiple turns naturally

Implementation Example

These examples read an image named diagram.png from the working directory. Create one there first, or change the filename to point at your own image.
When you run the example, the TypeScript version prints each response as it completes. The Python version’s receive_response() loop ends at the first result message, so it prints the security analysis; to read both responses, use one query() and receive_response() pair per message as shown in the Python reference’s example of continuing a conversation.
In the TypeScript SDK, if your message generator throws, for example when a file it reads is missing, the stream ends with an error that reads Claude Code process aborted by user instead of the original error, so check the code inside your generator first when you see that message. The error may also be preceded by a long minified line of bundled SDK source, so read to the end of the output for the error text.In the Python SDK, a generator exception is logged at debug level and the session stalls without raising, so if a streaming session hangs with no output, enable debug logging and check your generator.

Single Message Input

Single message input is simpler but more limited.

When to Use Single Message Input

Use single message input when:
  • You need a one-shot response
  • You do not need image attachments or mid-session control methods
  • You need to operate in a stateless environment, such as a lambda function

Limitations

Single message input mode does not support:
  • Direct image attachments in messages
  • Dynamic message queueing
  • Real-time interruption
  • Natural multi-turn conversations
If a query ends with an error result, such as error_max_turns, a single message query() call raises an error that includes the failure text after yielding the final result message, so wrap the loop in a try block if your code needs to continue. See Handle the result for the result subtypes.

Implementation Example

When you run the example, each query prints its final result text: first the authentication explanation, then the authorization explanation.