Skip to main content

claude_code_rs/types/
options.rs

1use std::collections::HashMap;
2use std::path::PathBuf;
3
4use super::agents::AgentDefinition;
5use super::hooks::HookDefinition;
6use super::mcp_config::McpServerConfig;
7use super::permissions::{CanUseToolCallback, PermissionMode};
8use super::sandbox::SandboxSettings;
9
10/// Configuration options for a Claude Agent SDK query or client.
11///
12/// All fields are public with sensible defaults. Use `..Default::default()` for
13/// fields you don't need to set.
14#[derive(Default)]
15pub struct ClaudeAgentOptions {
16    // --- Core ---
17    /// The prompt/message to send. Can be set here or passed to query().
18    pub prompt: Option<String>,
19
20    /// Model to use (e.g. "claude-sonnet-4-20250514").
21    pub model: Option<String>,
22
23    /// System prompt override.
24    pub system_prompt: Option<String>,
25
26    /// Append system prompt (added after default).
27    pub append_system_prompt: Option<String>,
28
29    /// Maximum turns (agentic loops) before stopping.
30    pub max_turns: Option<u32>,
31
32    /// Maximum tokens in the response.
33    pub max_tokens: Option<u32>,
34
35    // --- Session ---
36    /// Resume an existing session by ID.
37    pub session_id: Option<String>,
38
39    /// Continue the most recent session.
40    pub continue_session: bool,
41
42    // --- Working directory ---
43    /// Working directory for the CLI process.
44    pub cwd: Option<PathBuf>,
45
46    // --- Permission ---
47    /// Permission mode for tool usage.
48    pub permission_mode: PermissionMode,
49
50    /// Specific tools to allow (when using AllowedTools mode).
51    pub allowed_tools: Vec<String>,
52
53    /// Custom permission callback.
54    pub can_use_tool: Option<CanUseToolCallback>,
55
56    // --- Hooks ---
57    /// Registered hook definitions.
58    pub hooks: Vec<HookDefinition>,
59
60    // --- MCP ---
61    /// MCP servers to register with the CLI.
62    pub mcp_servers: HashMap<String, McpServerConfig>,
63
64    // --- Agents ---
65    /// Sub-agent definitions.
66    pub agents: Vec<AgentDefinition>,
67
68    // --- Sandbox ---
69    /// Sandbox configuration.
70    pub sandbox: Option<SandboxSettings>,
71
72    // --- CLI flags ---
73    /// Additional environment variables for the CLI process.
74    pub env: HashMap<String, String>,
75
76    /// Verbose output from CLI.
77    pub verbose: bool,
78
79    /// Path to the claude CLI binary (auto-detected if None).
80    pub cli_path: Option<PathBuf>,
81
82    /// Custom CLI arguments (appended after built-in ones).
83    pub extra_cli_args: Vec<String>,
84
85    /// Timeout for the initial connection handshake.
86    pub connect_timeout: Option<std::time::Duration>,
87
88    /// Timeout for control protocol requests.
89    pub control_timeout: Option<std::time::Duration>,
90
91    /// Stderr callback - receives stderr lines from CLI process.
92    pub on_stderr: Option<StderrCallback>,
93
94    /// Disallow use of the prompt cache
95    pub no_cache: bool,
96
97    /// Temperature setting
98    pub temperature: Option<f64>,
99
100    /// Context window fraction (0.0-1.0) to use before summarizing.
101    pub context_window: Option<f64>,
102}
103
104/// Callback for CLI stderr lines.
105pub type StderrCallback =
106    std::sync::Arc<dyn Fn(String) + Send + Sync>;
107
108impl std::fmt::Debug for ClaudeAgentOptions {
109    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110        f.debug_struct("ClaudeAgentOptions")
111            .field("model", &self.model)
112            .field("prompt", &self.prompt.as_ref().map(|p| {
113                if p.len() > 50 { format!("{}...", &p[..50]) } else { p.clone() }
114            }))
115            .field("max_turns", &self.max_turns)
116            .field("session_id", &self.session_id)
117            .field("permission_mode", &self.permission_mode)
118            .field("verbose", &self.verbose)
119            .field("hooks_count", &self.hooks.len())
120            .field("mcp_servers_count", &self.mcp_servers.len())
121            .field("agents_count", &self.agents.len())
122            .finish_non_exhaustive()
123    }
124}