Skip to content

Commit 0e2272c

Browse files
authored
feat(agents): allow creating agents with Claude Code
Allow creating agents with the installed Claude Code ACP harness, using Claude Code’s configured model and credentials. Honor explicit Claude CLI overrides before discovery, and add non-interactive session export documentation and tooling. Signed-off-by: Salman Mohammed <[email protected]>
1 parent 5aeeda7 commit 0e2272c

14 files changed

Lines changed: 733 additions & 34 deletions

File tree

‎crates/agent-controller/src/harness-presets.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@
66
"args": [],
77
"setupUrl": "https://hermes-agent.nousresearch.com/docs/user-guide/features/acp/",
88
"setupHint": "Install Hermes with ACP support and configure it with `hermes model`. Store provider API keys in `~/.hermes/.env`; Buzz doesn’t inherit shell exports. Verify with `hermes acp --check`."
9+
},
10+
{
11+
"id": "claude",
12+
"label": "Claude Code",
13+
"command": "claude-agent-acp",
14+
"args": [],
15+
"setupUrl": "https://github.com/agentclientprotocol/claude-agent-acp",
16+
"setupHint": "Install and sign in to Claude Code under Settings → Agents → Harnesses. Buzz uses Claude’s own model and credentials; shell credentials are not inherited."
917
}
1018
]

