Skip to content

Commit 9f1435e

Browse files
Sallvainianclaude
andcommitted
feat: add NVM Node.js PATH support from PR winfunc#346
- Add else clause to detect NVM Node.js when Claude isn't in NVM - Automatically find and add latest NVM Node.js version to PATH - Fix 'env: node: No such file or directory' for npm-local Claude - Only triggers when Claude NOT in NVM but needs Node from NVM - Zero impact on other installation types This resolves PATH issues when opcode launched from /Applications on macOS with npm-local Claude installations requiring NVM Node.js. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f13ede1 commit 9f1435e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src-tauri/src/claude_binary.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,38 @@ pub fn create_command_with_env(program: &str) -> Command {
669669
}
670670
}
671671
}
672-
672+
// Also add NVM Node.js when Claude isn't in NVM but needs Node.js
673+
else {
674+
let current_path = std::env::var("PATH").unwrap_or_default();
675+
if !current_path.contains("/.nvm/versions/node/") {
676+
if let Ok(home) = std::env::var("HOME") {
677+
let nvm_base = PathBuf::from(&home).join(".nvm").join("versions").join("node");
678+
if nvm_base.exists() {
679+
if let Ok(entries) = std::fs::read_dir(&nvm_base) {
680+
let mut node_versions: Vec<String> = entries
681+
.filter_map(|entry| entry.ok())
682+
.filter(|entry| entry.file_type().map(|t| t.is_dir()).unwrap_or(false))
683+
.map(|entry| entry.file_name().to_string_lossy().to_string())
684+
.collect();
685+
686+
// Sort to get latest version (simple string sort works for NVM format)
687+
node_versions.sort_by(|a, b| b.cmp(a));
688+
689+
if let Some(latest_version) = node_versions.first() {
690+
let node_bin_path = nvm_base.join(latest_version).join("bin");
691+
if node_bin_path.exists() {
692+
let node_bin_str = node_bin_path.to_string_lossy();
693+
let new_path = format!("{}:{}", node_bin_str, current_path);
694+
debug!("Adding NVM Node.js to PATH for Claude execution: {}", node_bin_str);
695+
cmd.env("PATH", new_path);
696+
}
697+
}
698+
}
699+
}
700+
}
701+
}
702+
}
703+
673704
// Add Homebrew support if the program is in a Homebrew directory
674705
if program.contains("/homebrew/") || program.contains("/opt/homebrew/") {
675706
if let Some(program_dir) = std::path::Path::new(program).parent() {

0 commit comments

Comments
 (0)