| Crates.io | anthropic-agent-sdk |
| lib.rs | anthropic-agent-sdk |
| version | 0.2.75 |
| created_at | 2025-12-07 21:58:38.608777+00 |
| updated_at | 2025-12-23 01:53:21.805862+00 |
| description | Rust SDK for Claude Code CLI - streaming queries, hooks, permissions, and MCP integration |
| homepage | |
| repository | https://github.com/bartolli/anthropic-agent-sdk |
| max_upload_size | |
| id | 1972333 |
| size | 817,374 |
Rust SDK for building AI agents powered by Claude Code. Mirrors the TypeScript Claude Agent SDK with idiomatic Rust patterns.
Prerequisites:
npm install -g @anthropic-ai/claude-code[dependencies]
anthropic-agent-sdk = "0.2"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
use anthropic_agent_sdk::{query, Message, ContentBlock, StreamExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let stream = query("What is 2 + 2?", None).await?;
let mut stream = Box::pin(stream);
while let Some(message) = stream.next().await {
if let Message::Assistant { message, .. } = message? {
for block in &message.content {
if let ContentBlock::Text { text } = block {
println!("{}", text);
}
}
}
}
Ok(())
}
# Core functionality
cargo run --example simple_query
cargo run --example convenience_methods
cargo run --example bidirectional_demo
cargo run --example message_queue_demo
cargo run --example session_binding_demo
cargo run --example interactive_client
# Hooks and permissions
cargo run --example hooks_demo
cargo run --example permissions_demo
cargo run --example hooks_lifecycle_test
# Introspection and runtime
cargo run --example introspection_demo
cargo run --example result_fields_demo
cargo run --example runtime_setters_demo
# Security
cargo run --example security_demo
# OAuth authentication
cargo run --example oauth_demo
cargo run --example oauth_demo -- status
cargo run --example oauth_demo -- logout
# Structured output
cargo run --example structured_output_demo
# MCP (requires --features rmcp for mcp_server)
cargo run --example mcp_integration
cargo run --example mcp_server --features rmcp
| Event | TypeScript | Rust SDK |
|---|---|---|
| PreToolUse | ✓ | ✓ |
| PostToolUse | ✓ | ✓ |
| PostToolUseFailure | ✓ | ✓ |
| Notification | ✓ | ✓ |
| UserPromptSubmit | ✓ | ✓ |
| SessionStart | ✓ | ✓ |
| SessionEnd | ✓ | ✓ |
| Stop | ✓ | ✓ |
| SubagentStart | ✓ | ✓ |
| SubagentStop | ✓ | ✓ |
| PreCompact | ✓ | ✓ |
| PermissionRequest | ✓ | ✓ |
| Method | TypeScript | Rust SDK |
|---|---|---|
| interrupt() | ✓ | ✓ |
| setPermissionMode() | ✓ | ✓ |
| setModel() | ✓ | ✓ |
| setMaxThinkingTokens() | ✓ | ✓ |
| supportedCommands() | ✓ | ✓ |
| supportedModels() | ✓ | ✓ |
| mcpServerStatus() | ✓ | ✓ |
| accountInfo() | ✓ | ✓ |
| Option | TypeScript | Rust SDK |
|---|---|---|
| allowedTools | ✓ | ✓ |
| disallowedTools | ✓ | ✓ |
| systemPrompt | ✓ | ✓ |
| mcpServers | ✓ | ✓ |
| permissionMode | ✓ | ✓ |
| canUseTool | ✓ | ✓ |
| hooks | ✓ | ✓ |
| agents | ✓ | ✓ |
| maxTurns | ✓ | ✓ |
| model | ✓ | ✓ |
| cwd | ✓ | ✓ |
| env | ✓ | ✓ |
| resume | ✓ | ✓ |
| forkSession | ✓ | ✓ |
| settingSources | ✓ | ✓ |
| maxBudgetUsd | ✓ | ✓ |
| maxThinkingTokens | ✓ | ✓ |
| fallbackModel | ✓ | ✓ |
| outputFormat | ✓ | ✓ |
| sandbox | ✓ | ✓ |
| plugins | ✓ | ✓ |
| betas | ✓ | ✓ |
| strictMcpConfig | ✓ | ✓ |
| resumeSessionAt | ✓ | ✓ |
| allowDangerouslySkipPermissions | ✓ | ✓ |
| pathToClaudeCodeExecutable | ✓ | ✓ |
| stderr | ✓ | ✓ |
| tools (preset) | ✓ | ✓ |
| enableFileCheckpointing | ✓ | ✓ |
| sessionId | ✓ | ✓ |
| Type | TypeScript | Rust SDK |
|---|---|---|
| stdio | ✓ | ✓ |
| sse | ✓ | ✓ |
| http | ✓ | ✓ |
| sdk (in-process) | ✓ | ✓ |
| Field | TypeScript | Rust SDK |
|---|---|---|
| modelUsage | ✓ | ✓ |
| permission_denials | ✓ | ✓ |
| structured_output | ✓ | ✓ |
| errors | ✓ | ✓ |
cargo build
cargo test
cargo clippy
cargo doc --open
The SDK implements strict security measures:
See SECURITY.md for full documentation.
For Claude Max/Pro subscribers, authenticate without API keys:
use anthropic_agent_sdk::auth::OAuthClient;
let client = OAuthClient::new()?;
let token = client.authenticate().await?;
// Token is cached in platform-specific config directory
See oauth_demo example for full usage including status check and logout.
MIT