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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//! # Claude Agent SDK V2 API
//!
//! This module provides a simplified, TypeScript-inspired API for interacting with Claude.
//! The V2 API offers a more ergonomic interface compared to V1, with:
//!
//! - **One-shot prompts**: Simple `prompt()` function for single queries
//! - **Session-based API**: `create_session()` and `resume_session()` for multi-turn conversations
//! - **Simplified options**: `SessionOptions` with only the most commonly used parameters
//! - **TypeScript-style naming**: `prompt`, `send`, `receive` instead of `query`, `query_with_prompt`, `receive_response`
//!
//! ## Quick Start
//!
//! ```no_run
//! use claude_agent_sdk::v2::{prompt, create_session};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // One-shot prompt
//! let result = prompt("What is 2 + 2?", Default::default()).await?;
//! println!("Answer: {}", result.content);
//!
//! // Session-based conversation
//! let mut session = create_session(Default::default()).await?;
//! session.send("Hello, Claude!").await?;
//!
//! for message in session.receive().await? {
//! println!("Message: {:?}", message);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## V1 vs V2 API Comparison
//!
//! ### V1 API (Current/Existing)
//! ```no_run
//! # use claude_agent_sdk::{query, ClaudeClient, ClaudeAgentOptions};
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // One-shot
//! let messages = query("What is 2 + 2?", None).await?;
//!
//! // Session-based
//! let options = ClaudeAgentOptions::builder().build();
//! let mut client = ClaudeClient::new(options);
//! client.connect().await?;
//! client.query("Hello").await?;
//! # Ok(())
//! # }
//! ```
//!
//! ### V2 API (Simplified)
//! ```no_run
//! # use claude_agent_sdk::v2::{prompt, create_session};
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // One-shot
//! let result = prompt("What is 2 + 2?", Default::default()).await?;
//!
//! // Session-based
//! let mut session = create_session(Default::default()).await?;
//! session.send("Hello").await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Key Differences
//!
//! 1. **Simplified Options**: `SessionOptions` has fewer fields than `ClaudeAgentOptions`
//! 2. **Direct Results**: `prompt()` returns `PromptResult` directly, not a stream
//! 3. **TypeScript Naming**: `send/receive` instead of `query/receive_response`
//! 4. **No Connect**: Sessions are auto-connected on creation
//!
//! ## Migration Guide
//!
//! ### From V1 to V2
//!
//! **One-shot queries**:
//! ```rust,ignore
//! // V1
//! let messages = query("Question", None).await?;
//! for msg in messages {
//! if let Message::Assistant(assist_msg) = msg {
//! // process...
//! }
//! }
//!
//! // V2
//! let result = prompt("Question", Default::default()).await?;
//! // result.content has the answer text
//! ```
//!
//! **Session-based**:
//! ```rust,ignore
//! // V1
//! let mut client = ClaudeClient::new(options);
//! client.connect().await?;
//! client.query("Hello").await?;
//! let stream = client.receive_response();
//!
//! // V2
//! let mut session = create_session(Default::default()).await?;
//! session.send("Hello").await?;
//! let messages = session.receive().await?;
//! ```
//!
//! ## Feature Parity
//!
//! V2 provides the same functionality as V1, just with a simpler API. For advanced use cases,
//! you can still use the V1 API directly.
//!
//! - ✅ One-shot queries
//! - ✅ Multi-turn sessions
//! - ✅ Streaming responses
//! - ✅ Permission management
//! - ✅ Cost control
//! - ✅ Custom tools
//! - ✅ Hooks
//! - ✅ Session resumption
pub use ;
pub use ;
use crateResult;
use crateClaudeAgentOptions;
use crateClaudeClient;
/// One-shot prompt API - simplified interface for single queries
///
/// This function sends a single prompt to Claude and returns the complete response.
/// It's the simplest way to interact with Claude for one-off queries.
///
/// # Arguments
///
/// * `prompt` - The prompt text to send to Claude
/// * `options` - Session options (use `Default::default()` for defaults)
///
/// # Returns
///
/// A `PromptResult` containing the response text and metadata
///
/// # Example
///
/// ```no_run
/// use claude_agent_sdk::v2::prompt;
///
/// #[tokio::main]
/// async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let result = prompt("What is 2 + 2?", Default::default()).await?;
/// println!("Claude says: {}", result.content);
/// println!("Used {} tokens", result.input_tokens + result.output_tokens);
/// Ok(())
/// }
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The prompt is empty
/// - Network connection fails
/// - API returns an error
/// - Response parsing fails
pub async