claude-agent-rs
Claude Code CLI Compatible Rust SDK
English | 한국어
Why claude-agent-rs?
| claude-agent-rs | Other SDKs | |
|---|---|---|
| No Node.js dependency | O | X |
| Reuse Claude Code CLI auth | O | X |
| Auto Prompt Caching | O | Manual |
| TOCTOU-Safe file ops | O | X |
| Multi-cloud | Bedrock, Vertex, Foundry | Limited |
Quick Start
Installation
[]
= "0.2"
= { = "1", = ["full"] }
One-shot Query
use query;
async
Streaming Response
use stream;
use StreamExt;
use pin;
async
Agent Workflow
use ;
use StreamExt;
use pin;
async
Authentication
Claude Code CLI (Recommended)
let agent = builder
.from_claude_code // Automatically use OAuth token
.build
.await?;
API Key
let agent = builder
.api_key
.build
.await?;
Cloud Providers
// AWS Bedrock
let agent = builder.bedrock.build.await?;
// Google Vertex AI
let agent = builder.vertex.build.await?;
// Azure AI Foundry
let agent = builder.foundry.build.await?;
See: Authentication Guide | Cloud Providers
Tools
12 Built-in Tools
| Category | Tools | Description |
|---|---|---|
| File | Read, Write, Edit, Glob, Grep | File system operations |
| Execution | Bash, KillShell | Shell command execution |
| Agent | Task, TaskOutput, TodoWrite, Skill | Agent orchestration |
| Planning | Plan | Structured planning workflow |
2 Server Tools (Anthropic API)
| Tool | Description | Enable |
|---|---|---|
| WebFetch | Fetch URL content | .with_web_fetch() |
| WebSearch | Web search | .with_web_search() |
Tool Access Control
all // All tools
only // Specific tools only
except // Exclude specific tools
See: Tools Guide
Key Features
Prompt Caching
Automatic system prompt caching for up to 90% token cost savings.
// Auto-enabled with from_claude_code
// Or manual configuration
let agent = builder
.cache_static_context
.build
.await?;
Skills System
.claude/commands/deploy.md:
description: Production deployment
allowed-tools: [Bash, Read]
Deploy to $ARGUMENTS environment.
Programmatic registration:
let skill = new
.with_trigger
.with_allowed_tools;
let agent = builder
.skill
.build
.await?;
See: Skills Guide
Subagents
Specialized agents running in isolated contexts:
| Type | Purpose | Model |
|---|---|---|
explore |
Codebase exploration | Haiku |
plan |
Implementation planning | Primary |
general |
General complex tasks | Primary |
See: Subagents Guide
Memory System
Auto-loads CLAUDE.md files for project context:
@import ./docs/architecture.md
-
See: Memory System Guide
Security
| Feature | Description |
|---|---|
| OS Sandbox | Landlock (Linux), Seatbelt (macOS) |
| TOCTOU-Safe | openat() + O_NOFOLLOW file operations |
| Bash AST Analysis | tree-sitter based dangerous command detection |
| Resource Limits | setrlimit() based process isolation |
See: Security Guide | Sandbox Guide
Documentation
| Document | Description |
|---|---|
| Architecture | Overall system structure |
| Authentication | OAuth, API Key, cloud integration |
| Tools | 12 built-in tools + 2 server tools |
| Skills | Skills system and slash commands |
| Subagents | Subagent system |
| Memory | CLAUDE.md, @import |
| Hooks | 10 event types, Pre/Post hooks |
| MCP | External MCP server integration |
| Session | Prompt Caching, context compaction |
| Permissions | Permission modes and policies |
| Security | TOCTOU-safe, Bash AST |
| Sandbox | Landlock, Seatbelt |
| Budget | Cost limits, tenant management |
| Observability | OpenTelemetry, metrics |
| Output Styles | Response format customization |
| Cloud Providers | Bedrock, Vertex, Foundry |
Examples
# Core SDK test
# Advanced features test
# All tools test
# Server tools (WebFetch, WebSearch)
# Files API
Environment Variables
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY |
API key |
ANTHROPIC_MODEL |
Default model |
CLAUDE_CODE_USE_BEDROCK |
Enable AWS Bedrock |
CLAUDE_CODE_USE_VERTEX |
Enable Google Vertex AI |
CLAUDE_CODE_USE_FOUNDRY |
Enable Azure Foundry |
Testing
License
MIT or Apache-2.0 (at your option)