Expand description
§claude-agent
Rust SDK for building AI agents with Anthropic’s Claude.
This crate provides a production-ready, memory-efficient way to build AI agents using the Anthropic Messages API directly, without CLI subprocess dependencies.
§Quick Start
use claude_agent::query;
#[tokio::main]
async fn main() -> Result<(), claude_agent::Error> {
let response = query("What is 2 + 2?").await?;
println!("{}", response);
Ok(())
}§Full Agent Example
use claude_agent::{Agent, AgentEvent, ToolAccess};
use futures::StreamExt;
use std::pin::pin;
#[tokio::main]
async fn main() -> Result<(), claude_agent::Error> {
let agent = Agent::builder()
.model("claude-sonnet-4-5")
.tools(ToolAccess::all())
.working_dir("./project")
.build()
.await?;
let stream = agent.execute_stream("Fix the bug").await?;
let mut stream = pin!(stream);
while let Some(event) = stream.next().await {
match event? {
AgentEvent::Text(text) => print!("{}", text),
AgentEvent::Complete(result) => {
println!("Done: {} tokens", result.total_tokens());
}
_ => {}
}
}
Ok(())
}Re-exports§
pub use agent::Agent;pub use agent::AgentBuilder;pub use agent::AgentConfig;pub use agent::AgentEvent;pub use agent::AgentResult;pub use auth::Auth;pub use auth::Credential;pub use client::Client;pub use client::ClientBuilder;pub use permissions::PermissionMode;pub use permissions::PermissionPolicy;pub use tools::ExecutionContext;pub use tools::SchemaTool;pub use tools::Tool;pub use tools::ToolAccess;pub use tools::ToolRegistry;pub use types::ContentBlock;pub use types::Message;pub use types::Role;pub use types::ToolDefinition;pub use types::ToolError;pub use types::ToolOutput;pub use types::ToolResult;pub use agent::AgentMetrics;pub use agent::AgentModelConfig;pub use agent::AgentState;pub use agent::BudgetConfig;pub use agent::CacheConfig;pub use agent::CacheStrategy;pub use agent::ExecutionConfig;pub use agent::PromptConfig;pub use agent::SecurityConfig;pub use agent::SystemPromptMode;pub use agent::ToolStats;pub use auth::CredentialProvider;pub use auth::OAuthConfig;pub use client::BetaConfig;pub use client::BetaFeature;pub use client::CloudProvider;pub use client::EffortLevel;pub use client::FallbackConfig;pub use client::ModelConfig;pub use client::ModelType;pub use client::OutputConfig;pub use client::ProviderConfig;pub use common::ContentSource;pub use common::Index;pub use common::IndexRegistry;pub use common::Named;pub use common::SourceType;pub use common::ToolRestricted;pub use context::ContextBuilder;pub use context::MemoryLoader;pub use context::MemoryProvider;pub use context::PromptOrchestrator;pub use context::RuleIndex;pub use context::StaticContext;pub use hooks::CommandHook;pub use hooks::Hook;pub use hooks::HookContext;pub use hooks::HookEvent;pub use hooks::HookManager;pub use hooks::HookOutput;pub use output_style::OutputStyle;pub use session::Session;pub use session::SessionConfig;pub use session::SessionId;pub use session::SessionManager;pub use session::SessionMessage;pub use session::SessionState;pub use session::ToolState;pub use skills::SkillExecutor;pub use skills::SkillIndex;pub use skills::SkillResult;pub use subagents::SubagentIndex;pub use subagents::builtin_subagents;pub use auth::ClaudeCliProvider;cli-integrationpub use client::BedrockAdapter;awspub use client::FoundryAdapter;azurepub use client::VertexAdapter;gcppub use output_style::OutputStyleLoader;cli-integrationpub use output_style::SystemPromptGenerator;cli-integrationpub use plugins::PluginDescriptor;pluginspub use plugins::PluginDiscovery;pluginspub use plugins::PluginError;pluginspub use plugins::PluginManager;pluginspub use plugins::PluginManifest;pluginspub use subagents::SubagentFrontmatter;cli-integrationpub use subagents::SubagentIndexLoader;cli-integration
Modules§
- agent
- Agent execution engine.
- auth
- Authentication module for Claude API.
- budget
- Tenant-based budget management for API cost control.
- client
- Anthropic API client with multi-provider support.
- common
- config
- Pluggable configuration provider system.
- context
- Context management with progressive disclosure for optimal token usage.
- hooks
- Hook system for intercepting agent execution.
- mcp
- MCP (Model Context Protocol) server integration.
- models
- observability
- Observability module for Claude Agent SDK.
- output_
style - permissions
- Permission system for controlling tool execution.
- plugins
plugins - Plugin system with namespace-based resource management.
- prelude
- Prelude module for convenient imports.
- prompts
- System prompts based on Claude Code CLI.
- security
- Security sandbox system providing TOCTOU-safe file operations and process isolation.
- session
- Session management for stateful conversations.
- skills
- Skill system - Progressive Disclosure pattern implementation.
- subagents
- Subagent system - Progressive Disclosure pattern implementation.
- tokens
- tools
- Built-in tools for the agent.
- types
- Core types for the Claude Agent SDK.
Enums§
- Error
- Error type for claude-agent operations.
- Error
Category - Error category for unified error handling.
Functions§
- query
- Simple query function for one-shot requests
- query_
with_ model - Query with a specific model
- stream
- Stream a response for one-shot requests