Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Never start the Claude desktop app as Claude Code when resolving a run's program (#1017)

FuryNocturnTV (Tare Fernandez)8169d681f3f1
diff --git a/crates/ai/src/cli_agents/mod.rs b/crates/ai/src/cli_agents/mod.rs
index 023e01d7..fa9383dd 100644
--- a/crates/ai/src/cli_agents/mod.rs
+++ b/crates/ai/src/cli_agents/mod.rs
@@ -60,31 +60,45 @@ pub fn program_for(agent: &str) -> String {
/// that's gone from this computer is looked for again (#721): an agent that installs each version
/// in a folder of its own (Codex's `bin/<build>/codex.exe`) moves on every update, so the same file
/// in the newest folder beside the old one is used, else the usual name on PATH. On another
-/// computer (ssh) the chosen command is used as it is.
-pub fn program_of(config: &BackendConfig, options: &BackendOptions) -> String {
+/// computer (ssh) the chosen command is used as it is. Fails when the usual name would start only
+/// the Claude desktop app, which can't build.
+pub fn program_of(config: &BackendConfig, options: &BackendOptions) -> Result<String, ToolError> {
+ program_in(config, options, craft_anything_platform::which::search_path())
+}
+
+fn program_in(config: &BackendConfig, options: &BackendOptions, search: Option<std::ffi::OsString>) -> Result<String, ToolError> {
let usual = program_for(&config.model);
let local = config.ssh_host.as_deref().is_none_or(|h| h.trim().is_empty());
let Some(chosen) = options.command.as_deref().map(str::trim).filter(|c| !c.is_empty()) else {
- return if local { usual_program(usual) } else { usual };
+ return if local { Ok(usual_program(&usual, search)?.unwrap_or(usual)) } else { Ok(usual) };
};
// A folder or app bundle saved before set_command refused it (#467) can't be started: the usual
// program is used, as when none is chosen.
if local && Path::new(chosen).is_dir() {
- return usual_program(usual);
+ return Ok(usual_program(&usual, search)?.unwrap_or(usual));
}
let path = Path::new(chosen);
if !local || path.parent().is_none_or(|p| p.as_os_str().is_empty()) || path.exists() {
- return chosen.to_string();
+ return Ok(chosen.to_string());
}
- moved_program(path).or_else(|| craft_anything_platform::which(&usual).map(|_| usual)).unwrap_or_else(|| chosen.to_string())
+ // Gone, and nothing beside it: the usual program if it's really here, else the saved path, so
+ // the error names it.
+ Ok(moved_program(path).or_else(|| usual_program(&usual, search).ok().flatten()).unwrap_or_else(|| chosen.to_string()))
}
-/// The usual name, or the real program's path when the name alone would start something else that
-/// comes first on the search path (the Claude desktop app's `claude.exe`).
-fn usual_program(usual: String) -> String {
- match (craft_anything_platform::which(&usual), find_program(&usual)) {
- (Some(first), Some(real)) if first != real => real.display().to_string(),
- _ => usual,
+/// How to start the usual program: its name, or the real program's path when the name alone would
+/// start something else that comes first on the search path (the Claude desktop app's
+/// `claude.exe`). `None` when nothing has that name; an error when only the desktop app does.
+fn usual_program(usual: &str, search: Option<std::ffi::OsString>) -> Result<Option<String>, ToolError> {
+ let first = craft_anything_platform::which::which_in(usual, search.clone()).into_iter().next();
+ match (first, find_program_in(usual, search)) {
+ (None, _) => Ok(None),
+ (Some(first), Some(real)) => Ok(Some(if first == real { usual.to_string() } else { real.display().to_string() })),
+ (Some(app), None) => Err(ToolError::new(
+ ErrorCode::EngineMissing,
+ format!("Claude Code isn't installed: the `claude` found ({}) is the Claude desktop app, which can't build.", app.display()),
+ )
+ .with_remediation("Install Claude Code apart from the desktop app, sign in to it once in a terminal, then try again.")),
}
}
@@ -580,7 +594,8 @@ fn acp_for(spec: &CliSpec) -> Option<AcpConversation> {
}
let local = spec.config.ssh_host.as_deref().is_none_or(|h| h.trim().is_empty());
let acp_args = selected_acp_args(adapter.as_ref(), &agent, &spec.options).filter(|_| local)?;
- let program = program_of(&spec.config, &spec.options);
+ // No program to start: the plain run reports why.
+ let program = program_of(&spec.config, &spec.options).ok()?;
let access = match (spec.question, spec.deep, spec.builder.is_some()) {
(true, true, _) => Access::Question,
(true, false, _) => Access::CleanRoomQuestion,
@@ -783,7 +798,13 @@ fn run_cli(spec: &CliSpec, text: &str, retry: bool, tx: &Sender<AgentEvent>, sto
let RunState { session, verified, lost, failure } = state;
let name = spec.config.name.clone();
let agent = spec.config.model.clone();
- let program = program_of(&spec.config, &spec.options);
+ let program = match program_of(&spec.config, &spec.options) {
+ Ok(program) => program,
+ Err(e) => {
+ let _ = tx.send(AgentEvent::Error { message: e.message, remediation: e.remediation, log: None });
+ return nothing_done(&name);
+ }
+ };
let remote = spec.config.ssh_host.clone().filter(|h| !h.trim().is_empty());
// A folder chosen for it is on the computer it runs on: on another one, it's set below.
let mut adapter = match remote {
@@ -1165,18 +1186,18 @@ mod tests {
enabled: true,
};
let chosen = |p: &Path| BackendOptions { command: Some(p.display().to_string()), ..Default::default() };
- assert_eq!(program_of(&config(None), &chosen(&gone)), new.display().to_string(), "the same file in the newer build folder");
- assert_eq!(program_of(&config(None), &chosen(&new)), new.display().to_string(), "a path that's there is used as it is");
- assert_eq!(program_of(&config(Some("box")), &chosen(&gone)), gone.display().to_string(), "another computer's path isn't checked here");
- assert_eq!(program_of(&config(None), &BackendOptions::default()), "codex", "nothing chosen: the usual name");
+ assert_eq!(program_of(&config(None), &chosen(&gone)).unwrap(), new.display().to_string(), "the same file in the newer build folder");
+ assert_eq!(program_of(&config(None), &chosen(&new)).unwrap(), new.display().to_string(), "a path that's there is used as it is");
+ assert_eq!(program_of(&config(Some("box")), &chosen(&gone)).unwrap(), gone.display().to_string(), "another computer's path isn't checked here");
+ assert_eq!(program_of(&config(None), &BackendOptions::default()).unwrap(), "codex", "nothing chosen: the usual name");
// #467: a saved app bundle is never started; the usual name is looked up instead.
let dir = tempfile::tempdir().unwrap();
let bundle = dir.path().join("Codex.app");
std::fs::create_dir_all(&bundle).unwrap();
- assert_eq!(program_of(&config(None), &chosen(&bundle)), "codex", "an app bundle is not the program");
- assert_eq!(program_of(&config(Some("box")), &chosen(&bundle)), bundle.display().to_string(), "another computer's path isn't checked here");
+ assert_eq!(program_of(&config(None), &chosen(&bundle)).unwrap(), "codex", "an app bundle is not the program");
+ assert_eq!(program_of(&config(Some("box")), &chosen(&bundle)).unwrap(), bundle.display().to_string(), "another computer's path isn't checked here");
let bare = BackendOptions { command: Some("my-codex".into()), ..Default::default() };
- assert_eq!(program_of(&config(None), &bare), "my-codex", "a bare name is left to PATH");
+ assert_eq!(program_of(&config(None), &bare).unwrap(), "my-codex", "a bare name is left to PATH");
}
/// The Claude desktop app's older installer names its app `claude.exe`; with its folder on
@@ -1211,6 +1232,25 @@ mod tests {
let (app_dir, cli_dir) = (app.parent().unwrap(), cli.parent().unwrap());
assert_eq!(find_program_in("claude", path(&[app_dir, cli_dir])), Some(cli.clone()), "the desktop app is passed over");
assert_eq!(find_program_in("claude", path(&[app_dir])), None, "only the desktop app: no Claude Code");
+ // What a run starts (review of #858): never the desktop app.
+ let claude = BackendConfig {
+ name: "Claude Code".into(),
+ kind: crate::BackendKind::AgentCli,
+ model: "claude-code".into(),
+ base_url: None,
+ ssh_host: None,
+ enabled: true,
+ };
+ let none = BackendOptions::default();
+ let gone = BackendOptions { command: Some(d.path().join("old").join("claude").join(file).display().to_string()), ..Default::default() };
+ let real = cli.display().to_string();
+ assert_eq!(program_in(&claude, &none, path(&[app_dir, cli_dir])).unwrap(), real, "the real one, by path, when the app comes first");
+ assert_eq!(program_in(&claude, &gone, path(&[app_dir, cli_dir])).unwrap(), real, "a saved path that's gone falls back to the real one");
+ assert_eq!(program_in(&claude, &none, path(&[cli_dir, app_dir])).unwrap(), "claude", "the name, when it starts the real one");
+ let err = program_in(&claude, &none, path(&[app_dir])).unwrap_err();
+ assert_eq!(err.code, ErrorCode::EngineMissing);
+ assert!(err.message.contains("desktop app"), "{}", err.message);
+ assert_eq!(program_in(&claude, &gone, path(&[app_dir])).unwrap(), gone.command.clone().unwrap(), "only the app: the saved path, not the app");
// Another agent's program in such a folder is only filtered for Claude.
let other = app_dir.join(if cfg!(windows) { "codex.exe" } else { "codex" });
std::fs::write(&other, b"").unwrap();
diff --git a/crates/ai/src/cli_agents/models.rs b/crates/ai/src/cli_agents/models.rs
index 4163680a..430e6d5f 100644
--- a/crates/ai/src/cli_agents/models.rs
+++ b/crates/ai/src/cli_agents/models.rs
@@ -106,7 +106,7 @@ pub(crate) fn query_args(options: &BackendOptions) -> Result<Vec<String>, ToolEr
/// Select the configured executable and catalogue location, quoting SSH arguments for the remote shell.
/// Local queries use the supplied directory or current directory; SSH queries expand remote `$PWD`.
fn query_command(config: &BackendConfig, options: &BackendOptions, directory: Option<&Path>) -> Result<(String, Vec<String>), ToolError> {
- let program = super::program_of(config, options);
+ let program = super::program_of(config, options)?;
let mut args = query_args(options)?;
match config.ssh_host.as_deref().filter(|h| !h.trim().is_empty()) {
Some(host) => {
diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rs
index b41475bd..933bbcf0 100644
--- a/crates/ai/src/lib.rs
+++ b/crates/ai/src/lib.rs
@@ -958,7 +958,7 @@ impl AiHub {
let e = self.entry(name)?;
let start = Instant::now();
if e.config.kind == BackendKind::AgentCli {
- let program = cli_agents::program_of(&e.config, &e.options);
+ let program = cli_agents::program_of(&e.config, &e.options)?;
let p = match e.config.ssh_host.as_deref().filter(|h| !h.trim().is_empty()) {
Some(h) => craft_anything_platform::Process::new("ssh").args(ssh::ssh_args(h, &[program.clone(), "--version".into()])),
None => craft_anything_platform::Process::new(&program).arg("--version"),
@@ -1072,14 +1072,16 @@ fn reach(e: &BackendEntry, key: Option<String>) -> Result<u64, String> {
compatible_client(&e.config.name, b, key, &e.config.model, "").list_models(t).map(|_| ()).map_err(|x| x.message)
}
}
- BackendKind::AgentCli => {
- let program = cli_agents::program_of(&e.config, &e.options);
- // A saved path that's gone (#721): PATH has nothing to do with it.
- let by_path = std::path::Path::new(&program).parent().is_some_and(|p| !p.as_os_str().is_empty());
- craft_anything_platform::which(&program)
- .map(|_| ())
- .ok_or_else(|| if by_path { format!("there's no program at {program}") } else { format!("{program} isn't on PATH") })
- }
+ BackendKind::AgentCli => match cli_agents::program_of(&e.config, &e.options) {
+ Err(x) => Err(x.message),
+ Ok(program) => {
+ // A saved path that's gone (#721): PATH has nothing to do with it.
+ let by_path = std::path::Path::new(&program).parent().is_some_and(|p| !p.as_os_str().is_empty());
+ craft_anything_platform::which(&program)
+ .map(|_| ())
+ .ok_or_else(|| if by_path { format!("there's no program at {program}") } else { format!("{program} isn't on PATH") })
+ }
+ },
};
r.map(|_| start.elapsed().as_millis() as u64)
}
diff --git a/crates/ai/src/rebuild/mod.rs b/crates/ai/src/rebuild/mod.rs
index 428d1bd1..942e4760 100644
--- a/crates/ai/src/rebuild/mod.rs
+++ b/crates/ai/src/rebuild/mod.rs
@@ -641,7 +641,7 @@ impl Worker {
adapter.check_remote_tool_server(host, &self.stop)?;
} else {
crate::cli_agents::check_builder_tools(adapter.as_ref(), &entry.config.model, &entry.options, &self.stop)?;
- let program = crate::cli_agents::program_of(&entry.config, &entry.options);
+ let program = crate::cli_agents::program_of(&entry.config, &entry.options)?;
if adapter.signed_in(&program) == Some(false) {
return Err(ToolError::new(ErrorCode::BadSettings, not_signed_in(&entry.config.model, adapter.signed_in_before()))
.with_remediation(adapter.sign_in_fix().unwrap_or_default()));
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 3885dda6..4b2eece9 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -55,7 +55,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi
| OpenCode models and thinking | OpenCode V2 locally and over SSH; Settings → AI lists only that instance's enabled chat models and supported Low/Medium/High/Xhigh/Max variants. Selection is validated and saved through UI, CLI and `ai_models_list` / `ai_model_set`. Explicit selections run natively with the Craft Anything MCP server (local runs, and over SSH: one `ssh` run checks `craft-anything-cli` on the host's PATH and writes the config on the host, `~/.cache/craft-anything/`, mode 600). See [OpenCode](opencode.md). | Stand-in catalogue/process, persistence, remote-command and UI tests; local live catalogue checks (34 models, all five depths represented). Regression checks route explicit selections natively and parse V2 tool events. Live (2026-11-04, Windows, OpenCode 2.2.5, opencode-go/deepseek-v4.1-flash): a `--standalone` run connected the server (38 tools) and called `core_session_show`. The SSH path is covered by a POSIX-shell regression test (probe fails fast without the helper; config written byte-exact, mode 600, atomic rename) and was exercised against a localhost SSH host; it has not been run with a live agent over SSH. No paid generation used |
| Claude desktop app without Claude Code | When the `claude` command isn't found but the Claude desktop app is (Windows: the Store package's `claude-desktop` app alias or the older installer's `AnthropicClaude` folder; macOS: `Claude.app`), the builder dialog under "No coding agent was found" and `ai detect` (on stderr) say the desktop app is installed but building needs Claude Code, installed apart (#259). Typed as `DetectHint` from `AiHub::detect_hints` | A regression finds the app in temp folders laid out as each Windows installer leaves it, and nothing on Linux; a UI test shows the hint in the dialog. On Windows 10 the real Store package's alias was found. Not checked: macOS, the older installer, and a computer with no `claude` installed |
| OpenCode models and thinking | OpenCode V2 locally and over SSH; Settings → AI lists only that instance's enabled chat models and supported Low/Medium/High/Xhigh/Max variants. Selection is validated and saved through UI, CLI and `ai_models_list` / `ai_model_set`. Explicit-selection execution is refused until native MCP integration exists; local ACP runs require clearing the selection. See [OpenCode](opencode.md). | Stand-in catalogue/process, persistence, remote-command and UI tests; local live catalogue checks (34 models, all five depths represented). Regression checks reject native chat/builds before process I/O with ACP on/off, local/SSH and model-only/depth-only/combined selections. No live SSH host or paid generation used |
-| Claude desktop app without Claude Code | When the `claude` command isn't found but the Claude desktop app is (Windows: the Store package's `claude-desktop` app alias, else its package folder, or the older installer's `AnthropicClaude` folder; macOS: `Claude.app`), the builder dialog under "No coding agent was found" and `ai detect` (on stderr) say the desktop app is installed but building needs Claude Code, installed apart (#259). The hint stays when the only suggestions are unchecked agents from `~/.ssh/config`. A `claude` program inside the desktop app (on PATH) is never offered or started as Claude Code: detection, the hint and a run's program look through one `cli_agents::find_program`. Typed as `DetectHint` from `AiHub::detect_hints` | A regression finds the app in temp folders laid out as each Windows installer leaves it, and nothing on Linux; a UI test shows the hint in the dialog, with only SSH suggestions too, and not once an agent here is found; a test passes over the desktop app's `claude.exe` on a search path. On Windows 10 the real Store package's alias was found. Not checked: macOS, the older installer, and a computer with no `claude` installed |
+| Claude desktop app without Claude Code | When the `claude` command isn't found but the Claude desktop app is (Windows: the Store package's `claude-desktop` app alias, else its package folder, or the older installer's `AnthropicClaude` folder; macOS: `Claude.app`), the builder dialog under "No coding agent was found" and `ai detect` (on stderr) say the desktop app is installed but building needs Claude Code, installed apart (#259). The hint stays when the only suggestions are unchecked agents from `~/.ssh/config`. A `claude` program inside the desktop app (on PATH) is never offered or started as Claude Code: detection, the hint and a run's program look through one `cli_agents::find_program`; with only the desktop app there, a run, `ai test` and the builder check fail with "Claude Code isn't installed" instead of starting it. Typed as `DetectHint` from `AiHub::detect_hints` | A regression finds the app in temp folders laid out as each Windows installer leaves it, and nothing on Linux; a UI test shows the hint in the dialog, with only SSH suggestions too, and not once an agent here is found; a test passes over the desktop app's `claude.exe` on a search path, and `program_of` with the app first, the real one first, a saved path that's gone, and the app alone. On Windows 10 the real Store package's alias was found. Not checked: macOS, the older installer, and a computer with no `claude` installed |
| Missing program paths | A program started by its path (a saved agent program, for one) that has no file there is reported with that path, as possibly moved by an update, with reason `path_missing`, instead of "isn't installed or isn't on your PATH"; a bare name still speaks of PATH. A relative path is looked up where the program starts (on Unix, its working folder), so a script there whose interpreter is missing isn't called a path with no file. It stays a missing program (`EngineMissing`), so builder turns aren't retried (#721). `ai test` names the agent program it ran and the saved one it replaced (`program`, `saved_program_replaced`), and `doctor` says a saved path has no program there | `a_saved_program_that_is_gone_is_named_by_test_and_doctor` runs both with a removed path. A regression starts a program at a path with no file on Windows 10 and checks the message, remediation and reason, with a bare-name control; on Linux (Docker), a relative script with a missing interpreter started in its folder, through `Process` and `Launch`. Not checked: a real Codex desktop update, or the app's Settings screen with a stale path |
| npm agents without Node on Windows | Programs are also looked for in nvm for Windows' version folders (`NVM_HOME`, else `%APPDATA%\nvm`, newest first, after `PATH`), so an npm shim such as `claude.cmd` finds Node when no `nvm use` link exists. When a shim's interpreter is still missing, starting it fails with `EngineMissing`, reason `interpreter_missing`, naming `node` and `nvm use`, instead of Rust's "batch file arguments are invalid" | On Windows 10 (Rust 1.99.1): unit tests for version-folder listing with nvm's own files beside the versions, the missing-interpreter check (no Node, Node on the search path, Node beside the shim) and the error's fields; the existing shim tests, including a real multi-line prompt through Node, and the platform crate's 70 tests pass. The failure was seen with Craft Anything 0.4.0 (Claude Code 1.0.96 npm shim, nvm with no version in use). Not checked: the fixed desktop app or CLI on that machine, and a build through a shim found only in nvm's folders |
| Mach-O Objective-C pointers | Chained offsets mapped only into file-empty `__PAGEZERO` reach the image-base fallback; pointer candidates must be backed by file bytes | Synthetic thin and fat Mach-O regression, plain-pointer and authenticated-rebase controls, null and unmapped-pointer checks. Real binaries were not checked for this correction |