Expand description
§Claude Code SDK for Rust
A Rust SDK for interacting with the Claude Code CLI, providing both simple query and interactive client interfaces.
§Features
- Simple Query Interface: One-shot queries with the
queryfunction - Interactive Client: Stateful conversations with
ClaudeSDKClient - Streaming Support: Async streaming of responses
- Type Safety: Strongly typed messages and errors
- Flexible Configuration: Extensive options for customization
§Quick Start
use cc_sdk::{query, Result};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<()> {
let mut messages = query("What is 2 + 2?", None).await?;
while let Some(msg) = messages.next().await {
println!("{:?}", msg?);
}
Ok(())
}Re-exports§
pub use types::ResultMessage;pub use types::SystemMessage;
Modules§
- prelude
- Prelude module for convenient imports
Structs§
- Assistant
Content - Assistant content structure for internal use
- Assistant
Message - Assistant message content
- Claude
Code Options - Configuration options for Claude Code SDK
- Claude
Code Options Builder - Builder for ClaudeCodeOptions
- ClaudeSDK
Client - Interactive client for bidirectional communication with Claude
- ClaudeSDK
Client Working - Working interactive client
- Interactive
Client - Interactive client for stateful conversations with Claude
- Message
Batcher - Message batcher for efficient processing
- Optimized
Client - Optimized client with improved performance characteristics
- Performance
Metrics - Performance metrics collector
- Retry
Config - Configuration for retry logic
- Simple
Interactive Client - Interactive client for stateful conversations with Claude
- Text
Content - Text content block
- Thinking
Content - Thinking content block
- Tool
Result Content - Tool result content block
- Tool
UseContent - Tool use content block
- User
Content - User content structure for internal use
- User
Message - User message content
Enums§
- Client
Mode - Client mode for different usage patterns
- Content
Block - Content block types
- Content
Value - Content value for tool results
- Control
Request - Control request types
- Control
Response - Control response types
- McpServer
Config - MCP (Model Context Protocol) server configuration
- Message
- Main message type enum
- Permission
Mode - Permission mode for tool execution
- SdkError
- Main error type for the Claude Code SDK
Functions§
- query
- Query Claude Code for one-shot or unidirectional streaming interactions.
Type Aliases§
- ClaudeSDK
Client Default - Default interactive client - the recommended client for interactive use
- Result
- Result type alias for SDK operations