Claude SDK for Rust
A native Rust implementation of the Claude API client with streaming support, tool execution, and programmatic tool calling.
Features
- ✅ Non-streaming API - Send messages and get complete responses
- ✅ Streaming API - Stream responses with Server-Sent Events in real-time
- 🚧 Tool Use - Define and execute tools with programmatic calling (coming soon)
- 🚧 Prompt Caching - Reduce costs with prompt caching support (coming soon)
- 🚧 AWS Bedrock - Support for Claude models via AWS Bedrock (coming soon)
- 🦀 Idiomatic Rust - Type-safe, async/await, zero-cost abstractions
- 📦 Standalone - No FFI, no subprocesses, pure Rust
Quick Start
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Basic Usage
use ;
async
Streaming Responses
use ;
use StreamExt;
async
Examples
Run the examples with your API key:
Available examples:
simple_chat- Basic message sending with complete responsesstreaming_chat- Real-time streaming responses with token display
Supported Models
claude-3-5-sonnet-20241022- Most capable, balanced performanceclaude-3-5-haiku-20241022- Fast and cost-effectiveclaude-3-opus-20240229- Most powerful for complex tasks
API Coverage
✅ Implemented
- Basic message sending
- Streaming responses with SSE
- Request/response types
- Error handling
- Authentication
- Token usage tracking
- Model registry with constraints
- Bedrock regional/global endpoints
🚧 In Progress
- Tool definitions
- Tool use and results
- Multi-turn conversations
- Prompt caching
📋 Planned
- AWS Bedrock client support
- Token counting
- Retry logic with backoff
- Interactive REPL
Development Status
Phase 1 (Foundation) - COMPLETE ✅
- Non-streaming API
- Streaming API with SSE
- Model registry with all Claude 4.5/4.x/3.x models
- Comprehensive error handling
Phase 2 (Tools) - In Progress 🚧
- Tool definitions and execution
- Multi-turn conversations
- Prompt caching
See .claude/system/features.json for detailed feature tracking.
Project Structure
claude-agent-sdk-rust/
├── src/
│ ├── lib.rs # Public API
│ ├── client.rs # HTTP client
│ ├── types.rs # Request/response types
│ └── error.rs # Error types
├── examples/
│ └── simple_chat.rs # Example usage
└── .claude/
└── system/ # Development tracking
Development Setup
Install Git Hooks
We use pre-commit hooks to ensure code quality. Install them with:
The pre-commit hook automatically runs:
cargo test- All tests must passcargo clippy -- -D warnings- No clippy warnings allowedcargo fmt --check- Code must be formattedcargo doc- Documentation must build
To bypass the hook (not recommended): git commit --no-verify
Running Checks Manually
# Run all checks
# Auto-fix formatting
Developer Tools
Automated Changelog Generation:
Use Claude to generate changelog entries from git commits:
This analyzes commits since the last release and generates Keep a Changelog format entries.
Contributing
This project is part of Colony Shell (F015 - Claude ADK integration) but can be used standalone.
See CONTRIBUTING.md for development guidelines.
Design Principles
- Native Rust - No FFI, no subprocess, pure Rust
- Type-safe - Leverage Rust's type system
- Async-first - Built on tokio
- API-compliant - Match official Claude API exactly
- Zero-copy - Minimize allocations where possible
License
MIT