claude-agent-rs
Production-Ready Rust SDK for Claude API
English | 한국어
Why claude-agent-rs?
| Feature | claude-agent-rs | Other SDKs |
|---|---|---|
| Pure Rust, No Runtime Dependencies | Native | Node.js/Python required |
| Claude Code CLI Auth Reuse | OAuth token sharing | Manual API key setup |
| Automatic Prompt Caching | System + Message caching | Manual implementation |
| TOCTOU-Safe File Operations | openat() + O_NOFOLLOW |
Standard file I/O |
| Multi-Cloud Support | Bedrock, Vertex, Foundry | Limited or none |
| OS-Level Sandboxing | Landlock, Seatbelt | None |
| 1000+ Tests | Production-proven | Varies |
Quick Start
Installation
[]
= "0.2"
= { = "1", = ["full"] }
Simple Query
use query;
async
Streaming Response
use stream;
use StreamExt;
use pin;
async
Full Agent with Tools
use ;
use StreamExt;
use pin;
async
Authentication
Claude Code CLI (Recommended)
builder
.from_claude_code // Uses ~/.claude/credentials.json
.build
.await?
API Key
use Auth;
builder
.auth.await?
.build
.await?
Cloud Providers
use Auth;
// AWS Bedrock
builder
.auth.await?
.build.await?
// Google Vertex AI
builder
.auth.await?
.build.await?
// Azure AI Foundry
builder
.auth.await?
.build.await?
See: Authentication Guide | Cloud Providers
Tools
12 Built-in Tools
| Category | Tools |
|---|---|
| File | Read, Write, Edit, Glob, Grep |
| Shell | Bash, KillShell |
| Agent | Task, TaskOutput, TodoWrite, Skill |
| Planning | Plan |
2 Server Tools (Anthropic API only)
| Tool | Description |
|---|---|
| WebFetch | Fetch and process URL content |
| WebSearch | Web search with citations |
builder
.with_web_fetch
.with_web_search
Tool Access Control
all // All 12 tools
only // Specific tools
except // Exclude tools
See: Tools Guide
Key Features
Prompt Caching
Automatic caching based on Anthropic best practices:
- System prompt caching: Static context cached automatically
- Message history caching: Last user turn cached for multi-turn efficiency
use CacheConfig;
builder
.cache // Both enabled by default
// .cache(CacheConfig::system_only()) // System prompt only
// .cache(CacheConfig::disabled()) // No caching
3 Built-in Subagents
| Type | Model | Purpose |
|---|---|---|
explore |
Haiku | Fast codebase search |
plan |
Primary | Implementation planning |
general |
Primary | Complex multi-step tasks |
See: Subagents Guide
Skills System
Define reusable skills via markdown:
.claude/skills/deploy.md:
description: Production deployment
allowed-tools: [Bash, Read]
Deploy to $ARGUMENTS environment.
See: Skills Guide
Memory System
Auto-loads CLAUDE.md for project context:
@import ./docs/architecture.md
-
See: Memory System Guide
Session Persistence
| Backend | Feature | Use Case |
|---|---|---|
| Memory | (default) | Development |
| PostgreSQL | postgres |
Production (7 tables) |
| Redis | redis-backend |
High-throughput |
See: Session Guide
Hooks System
10 lifecycle events for execution control:
| Blockable | Non-Blockable |
|---|---|
| PreToolUse | PostToolUse, PostToolUseFailure |
| UserPromptSubmit | Stop, SubagentStart, SubagentStop |
| PreCompact, SessionStart, SessionEnd |
See: Hooks Guide
MCP Integration
use ;
use HashMap;
let mut mcp = new;
mcp.add_server.await?;
builder.mcp_manager.build.await?
See: MCP Guide
Security
| Feature | Description |
|---|---|
| OS Sandbox | Landlock (Linux 5.13+), Seatbelt (macOS) |
| TOCTOU-Safe | openat() + O_NOFOLLOW atomic operations |
| Bash AST | tree-sitter based dangerous command detection |
| Resource Limits | setrlimit() process isolation |
| Network Filter | Domain whitelist/blacklist |
See: Security Guide | Sandbox Guide
Documentation
| Document | Description |
|---|---|
| Architecture | System structure and data flow |
| Authentication | OAuth, API Key, cloud integration |
| Tools | 12 built-in + 2 server tools |
| Skills | Slash commands and skill definitions |
| Subagents | Subagent spawning and management |
| Memory | CLAUDE.md and @import |
| Hooks | 10 lifecycle events |
| MCP | External MCP servers |
| Session | Persistence and prompt caching |
| Permissions | Permission modes and policies |
| Security | TOCTOU-safe operations |
| Sandbox | Landlock and Seatbelt |
| Budget | Token/cost limits |
| Observability | OpenTelemetry integration |
| Output Styles | Response formatting |
| Cloud Providers | Bedrock, Vertex, Foundry |
Feature Flags
[]
= { = "0.2", = ["mcp", "postgres"] }
| Feature | Description |
|---|---|
cli-integration |
Claude Code CLI support (default) |
mcp |
MCP protocol support |
multimedia |
PDF reading support |
aws |
AWS Bedrock |
gcp |
Google Vertex AI |
azure |
Azure AI Foundry |
postgres |
PostgreSQL persistence |
redis-backend |
Redis persistence |
otel |
OpenTelemetry |
full |
All features |
Examples
Environment Variables
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY |
API key |
ANTHROPIC_MODEL |
Default model |
CLAUDE_CODE_USE_BEDROCK |
Enable Bedrock |
CLAUDE_CODE_USE_VERTEX |
Enable Vertex AI |
CLAUDE_CODE_USE_FOUNDRY |
Enable Foundry |
Testing
License
MIT