Choosing between query() and ClaudeSDKClient
The Python SDK provides two ways to interact with Claude Code:
| Feature | query() | ClaudeSDKClient |
|---|---|---|
| Session | Creates a new session by default | Reuses same session |
| Conversation | Single exchange | Multiple exchanges in same context |
| Connection | Managed automatically | Manual control |
| Streaming Input | ✅ Supported | ✅ Supported |
| Interrupts | ❌ Not supported | ✅ Supported |
| Hooks | ✅ Supported | ✅ Supported |
| Custom Tools | ✅ Supported | ✅ Supported |
| Continue Chat | Manual via continue_conversation or resume | ✅ Automatic |
| Use Case | One-off tasks | Continuous conversations |
Use ClaudeSDKClient for interactive applications such as chat interfaces, or when the next action depends on Claude's response.