Skip to content

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

Rust

Look up a saved claude command the same way, so it never starts the Claude desktop app (#1036)

FuryNocturnTV (Tare Fernandez)75b5040af2d7
diff --git a/crates/ai/src/cli_agents/mod.rs b/crates/ai/src/cli_agents/mod.rs
index 95ddd72c..a0a42e32 100644
--- a/crates/ai/src/cli_agents/mod.rs
+++ b/crates/ai/src/cli_agents/mod.rs
@@ -78,7 +78,18 @@ fn program_in(config: &BackendConfig, options: &BackendOptions, search: Option<s
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() {
+ let bare = path.parent().is_none_or(|p| p.as_os_str().is_empty());
+ // A saved `claude`, by name or as the desktop app's own file, is looked up as the usual one is,
+ // so it never starts the desktop app.
+ let named_claude = bare && path.file_stem().is_some_and(|s| s.eq_ignore_ascii_case(&usual));
+ if local && usual == "claude" && (named_claude || is_claude_desktop(path)) {
+ return match usual_program(&usual, search)? {
+ Some(program) => Ok(program),
+ None if bare => Ok(chosen.to_string()),
+ None => Err(desktop_app_error(path)),
+ };
+ }
+ if !local || bare || path.exists() {
return Ok(chosen.to_string());
}
// Gone, and nothing beside it: the usual program if it's really here, else the saved path, so
@@ -94,14 +105,18 @@ fn usual_program(usual: &str, search: Option<std::ffi::OsString>) -> Result<Opti
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.")),
+ (Some(app), None) => Err(desktop_app_error(&app)),
}
}
+fn desktop_app_error(app: &Path) -> ToolError {
+ 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.")
+}
+
/// Where an agent's program is on this computer: the first match on the search path that is
/// really it. Detection, the desktop app hint and starting a run all look through this, so what's
/// offered is what runs.
@@ -1253,6 +1268,18 @@ mod tests {
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");
+ // A saved `claude`, by name or as the app's own file (review of #1017), is filtered the same way.
+ let saved = |c: &str| BackendOptions { command: Some(c.into()), ..Default::default() };
+ let (by_name, the_app) = (saved(file), saved(&app.display().to_string()));
+ assert_eq!(program_in(&claude, &by_name, path(&[app_dir, cli_dir])).unwrap(), real, "a saved name, the app first");
+ assert_eq!(program_in(&claude, &by_name, path(&[cli_dir, app_dir])).unwrap(), "claude", "a saved name that starts the real one");
+ assert_eq!(program_in(&claude, &by_name, path(&[app_dir])).unwrap_err().code, ErrorCode::EngineMissing);
+ assert_eq!(program_in(&claude, &by_name, path(&[])).unwrap(), file, "nothing found: the saved name, so the run says so");
+ assert_eq!(program_in(&claude, &the_app, path(&[app_dir, cli_dir])).unwrap(), real, "the app's own file saved: the real one");
+ let err = program_in(&claude, &the_app, path(&[])).unwrap_err();
+ assert!(err.code == ErrorCode::EngineMissing && err.message.contains("desktop app"), "{}", err.message);
+ let saved_cli = saved(&cli.display().to_string());
+ assert_eq!(program_in(&claude, &saved_cli, path(&[app_dir])).unwrap(), real, "a saved real path is kept");
// 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/docs/STATUS.md b/docs/STATUS.md
index 676ea723..04ae9472 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -57,7 +57,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`; 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 |
+| 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, also when `claude` (by name or as the desktop app's own file) is the saved 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, and `program_of` with the app first, the real one first, a saved path that's gone, and the app alone, and a saved `claude` by name or as the app's file. 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 |