clau.rs 🦀
A type-safe, async-first Rust SDK for Claude Code that transforms the CLI tool into a powerful programmatic API.
Features
- Type-Safe API: Strongly typed request/response models with compile-time safety
- Async/Await: Built on Tokio for efficient async operations
- Raw JSON Access: Full access to Claude CLI responses for maximum flexibility
- Timeout Support: Configurable timeouts for all operations
- Streaming Support: Real-time streaming responses with async iterators
- Session Management: First-class session support with persistence
- MCP Integration: Type-safe Model Context Protocol configuration
- Error Handling: Comprehensive error types with detailed messages
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use ;
async
Advanced Features
Raw JSON Access
Access the complete response with metadata and raw JSON for maximum flexibility:
use ;
let client = builder
.stream_format
.build;
let response = client
.query
.send_full
.await?;
println!;
// Access metadata
if let Some = &response.metadata
// Access raw JSON for custom parsing
if let Some = &response.raw_json
// Serialize the entire response for storage
let json_string = to_string?;
Timeout Configuration
let client = builder
.timeout_secs // 60 second timeout
.build;
Examples
Streaming Responses
use *;
let mut stream = client
.query
.format
.stream
.await?;
while let Some = stream.next.await
Custom Configuration
use ;
let client = builder
.system_prompt
.model
.allowed_tools
.stream_format
.build;
Session Management
let session_manager = new;
let session = session_manager
.create_session
.with_system_prompt
.build
.await?;
// Continue conversation with session ID
let response = client
.query
.session
.send
.await?;
Architecture
The SDK is organized into modular crates:
clau-core: Core types and traitsclau-runtime: Process management and I/Oclau-mcp: MCP protocol implementationclau-macros: Derive macros for custom types
Requirements
- Rust 1.70+
- Claude Code CLI installed and authenticated
License
MIT
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Links
- Documentation <- Not Up Yet
- Repository
- Claude Code