‎crates/agent-controller/src/runtime.rs‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ impl RuntimeBundle {
138138
})
139139
.transpose()?;
140140
let pi = crate::pi::verify_launch(pi, preflight)?;
141+
let claude = (crate::agent_defaults::harness_kind(&harness.command) == Some("claude"))
142+
.then(|| {
143+
claude_tools(
144+
&worker,
145+
agent
146+
.environment
147+
.get("CLAUDE_CODE_EXECUTABLE")
148+
.map(String::as_str),
149+
)
150+
})
151+
.transpose()?;
141152
let (args, environment, tools_path) = if let Some(pi) = &pi {
142153
(
143154
pi.adapter_args(&agent.harness)?,
@@ -148,14 +159,24 @@ impl RuntimeBundle {
148159
(
149160
goose_args(&harness.command, &agent.harness.args),
150161
&agent.environment,
151-
tools_path()?,
162+
if let Some((path, _)) = &claude {
163+
path.clone()
164+
} else {
165+
tools_path()?
166+
},
152167
)
153168
};
154169
let path = std::env::join_paths(
155170
std::iter::once(self.directory.clone()).chain(std::env::split_paths(&tools_path)),
156171
)
157172
.map_err(|_| "Invalid runtime tools path")?;
158173
command.envs(environment).env("PATH", &path);
174+
if let Some((_, Some(cli))) = &claude {
175+
if !environment.contains_key("CLAUDE_CODE_EXECUTABLE") {
176+
// Do not depend on the SDK's optional native-binary download.
177+
command.env("CLAUDE_CODE_EXECUTABLE", cli);
178+
}
179+
}
159180
let key_hex = key.hex();
160181
command
161182
.env("BUZZ_PRIVATE_KEY", &*key_hex)
@@ -318,6 +339,61 @@ fn tools_path() -> Result<std::ffi::OsString> {
318339
dirs.extend(["/usr/bin", "/bin", "/usr/sbin", "/sbin"].map(PathBuf::from));
319340
std::env::join_paths(dirs).map_err(|_| "Invalid runtime tools path".into())
320341
}
342+
/// Claude's npm launcher needs Node even when a desktop app has no shell PATH.
343+
/// An app-owned adapter keeps using its pinned Node, independently of global tools.
344+
fn claude_tools(
345+
adapter: &Path,
346+
cli_override: Option<&str>,
347+
) -> Result<(std::ffi::OsString, Option<PathBuf>)> {
348+
let bin = adapter.parent().ok_or("Invalid Claude ACP adapter path")?;
349+
let managed_data = bin
350+
.file_name()
351+
.filter(|name| *name == "bin")
352+
.and_then(|_| bin.parent())
353+
.filter(|prefix| {
354+
prefix
355+
.file_name()
356+
.is_some_and(|name| name == "claude-tools")
357+
})
358+
.and_then(Path::parent);
359+
let node = if let Some(app_data) = managed_data {
360+
managed_tool(app_data, "node")
361+
} else {
362+
let sibling = bin.join(if cfg!(windows) { "node.exe" } else { "node" });
363+
if executable(&sibling).is_ok() {
364+
Some(sibling)
365+
} else {
366+
installed_npm_tool("node")
367+
}
368+
}
369+
.ok_or("Install Node.js for Claude Code in Settings → Agents → Harnesses")?;
370+
let cli = if cli_override.is_some() {
371+
// Advanced owns this value; do not require an unrelated discoverable CLI.
372+
None
373+
} else {
374+
let cli = if let Some(app_data) = managed_data {
375+
managed_tool(app_data, "claude").or_else(|| installed_npm_tool("claude"))
376+
} else {
377+
installed_npm_tool("claude")
378+
}
379+
.ok_or("Install Claude Code in Settings → Agents → Harnesses")?;
380+
// Rust can run Windows batch launchers; the adapter's JavaScript SDK cannot.
381+
// In that case leave native binary resolution to the SDK itself.
382+
let batch = cfg!(windows)
383+
&& cli.extension().is_some_and(|ext| {
384+
ext.eq_ignore_ascii_case("cmd") || ext.eq_ignore_ascii_case("bat")
385+
});
386+
(!batch).then_some(cli)
387+
};
388+
let path = std::env::join_paths(
389+
[node.parent().ok_or("Invalid Node.js path")?, bin]
390+
.into_iter()
391+
.map(Path::to_path_buf)
392+
.chain(std::env::split_paths(&tools_path()?)),
393+
)
394+
.map_err(|_| "Invalid Claude tools path")?;
395+
Ok((path, cli))
396+
}
321397
/// App-owned npm shims and the pinned Node binary are separate from user-global tools.
322398
/// `app_data` is Tauri's resolved app-data directory, never browser input.
323399
pub fn managed_tool(app_data: &Path, name: &str) -> Option<PathBuf> {

‎crates/agent-controller/src/runtime/tests.rs‎

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,73 @@ fn launch_path_puts_bundled_tools_before_platform_tools() {
11511151
assert_eq!(std::env::split_paths(path).collect::<Vec<_>>(), expected);
11521152
}
11531153

1154+
#[test]
1155+
#[cfg(unix)]
1156+
fn claude_launch_uses_its_node_and_preserves_harness_defaults() {
1157+
let dir = tempfile::Builder::new()
1158+
.prefix("Claude tools ")
1159+
.tempdir()
1160+
.unwrap();
1161+
let runtime = bundle(dir.path());
1162+
let key = Secret::parse(KEY, PUB).unwrap();
1163+
let mut saved = agent(dir.path());
1164+
saved.harness.model.clear();
1165+
saved.harness.provider.clear();
1166+
let bin = dir.path().join("claude-tools/bin");
1167+
fs::create_dir_all(&bin).unwrap();
1168+
let adapter = bin.join("claude-agent-acp");
1169+
let cli = bin.join("claude");
1170+
for path in [&adapter, &cli] {
1171+
fs::copy(dir.path().join("buzz-agent"), path).unwrap();
1172+
}
1173+
let node = dir.path().join("runtimes/node/v24.18.0").join(
1174+
match (std::env::consts::OS, std::env::consts::ARCH) {
1175+
("macos", "aarch64") => "darwin-arm64/bin/node",
1176+
("macos", _) => "darwin-x64/bin/node",
1177+
("linux", "aarch64") => "linux-arm64/bin/node",
1178+
_ => "linux-x64/bin/node",
1179+
},
1180+
);
1181+
fs::create_dir_all(node.parent().unwrap()).unwrap();
1182+
fs::copy(dir.path().join("buzz-agent"), &node).unwrap();
1183+
saved.harness.command = adapter.to_string_lossy().into_owned();
1184+
let command = runtime
1185+
.command_with_defaults(&saved, &key, &deployment_defaults())
1186+
.unwrap();
1187+
let environment: BTreeMap<_, _> = command.get_envs().collect();
1188+
let env = |name| environment[std::ffi::OsStr::new(name)].unwrap();
1189+
assert_eq!(env("BUZZ_ACP_AGENT_COMMAND"), adapter.as_os_str());
1190+
assert_eq!(env("BUZZ_ACP_AGENT_ARGS"), "");
1191+
let path: Vec<_> = std::env::split_paths(env("PATH")).collect();
1192+
assert_eq!(
1193+
&path[..3],
1194+
&[dir.path(), node.parent().unwrap(), bin.as_path()]
1195+
);
1196+
assert!(!environment.contains_key(std::ffi::OsStr::new("BUZZ_ACP_MODEL")));
1197+
assert_eq!(env("CLAUDE_CODE_EXECUTABLE"), cli.as_os_str());
1198+
saved
1199+
.environment
1200+
.insert("CLAUDE_CODE_EXECUTABLE".into(), "/custom/claude".into());
1201+
let override_command = runtime.command(&saved, &key).unwrap();
1202+
assert!(override_command
1203+
.get_envs()
1204+
.any(|(name, value)| name == "CLAUDE_CODE_EXECUTABLE"
1205+
&& value == Some(std::ffi::OsStr::new("/custom/claude"))));
1206+
saved.harness.model = "old-model".into();
1207+
assert!(runtime
1208+
.command(&saved, &key)
1209+
.unwrap_err()
1210+
.contains("Use Claude Code defaults"));
1211+
saved.harness.model.clear();
1212+
fs::remove_file(&cli).unwrap();
1213+
// The managed Node remains required even when another installation is on PATH.
1214+
fs::remove_file(node).unwrap();
1215+
assert!(runtime
1216+
.command(&saved, &key)
1217+
.unwrap_err()
1218+
.contains("Install Node.js for Claude Code"));
1219+
}
1220+
11541221
#[test]
11551222
#[cfg(unix)]
11561223
fn start_and_restart_reject_missing_saved_identities() {
@@ -1168,6 +1235,90 @@ fn start_and_restart_reject_missing_saved_identities() {
11681235
assert!(controller.running.is_empty());
11691236
}
11701237

1238+
#[test]
1239+
fn external_claude_launch_resolves_node_and_avoids_windows_batch_cli_overrides() {
1240+
const FIXTURE: &str = "BUZZ_CLAUDE_LAUNCH_FIXTURE";
1241+
let Some(root) = std::env::var_os(FIXTURE) else {
1242+
let dir = tempfile::Builder::new()
1243+
.prefix("External Claude ")
1244+
.tempdir()
1245+
.unwrap();
1246+
let output = Command::new(std::env::current_exe().unwrap())
1247+
.args(["--exact", "runtime::tests::external_claude_launch_resolves_node_and_avoids_windows_batch_cli_overrides", "--nocapture"])
1248+
.env(FIXTURE, dir.path())
1249+
.env("HOME", dir.path().join("home"))
1250+
.env("PATH", dir.path().join("tools"))
1251+
.output().unwrap();
1252+
assert!(
1253+
output.status.success(),
1254+
"{}{}",
1255+
String::from_utf8_lossy(&output.stdout),
1256+
String::from_utf8_lossy(&output.stderr)
1257+
);
1258+
return;
1259+
};
1260+
let root = PathBuf::from(root);
1261+
let runtime = bundle(&root);
1262+
let bin = root.join("tools");
1263+
fs::create_dir_all(&bin).unwrap();
1264+
let adapter = bin.join(if cfg!(windows) {
1265+
"claude-agent-acp.cmd"
1266+
} else {
1267+
"claude-agent-acp"
1268+
});
1269+
let cli = bin.join(if cfg!(windows) {
1270+
"claude.cmd"
1271+
} else {
1272+
"claude"
1273+
});
1274+
let node = bin.join(if cfg!(windows) { "node.exe" } else { "node" });
1275+
let fixture = root.join(format!("buzz-agent{}", std::env::consts::EXE_SUFFIX));
1276+
for path in [&adapter, &cli, &node] {
1277+
fs::copy(&fixture, path).unwrap();
1278+
}
1279+
let mut saved = agent(&root);
1280+
saved.harness.command = adapter.to_string_lossy().into_owned();
1281+
saved.harness.model.clear();
1282+
saved.harness.provider.clear();
1283+
let key = Secret::parse(KEY, PUB).unwrap();
1284+
let command = runtime.command(&saved, &key).unwrap();
1285+
let env: BTreeMap<_, _> = command.get_envs().collect();
1286+
assert_eq!(
1287+
env[std::ffi::OsStr::new("BUZZ_ACP_AGENT_COMMAND")],
1288+
Some(adapter.as_os_str())
1289+
);
1290+
let path: Vec<_> = std::env::split_paths(env[std::ffi::OsStr::new("PATH")].unwrap()).collect();
1291+
assert_eq!(path[1], bin);
1292+
if cfg!(windows) {
1293+
assert!(!env.contains_key(std::ffi::OsStr::new("CLAUDE_CODE_EXECUTABLE")));
1294+
let native = bin.join("claude.exe");
1295+
fs::copy(&fixture, &native).unwrap();
1296+
let command = runtime.command(&saved, &key).unwrap();
1297+
assert!(command.get_envs().any(
1298+
|(key, value)| key == "CLAUDE_CODE_EXECUTABLE" && value == Some(native.as_os_str())
1299+
));
1300+
} else {
1301+
assert_eq!(
1302+
env[std::ffi::OsStr::new("CLAUDE_CODE_EXECUTABLE")],
1303+
Some(cli.as_os_str())
1304+
);
1305+
}
1306+
fs::remove_file(&cli).unwrap();
1307+
if cfg!(windows) {
1308+
fs::remove_file(bin.join("claude.exe")).unwrap();
1309+
}
1310+
let custom_cli = root.join(format!("custom-claude{}", std::env::consts::EXE_SUFFIX));
1311+
fs::copy(&fixture, &custom_cli).unwrap();
1312+
saved.environment.insert(
1313+
"CLAUDE_CODE_EXECUTABLE".into(),
1314+
custom_cli.to_string_lossy().into_owned(),
1315+
);
1316+
let command = runtime.command(&saved, &key).unwrap();
1317+
assert!(command.get_envs().any(|(name, value)| {
1318+
name == "CLAUDE_CODE_EXECUTABLE" && value == Some(custom_cli.as_os_str())
1319+
}));
1320+
}
1321+
11711322
#[test]
11721323
#[cfg(unix)]
11731324
fn shared_cache_spawn_capture_disconnect_snapshot_and_private_temp_cleanup() {

‎docs/agent-control.md‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ installation guidance and device-wide defaults.
251251
### Harnesses
252252

253253
The **Harnesses** card always lists **Buzz Agent**, **Goose**, **Pi**, and
254-
**Claude Code**. Claude Code supports installation only in this slice; it is
255-
not yet a choice when creating an agent. **Add harness** opens the Tier 2 Hermes chooser and setup details.
254+
**Claude Code**. Claude Code is also a choice in Create/Edit once its tools are
255+
installed. **Add harness** opens the Tier 2 Hermes chooser and setup details.
256256
Hermes also appears in the main list once its executable is detected:
257257

258258
- **Buzz Agent** is bundled and shows **Ready**.
@@ -317,10 +317,31 @@ Hermes also appears in the main list once its executable is detected:
317317
after installation. Only its `loggedIn` boolean is exposed; account metadata
318318
is discarded. Ready rows hide setup guidance; failed installs retain their
319319
error and log. This confirms local sign-in, not inference. The ACP adapter bundles its own Claude
320-
runtime; the separate CLI provides the sign-in command. This PR does not
321-
launch Claude agents, discover models or restart agents.
322-
Native reports this setup separately through `claudeSetup`, outside
323-
`harnessOptions`, so it cannot become a creation or default-harness choice.
320+
runtime; the separate CLI provides the sign-in command. Native retains
321+
`claudeSetup` for Settings and reports the selected adapter in `harnessOptions`
322+
for Create/Edit. Picker availability confirms installed tools, not sign-in or
323+
inference. Claude is not a device-wide default-harness choice yet.
324+
325+
**Create agent → Harness → Claude Code** uses Claude's own model and sign-in.
326+
Provider, model browsing and Test connection are not offered in this slice.
327+
Saved model/provider fields remain visible for recovery; choose **Use Claude
328+
Code defaults** before saving or starting those agents. Start uses the saved
329+
absolute adapter path with empty default arguments. Managed adapters use the
330+
pinned managed Node; external adapters prefer a runnable Node beside the adapter,
331+
then native discovery. Node and adapter directories precede the existing
332+
controlled tools PATH, after bundled Buzz tools. Shell provider credentials
333+
are not inherited. Explicit Advanced environment values remain write-only.
334+
Buzz points `CLAUDE_CODE_EXECUTABLE` at the selected runnable CLI unless Advanced
335+
environment explicitly overrides it. An explicit override skips CLI discovery;
336+
Node is still required. This avoids relying on the SDK's optional
337+
native-binary download. Windows `.cmd`/`.bat` login launchers cannot be used by
338+
the JavaScript SDK, so those installations use the SDK's bundled native runtime
339+
and must include its platform optional dependency.
340+
The pinned `buzz-acp` owns Claude system-prompt append, channel/thread sessions,
341+
permissions, cancellation and cleanup. Create, Start/Stop/Restart and retry use
342+
the existing native controller, without another identity or lifecycle owner.
343+
See [View a Claude Code session](view-claude-session.md) for local transcripts
344+
and tool activity.
324345

325346
Tier 2 definitions live in [`harness-presets.json`](../crates/agent-controller/src/harness-presets.json),
326347
owned by the controller and read by both Rust and TypeScript. Native discovery

0 commit comments

Comments
 (0)