The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(claude-code): resolve claude CLI from well-known install paths, not only PATH
Nocturnal9239c3852cc3
diff --git a/src/openhuman/inference/provider/claude_code/driver.rs b/src/openhuman/inference/provider/claude_code/driver.rsindex bec1cac113..fddb30ebf2 100644--- a/src/openhuman/inference/provider/claude_code/driver.rs+++ b/src/openhuman/inference/provider/claude_code/driver.rs@@ -187,6 +187,33 @@ fn write_mcp_http_config(Ok(path)}+/// Build the child's `PATH` so `claude` — and any tool it shells out to (git,+/// ripgrep, node, …) — resolves even when OpenHuman was launched from+/// Finder/Dock and inherited only the stripped launchd `PATH`+/// (`/usr/bin:/bin:/usr/sbin:/sbin`, no `~/.local/bin`). Prepends the resolved+/// CLI's own directory plus the common user/Homebrew bin dirs to whatever+/// `PATH` we inherited; the inherited system entries are kept after them.+/// Prepend-only — duplicate `PATH` entries are harmless, so this stays safe if+/// a dir is already present (e.g. a terminal launch).+fn child_path_with_user_bins(claude_bin: &std::path::Path) -> std::ffi::OsString {+ let mut prefix: Vec<PathBuf> = Vec::new();+ if let Some(parent) = claude_bin.parent() {+ if !parent.as_os_str().is_empty() {+ prefix.push(parent.to_path_buf());+ }+ }+ if let Some(home) = dirs::home_dir() {+ prefix.push(home.join(".local/bin"));+ prefix.push(home.join("bin"));+ }+ prefix.push(PathBuf::from("/opt/homebrew/bin"));+ prefix.push(PathBuf::from("/usr/local/bin"));++ let existing = std::env::var_os("PATH").unwrap_or_default();+ std::env::join_paths(prefix.into_iter().chain(std::env::split_paths(&existing)))+ .unwrap_or(existing)+}+/// Keep the potentially large harness prompt out of argv. Windows flattens/// argv into a command line capped at 32,767 UTF-16 code units, while Claude's/// file flag has no such limit. The per-turn scratch directory owns cleanup.@@ -385,6 +412,9 @@ pub async fn run_turn(ctx: TurnContext<'_>) -> anyhow::Result<ChatResponse> {if let Some(key) = &ctx.anthropic_api_key {cmd.env("ANTHROPIC_API_KEY", key);}+ // A Finder/Dock launch inherits a stripped launchd PATH; make sure the CLI+ // and anything it invokes resolve by prepending the user's bin dirs.+ cmd.env("PATH", child_path_with_user_bins(&ctx.bin_path));let mut child = cmd.spawn()@@ -519,6 +549,36 @@ mod tests {assert!(server.get("command").is_none());}+ #[test]+ fn child_path_prepends_cli_dir_and_keeps_inherited_entries() {+ let _env = super::super::ENV_TEST_LOCK+ .lock()+ .unwrap_or_else(|e| e.into_inner());+ let prev = std::env::var_os("PATH");+ std::env::set_var("PATH", "/usr/bin:/bin");++ let combined = child_path_with_user_bins(std::path::Path::new(+ "/Users/test/.local/bin/claude",+ ));+ let dirs: Vec<PathBuf> = std::env::split_paths(&combined).collect();++ // The resolved CLI's own dir is prepended, ahead of the inherited PATH.+ assert_eq!(dirs.first().map(|p| p.as_path()),+ Some(std::path::Path::new("/Users/test/.local/bin")));+ // Inherited system entries survive (appended after the prefixes).+ assert!(dirs.iter().any(|p| p == std::path::Path::new("/usr/bin")));+ assert!(dirs.iter().any(|p| p == std::path::Path::new("/bin")));+ // The CLI dir sorts before the inherited /usr/bin.+ let cli_idx = dirs.iter().position(|p| p == std::path::Path::new("/Users/test/.local/bin"));+ let usr_idx = dirs.iter().position(|p| p == std::path::Path::new("/usr/bin"));+ assert!(cli_idx < usr_idx, "CLI dir must come before inherited /usr/bin");++ match prev {+ Some(v) => std::env::set_var("PATH", v),+ None => std::env::remove_var("PATH"),+ }+ }+#[test]fn large_system_prompt_is_written_to_file_instead_of_argv() {let dir = tempfile::tempdir().expect("tempdir");diff --git a/src/openhuman/inference/provider/claude_code/version_check.rs b/src/openhuman/inference/provider/claude_code/version_check.rsindex 3de1c37e55..975835b750 100644--- a/src/openhuman/inference/provider/claude_code/version_check.rs+++ b/src/openhuman/inference/provider/claude_code/version_check.rs@@ -10,10 +10,19 @@ use std::process::Command;use super::types::{CliStatus, MIN_CLI_VERSION};-/// Locate the `claude` CLI binary on `PATH`.+/// Locate the `claude` CLI binary.///-/// Honors `OPENHUMAN_CLAUDE_CLI` env override so tests and power users can-/// point at a specific binary.+/// Resolution order:+/// 1. `OPENHUMAN_CLAUDE_CLI` env override (tests / power users / a fixed path).+/// 2. `PATH` search.+/// 3. Well-known absolute install locations ([`well_known_candidates`]).+///+/// Step 3 exists because a macOS app launched from Finder/Dock inherits only+/// the stripped launchd `PATH` (`/usr/bin:/bin:/usr/sbin:/sbin`), which never+/// contains the native installer's `~/.local/bin` — so a PATH-only lookup+/// reports the CLI "not installed" even though it is present. (Terminal+/// launches inherit the shell `PATH` and hit step 2, so this only bites GUI+/// launches.)pub fn resolve_binary() -> Option<PathBuf> {if let Ok(explicit) = std::env::var("OPENHUMAN_CLAUDE_CLI") {let p = PathBuf::from(explicit);@@ -21,7 +30,44 @@ pub fn resolve_binary() -> Option<PathBuf> {return Some(p);}}- which_on_path("claude")+ if let Some(p) = which_on_path("claude") {+ return Some(p);+ }+ // PATH miss — fall back to well-known install locations. This is the+ // Finder/Dock-launch case where `~/.local/bin` is absent from `PATH`.+ let found = first_existing(&well_known_candidates());+ if let Some(p) = found.as_ref() {+ log::debug!(+ "[claude-code][version] `claude` not on PATH; resolved via well-known location {}",+ p.display()+ );+ }+ found+}++/// Absolute paths the `claude` CLI is commonly installed at, tried in order+/// when it is not found on `PATH`. Ordered by how the native installer and the+/// common package managers lay it down; the native installer's `~/.local/bin`+/// is first because that is the default and the one a stripped launchd `PATH`+/// omits.+fn well_known_candidates() -> Vec<PathBuf> {+ let mut out = Vec::new();+ if let Some(home) = dirs::home_dir() {+ out.push(home.join(".local/bin/claude")); // native installer default+ out.push(home.join(".claude/local/claude")); // legacy local install+ out.push(home.join(".bun/bin/claude")); // bun global+ out.push(home.join(".npm-global/bin/claude")); // npm global (custom prefix)+ out.push(home.join("bin/claude"));+ }+ out.push(PathBuf::from("/opt/homebrew/bin/claude")); // Homebrew (Apple Silicon)+ out.push(PathBuf::from("/usr/local/bin/claude")); // Homebrew (Intel) / npm default+ out+}++/// First candidate that resolves to a file (follows symlinks — the native+/// installer's `~/.local/bin/claude` is a symlink into a versioned dir).+fn first_existing(candidates: &[PathBuf]) -> Option<PathBuf> {+ candidates.iter().find(|p| p.is_file()).cloned()}fn which_on_path(name: &str) -> Option<PathBuf> {@@ -164,4 +210,32 @@ mod tests {fn version_compare_strips_prerelease() {assert!(!version_lt("2.0.0-rc.1", "2.0.0"));}++ #[test]+ fn first_existing_picks_the_first_real_file() {+ let dir = tempfile::tempdir().expect("tempdir");+ let missing_a = dir.path().join("nope-a/claude");+ let missing_b = dir.path().join("nope-b/claude");+ let real = dir.path().join("claude");+ std::fs::write(&real, b"#!/bin/sh\n").expect("write fake binary");++ // Nothing present → None (the "CLI not installed" path).+ assert_eq!(first_existing(&[missing_a.clone(), missing_b.clone()]), None);+ // Skips the absent candidates and returns the first file that exists.+ assert_eq!(+ first_existing(&[missing_a, missing_b, real.clone()]),+ Some(real)+ );+ }++ #[test]+ fn well_known_candidates_lead_with_native_installer_path() {+ // The native installer default (`~/.local/bin/claude`) is the one a+ // stripped launchd PATH omits, so it must be the first fallback tried.+ let candidates = well_known_candidates();+ assert!(!candidates.is_empty());+ if let Some(home) = dirs::home_dir() {+ assert_eq!(candidates[0], home.join(".local/bin/claude"));+ }+ }}