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 model_recommendation::ModelRecommendation;pub use token_tracker::BudgetLimit;pub use token_tracker::BudgetManager;pub use token_tracker::BudgetStatus;pub use token_tracker::TokenUsageTracker;pub use types::ResultMessage;pub use types::SystemMessage;pub use transport::SubprocessTransport;
Modules§
- model_
recommendation - Model selection recommendations for token optimization
- prelude
- Prelude module for convenient imports
- token_
tracker - Token usage tracking and budget management
- transport
- Transport layer abstractions
Macros§
- tool
- Macro to define a tool with a simple syntax
Structs§
- Agent
Definition - Agent definition for programmatic agents
- Assistant
Content - Assistant content structure for internal use
- Assistant
Message - Assistant message content
- Async
HookJSON Output - Async hook output for deferred execution
- Base
Hook Input - Base hook input fields present across many hook events
- 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
- Hook
Context - Hook context
- Hook
Matcher - Hook matcher configuration
- 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
- Permission
Result Allow - Permission result - Allow
- Permission
Result Deny - Permission result - Deny
- Permission
Rule Value - Permission rule value
- Permission
Update - Permission update
- Post
Tool UseHook Input - Input data for PostToolUse hook events
- Post
Tool UseHook Specific Output - Hook-specific output for PostToolUse events
- PreCompact
Hook Input - Input data for PreCompact hook events
- PreTool
UseHook Input - Input data for PreToolUse hook events
- PreTool
UseHook Specific Output - Hook-specific output for PreToolUse events
- Query
- Internal query handler with control protocol support
- Retry
Config - Configuration for retry logic
- SDKControl
Initialize Request - SDK Control Protocol - Initialize request
- SDKControl
Interrupt Request - SDK Control Protocol - Interrupt request
- SDKControl
McpMessage Request - SDK Control Protocol - MCP message request
- SDKControl
Permission Request - SDK Control Protocol - Permission request
- SDKControl
SetPermission Mode Request - SDK Control Protocol - Set permission mode request
- SDKHook
Callback Request - SDK Hook callback request
- SdkMcp
Server - SDK MCP Server
- SdkMcp
Server Builder - Builder for creating SDK MCP servers
- Session
Start Hook Specific Output - Hook-specific output for SessionStart events
- Simple
Interactive Client - Interactive client for stateful conversations with Claude
- Stop
Hook Input - Input data for Stop hook events
- Subagent
Stop Hook Input - Input data for SubagentStop hook events
- Sync
HookJSON Output - Synchronous hook output with control and decision fields
- Text
Content - Text content block
- Thinking
Content - Thinking content block
- Tool
Definition - Tool definition
- Tool
Input Schema - Tool input schema definition
- Tool
Permission Context - Tool permission context
- Tool
Result - Tool execution result
- 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
- User
Prompt Submit Hook Input - Input data for UserPromptSubmit hook events
- User
Prompt Submit Hook Specific Output - Hook-specific output for UserPromptSubmit events
Enums§
- Client
Mode - Client mode for different usage patterns
- Content
Block - Content block types
- Content
Value - Content value for tool results
- Control
Protocol Format - Control protocol format for sending messages
- Control
Request - Control request types (legacy, keeping for compatibility)
- Control
Response - Control response types (legacy, keeping for compatibility)
- Hook
Input - Union type for all hook inputs (discriminated by hook_event_name)
- HookJSON
Output - Union type for hook outputs
- Hook
Specific Output - Union type for hook-specific outputs (discriminated by hookEventName)
- McpServer
Config - MCP (Model Context Protocol) server configuration
- Message
- Main message type enum
- Permission
Behavior - Permission behavior
- Permission
Mode - Permission mode for tool execution
- Permission
Result - Permission result
- Permission
Update Destination - Permission update destination
- Permission
Update Type - Permission update type
- SDKControl
Request - SDK Control Protocol request types
- SdkError
- Main error type for the Claude Code SDK
- SdkTool
Result Content - Tool result content types
- Setting
Source - Setting source for configuration loading
- System
Prompt - System prompt configuration
Traits§
- CanUse
Tool - Tool permission callback trait
- Hook
Callback - Hook callback trait with strongly-typed inputs and outputs
- Tool
Handler - Tool handler trait
Functions§
- create_
simple_ tool - Helper function to create a simple text-based tool
- query
- Query Claude Code for one-shot or unidirectional streaming interactions.
Type Aliases§
- Claude
Agent Options - Alias for ClaudeCodeOptions (matches Python SDK naming)
- Claude
Agent Options Builder - Alias for ClaudeCodeOptionsBuilder (matches Python SDK naming)
- ClaudeSDK
Client Default - Default interactive client - the recommended client for interactive use
- Result
- Result type alias for SDK operations