Skip to content

Commit 246e0c8

Browse files
junyoungeom123vivekr
authored andcommitted
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.
1 parent 9f03d77 commit 246e0c8

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src-tauri/src/claude_binary.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,17 @@ fn source_preference(installation: &ClaudeInstallation) -> u8 {
129129
"which" => 1,
130130
"homebrew" => 2,
131131
"system" => 3,
132-
source if source.starts_with("nvm") => 4,
133-
"local-bin" => 5,
134-
"claude-local" => 6,
135-
"npm-global" => 7,
136-
"yarn" | "yarn-global" => 8,
137-
"bun" => 9,
138-
"node-modules" => 10,
139-
"home-bin" => 11,
140-
"PATH" => 12,
141-
_ => 13,
132+
"nvm-active" => 4,
133+
source if source.starts_with("nvm") => 5,
134+
"local-bin" => 6,
135+
"claude-local" => 7,
136+
"npm-global" => 8,
137+
"yarn" | "yarn-global" => 9,
138+
"bun" => 10,
139+
"node-modules" => 11,
140+
"home-bin" => 12,
141+
"PATH" => 13,
142+
_ => 14,
142143
}
143144
}
144145

@@ -151,7 +152,7 @@ fn discover_system_installations() -> Vec<ClaudeInstallation> {
151152
installations.push(installation);
152153
}
153154

154-
// 2. Check NVM paths
155+
// 2. Check NVM paths (includes current active NVM)
155156
installations.extend(find_nvm_installations());
156157

157158
// 3. Check standard paths
@@ -212,6 +213,21 @@ fn try_which_command() -> Option<ClaudeInstallation> {
212213
fn find_nvm_installations() -> Vec<ClaudeInstallation> {
213214
let mut installations = Vec::new();
214215

216+
// First check NVM_BIN environment variable (current active NVM)
217+
if let Ok(nvm_bin) = std::env::var("NVM_BIN") {
218+
let claude_path = PathBuf::from(&nvm_bin).join("claude");
219+
if claude_path.exists() && claude_path.is_file() {
220+
debug!("Found Claude via NVM_BIN: {:?}", claude_path);
221+
let version = get_claude_version(&claude_path.to_string_lossy()).ok().flatten();
222+
installations.push(ClaudeInstallation {
223+
path: claude_path.to_string_lossy().to_string(),
224+
version,
225+
source: "nvm-active".to_string(),
226+
});
227+
}
228+
}
229+
230+
// Then check all NVM directories
215231
if let Ok(home) = std::env::var("HOME") {
216232
let nvm_dir = PathBuf::from(&home)
217233
.join(".nvm")

0 commit comments

Comments
 (0)