From 8a38c089687f0775881aff92588fffe27d1caba0 Mon Sep 17 00:00:00 2001 From: Junyoung Eom Date: Wed, 25 Jun 2025 20:59:07 +0900 Subject: [PATCH] feat: improve Claude binary detection for active NVM environments - Add support for NVM_BIN environment variable detection - Prioritize currently active NVM environment over other installations - Consolidate NVM-related logic in find_nvm_installations function - Maintain backward compatibility with existing detection methods This change helps users who manage Node.js versions with NVM by ensuring Claudia detects the Claude binary from the currently active Node.js environment, resolving issues where the wrong Claude version might be selected despite having multiple NVM installations available. --- src-tauri/src/claude_binary.rs | 38 ++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/claude_binary.rs b/src-tauri/src/claude_binary.rs index adf33652d..f6ac98a97 100644 --- a/src-tauri/src/claude_binary.rs +++ b/src-tauri/src/claude_binary.rs @@ -107,16 +107,17 @@ fn source_preference(installation: &ClaudeInstallation) -> u8 { "which" => 1, "homebrew" => 2, "system" => 3, - source if source.starts_with("nvm") => 4, - "local-bin" => 5, - "claude-local" => 6, - "npm-global" => 7, - "yarn" | "yarn-global" => 8, - "bun" => 9, - "node-modules" => 10, - "home-bin" => 11, - "PATH" => 12, - _ => 13, + "nvm-active" => 4, + source if source.starts_with("nvm") => 5, + "local-bin" => 6, + "claude-local" => 7, + "npm-global" => 8, + "yarn" | "yarn-global" => 9, + "bun" => 10, + "node-modules" => 11, + "home-bin" => 12, + "PATH" => 13, + _ => 14, } } @@ -129,7 +130,7 @@ fn discover_all_installations() -> Vec { installations.push(installation); } - // 2. Check NVM paths + // 2. Check NVM paths (includes current active NVM) installations.extend(find_nvm_installations()); // 3. Check standard paths @@ -189,6 +190,21 @@ fn try_which_command() -> Option { fn find_nvm_installations() -> Vec { let mut installations = Vec::new(); + // First check NVM_BIN environment variable (current active NVM) + if let Ok(nvm_bin) = std::env::var("NVM_BIN") { + let claude_path = PathBuf::from(&nvm_bin).join("claude"); + if claude_path.exists() && claude_path.is_file() { + debug!("Found Claude via NVM_BIN: {:?}", claude_path); + let version = get_claude_version(&claude_path.to_string_lossy()).ok().flatten(); + installations.push(ClaudeInstallation { + path: claude_path.to_string_lossy().to_string(), + version, + source: "nvm-active".to_string(), + }); + } + } + + // Then check all NVM directories if let Ok(home) = std::env::var("HOME") { let nvm_dir = PathBuf::from(&home) .join(".nvm")