Crate cc_sdk

Source
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 query function
  • 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§

AssistantContent
Assistant content structure for internal use
AssistantMessage
Assistant message content
ClaudeCodeOptions
Configuration options for Claude Code SDK
ClaudeCodeOptionsBuilder
Builder for ClaudeCodeOptions
ClaudeSDKClient
Interactive client for bidirectional communication with Claude
ClaudeSDKClientWorking
Working interactive client
InteractiveClient
Interactive client for stateful conversations with Claude
MessageBatcher
Message batcher for efficient processing
OptimizedClient
Optimized client with improved performance characteristics
PerformanceMetrics
Performance metrics collector
RetryConfig
Configuration for retry logic
SimpleInteractiveClient
Interactive client for stateful conversations with Claude
TextContent
Text content block
ThinkingContent
Thinking content block
ToolResultContent
Tool result content block
ToolUseContent
Tool use content block
UserContent
User content structure for internal use
UserMessage
User message content

Enums§

ClientMode
Client mode for different usage patterns
ContentBlock
Content block types
ContentValue
Content value for tool results
ControlRequest
Control request types
ControlResponse
Control response types
McpServerConfig
MCP (Model Context Protocol) server configuration
Message
Main message type enum
PermissionMode
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§

ClaudeSDKClientDefault
Default interactive client - the recommended client for interactive use
Result
Result type alias for SDK operations