1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//! # Claude Agents SDK
//!
//! A Rust SDK for building agents that interact with the Claude Code CLI.
//!
//! This SDK provides two main entry points:
//!
//! - [`query`]: One-shot, unidirectional queries that return an async stream of messages
//! - [`ClaudeClient`]: Full bidirectional client with control protocol support
//!
//! ## Quick Start
//!
//! ### Simple Query
//!
//! ```rust,no_run
//! use claude_agents_sdk::{query, ClaudeAgentOptions, Message};
//! use tokio_stream::StreamExt;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let options = ClaudeAgentOptions::new()
//! .with_max_turns(3);
//!
//! let mut stream = query("What is 2 + 2?", Some(options), None).await?;
//!
//! while let Some(message) = stream.next().await {
//! match message? {
//! Message::Assistant(msg) => print!("{}", msg.text()),
//! Message::Result(result) => {
//! println!("\nCost: ${:.4}", result.total_cost_usd.unwrap_or(0.0));
//! }
//! _ => {}
//! }
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Bidirectional Client
//!
//! ```rust,no_run
//! use claude_agents_sdk::ClaudeClient;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut client = ClaudeClient::new(None, None);
//! client.connect().await?;
//!
//! // First query
//! client.query("What is the capital of France?").await?;
//! let (response, _) = client.receive_response().await?;
//! println!("Response: {}", response);
//!
//! // Follow-up query (maintains context)
//! client.query("What's its population?").await?;
//! let (response, _) = client.receive_response().await?;
//! println!("Response: {}", response);
//!
//! client.disconnect().await?;
//! Ok(())
//! }
//! ```
//!
//! ## Tool Permission Callbacks
//!
//! Control which tools Claude can use by providing a permission callback:
//!
//! ```rust,no_run
//! use claude_agents_sdk::{ClaudeClientBuilder, PermissionResult, PermissionMode};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut client = ClaudeClientBuilder::new()
//! .permission_mode(PermissionMode::Default)
//! .can_use_tool(|tool_name, input, _ctx| async move {
//! println!("Tool requested: {} with {:?}", tool_name, input);
//!
//! // Allow Read, deny dangerous Bash commands
//! if tool_name == "Bash" {
//! if let Some(cmd) = input.get("command").and_then(|v| v.as_str()) {
//! if cmd.contains("rm -rf") {
//! return PermissionResult::deny_with_message("Dangerous command");
//! }
//! }
//! }
//!
//! PermissionResult::allow()
//! })
//! .build();
//!
//! client.connect().await?;
//! // ... use client
//! Ok(())
//! }
//! ```
//!
//! ## Error Handling
//!
//! The SDK provides [`ClaudeSDKError`] for comprehensive error handling:
//!
//! ```rust,no_run
//! use claude_agents_sdk::{query, ClaudeAgentOptions, ClaudeSDKError, PermissionMode};
//!
//! #[tokio::main]
//! async fn main() {
//! let options = ClaudeAgentOptions::new()
//! .with_permission_mode(PermissionMode::Default)
//! .with_timeout_secs(30);
//!
//! match query("Hello", Some(options), None).await {
//! Ok(stream) => {
//! // Process stream...
//! }
//! Err(ClaudeSDKError::CLINotFound { message }) => {
//! eprintln!("Claude CLI not installed: {}", message);
//! }
//! Err(ClaudeSDKError::Timeout { duration_ms }) => {
//! eprintln!("Operation timed out after {}ms", duration_ms);
//! }
//! Err(e) => {
//! eprintln!("Error: {}", e);
//! }
//! }
//! }
//! ```
//!
//! ## Configuration Options
//!
//! Configure queries with [`ClaudeAgentOptions`]:
//!
//! ```rust
//! use claude_agents_sdk::{ClaudeAgentOptions, PermissionMode};
//!
//! let options = ClaudeAgentOptions::new()
//! .with_model("claude-sonnet-4-20250514")
//! .with_system_prompt("You are a helpful coding assistant.")
//! .with_max_turns(10)
//! .with_permission_mode(PermissionMode::AcceptEdits)
//! .with_allowed_tools(vec!["Read".into(), "Write".into()])
//! .with_timeout_secs(60);
//! ```
//!
//! ## Feature Flags
//!
//! - **default**: Core SDK functionality
//! - **mcp**: Enables MCP (Model Context Protocol) tool support for defining custom tools
// Re-export public API
pub use ;
pub use *;
pub use ;
pub use *;
// Re-export MCP tools when feature enabled
pub use ;
/// SDK version
pub const VERSION: &str = env!;
/// Minimum required Claude CLI version
pub const MIN_CLI_VERSION: &str = "2.0.0";