Skip to main content
The query() function provides a simple, one-shot way to interact with Claude. It’s perfect for basic tasks and quick interactions.

Basic Example

The simplest way to use the SDK is with a basic question:

Using Custom Options

You can customize Claude’s behavior using ClaudeAgentOptions:
The max_turns option limits the number of conversation turns. Setting it to 1 ensures Claude responds only once.

Using Tools

You can enable specific tools for Claude to use:

Complete Example

Here’s a complete example running all three patterns:

Key Takeaways

  • Use query() for simple, one-shot interactions
  • Iterate over the async generator to receive messages
  • Check message types using isinstance()
  • Configure behavior with ClaudeAgentOptions
  • Enable tools using the allowed_tools parameter

Next Steps

Streaming Mode

Learn about interactive conversations with ClaudeSDKClient

Tool Permissions

Control which tools Claude can use