claude_code_rs/types/
options.rs1use 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;
9use crate::transport::cli_discovery;
10
11#[derive(Default)]
16pub struct ClaudeAgentOptions {
17 pub prompt: Option<String>,
20
21 pub model: Option<String>,
23
24 pub system_prompt: Option<String>,
26
27 pub append_system_prompt: Option<String>,
29
30 pub max_turns: Option<u32>,
32
33 pub max_tokens: Option<u32>,
35
36 pub session_id: Option<String>,
39
40 pub continue_session: bool,
42
43 pub cwd: Option<PathBuf>,
46
47 pub permission_mode: PermissionMode,
50
51 pub allowed_tools: Vec<String>,
53
54 pub can_use_tool: Option<CanUseToolCallback>,
56
57 pub hooks: Vec<HookDefinition>,
60
61 pub mcp_servers: HashMap<String, McpServerConfig>,
64
65 pub agents: Vec<AgentDefinition>,
68
69 pub sandbox: Option<SandboxSettings>,
72
73 pub env: HashMap<String, String>,
76
77 pub verbose: bool,
79
80 pub cli_path: Option<PathBuf>,
82
83 pub extra_cli_args: Vec<String>,
85
86 pub connect_timeout: Option<std::time::Duration>,
88
89 pub control_timeout: Option<std::time::Duration>,
91
92 pub on_stderr: Option<StderrCallback>,
94
95 pub no_cache: bool,
97
98 pub temperature: Option<f64>,
100
101 pub context_window: Option<f64>,
103}
104
105pub type StderrCallback =
107 std::sync::Arc<dyn Fn(String) + Send + Sync>;
108
109impl ClaudeAgentOptions {
110 pub fn resolve_cli_path(&self) -> crate::error::Result<PathBuf> {
112 match self.cli_path {
113 Some(ref p) => Ok(p.clone()),
114 None => cli_discovery::find_cli(),
115 }
116 }
117}
118
119impl std::fmt::Debug for ClaudeAgentOptions {
120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
121 f.debug_struct("ClaudeAgentOptions")
122 .field("model", &self.model)
123 .field("prompt", &self.prompt.as_ref().map(|p| {
124 if p.len() > 50 { format!("{}...", &p[..50]) } else { p.clone() }
125 }))
126 .field("max_turns", &self.max_turns)
127 .field("session_id", &self.session_id)
128 .field("permission_mode", &self.permission_mode)
129 .field("verbose", &self.verbose)
130 .field("hooks_count", &self.hooks.len())
131 .field("mcp_servers_count", &self.mcp_servers.len())
132 .field("agents_count", &self.agents.len())
133 .finish_non_exhaustive()
134 }
135}