artifactize_harness/claude/
command.rs1use std::{collections::BTreeMap, ffi::OsString};
6
7use serde_json::{Value, json};
8
9use crate::platform;
10
11pub const PROGRAM: &str = "claude";
13pub const SERVER: &str = crate::stdio_mcp::NAME;
16
17#[derive(Debug, Default)]
19pub struct Launch<'a> {
20 pub model: Option<&'a str>,
21 pub effort: Option<&'a str>,
22 pub system: Option<&'a str>,
24 pub tools: Vec<&'a str>,
26 pub schema: Option<&'a Value>,
28}
29
30impl Launch<'_> {
31 pub fn args(&self) -> Vec<OsString> {
32 let mut args: Vec<String> = [
33 "-p",
34 "--input-format",
35 "stream-json",
36 "--output-format",
37 "stream-json",
38 "--verbose",
39 "--include-partial-messages",
40 "--tools",
42 "",
43 "--strict-mcp-config",
44 "--permission-mode",
45 "dontAsk",
46 "--setting-sources",
47 "",
48 "--settings",
49 r#"{"disableAllHooks":true}"#,
50 "--no-session-persistence",
51 "--disable-slash-commands",
52 "--no-chrome",
53 ]
54 .map(str::to_owned)
55 .into();
56 if self.model.is_some() {
57 args.extend([
58 "--mcp-config".into(),
59 json!({"mcpServers": {SERVER: {"type": "sdk", "name": SERVER}}}).to_string(),
60 ]);
61 }
62 if !self.tools.is_empty() {
63 let tools: Vec<String> = self.tools.iter().map(|name| tool_name(name)).collect();
64 args.extend(["--allowedTools".into(), tools.join(",")]);
65 }
66 if let Some(model) = self.model {
67 args.extend([
68 "--model".into(),
69 model.into(),
70 "--thinking".into(),
71 "adaptive".into(),
72 "--thinking-display".into(),
73 "summarized".into(),
74 ]);
75 }
76 if let Some(effort) = self.effort {
77 args.extend(["--effort".into(), effort.into()]);
78 }
79 if let Some(system) = self.system {
80 args.extend(["--append-system-prompt".into(), system.into()]);
81 }
82 if let Some(schema) = self.schema {
83 args.extend(["--json-schema".into(), schema.to_string()]);
84 }
85 args.into_iter().map(OsString::from).collect()
86 }
87}
88
89pub fn tool_name(name: &str) -> String {
91 format!("mcp__{SERVER}__{name}")
92}
93
94const CLEARED: [&str; 5] = [
98 "CLAUDE_CODE_SIMPLE",
99 "CLAUDE_CODE_EFFORT_LEVEL",
100 "MCP_TOOL_TIMEOUT",
101 "CLAUDECODE",
102 "CLAUDE_CODE_ENTRYPOINT",
103];
104
105const SET: [(&str, &str); 9] = [
110 ("CLAUDE_CODE_DISABLE_CLAUDE_MDS", "1"),
111 ("CLAUDE_CODE_DISABLE_AUTO_MEMORY", "1"),
112 ("DISABLE_AUTO_COMPACT", "1"),
113 ("CLAUDE_CODE_ENABLE_AWAY_SUMMARY", "0"),
114 ("ENABLE_TOOL_SEARCH", "false"),
115 ("CLAUDE_CODE_DISABLE_ADVISOR_TOOL", "1"),
116 ("MAX_MCP_OUTPUT_TOKENS", "200000"),
117 ("CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK", "1"),
118 ("CLAUDE_CODE_DISABLE_REFUSAL_FALLBACK", "1"),
119];
120
121pub fn environment(mut inherited: BTreeMap<OsString, OsString>) -> BTreeMap<OsString, OsString> {
125 for name in CLEARED {
126 platform::remove(&mut inherited, name.as_ref());
127 }
128 for (name, value) in SET {
129 platform::set(&mut inherited, name, value);
130 }
131 inherited
132}
133
134#[cfg(test)]
135mod tests;