Skip to content

Commit f9b85a4

Browse files
committed
fix(claude): accurate version detection and nvm migration
- Simplify version_command to use 'claude --version' directly (package.json was returning stale/incorrect versions) - Detect nvm-managed npm installs (.nvm/ paths) for migration - Simplify get_current_version() to always run the binary
1 parent 83ec03b commit f9b85a4

2 files changed

Lines changed: 5 additions & 24 deletions

File tree

catalog/claude.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"github_repo": "anthropics/claude-code",
88
"binary_name": "claude",
99
"script": "install_claude.sh",
10-
"version_command": "claude_bin=$(command -v claude 2>/dev/null); if [ -n \"$claude_bin\" ]; then real_path=$(readlink -f \"$claude_bin\" 2>/dev/null || echo \"$claude_bin\"); if echo \"$real_path\" | grep -q 'node_modules'; then pkg_dir=$(dirname \"$real_path\"); [ -f \"$pkg_dir/package.json\" ] && grep '\"version\"' \"$pkg_dir/package.json\" | head -1 | sed 's/.*\"version\": *\"\\([0-9][0-9.]*\\)\".*/\\1/' && exit 0; fi; timeout 2 \"$claude_bin\" --version 2>/dev/null | grep -oE '[0-9]+\\.[0-9]+\\.[0-9]+' | head -1; fi",
10+
"version_command": "timeout 2 claude --version 2>/dev/null | grep -oE '[0-9]+\\.[0-9]+\\.[0-9]+' | head -1",
1111
"guide": {
1212
"display_name": "Claude Code",
1313
"install_action": "upgrade",

scripts/install_claude.sh

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,8 @@ ACTION="${1:-install}"
88

99
# Get current version
1010
get_current_version() {
11-
local claude_bin
12-
claude_bin=$(command -v claude 2>/dev/null || true)
13-
14-
if [ -z "$claude_bin" ]; then
15-
echo ""
16-
return
17-
fi
18-
19-
local real_path
20-
real_path=$(readlink -f "$claude_bin" 2>/dev/null || echo "$claude_bin")
21-
22-
# If npm install, get version from package.json (avoids Node.js version issues)
23-
if echo "$real_path" | grep -q 'node_modules'; then
24-
local pkg_dir
25-
pkg_dir=$(dirname "$real_path")
26-
if [ -f "$pkg_dir/package.json" ]; then
27-
grep '"version"' "$pkg_dir/package.json" | head -1 | sed 's/.*"version": *"\([0-9][0-9.]*\)".*/\1/' && return
28-
fi
29-
fi
30-
31-
# For native installs, try --version
32-
timeout 2 "$claude_bin" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true
11+
# Always use --version for accurate version detection
12+
timeout 2 claude --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true
3313
}
3414

3515
# Install via native installer (recommended)
@@ -116,7 +96,8 @@ upgrade_claude() {
11696
real_path=$(readlink -f "$claude_bin" 2>/dev/null || echo "$claude_bin")
11797

11898
# Detect installation method and upgrade accordingly
119-
if echo "$real_path" | grep -q 'node_modules'; then
99+
# Check for npm install: node_modules in resolved path OR .nvm path (nvm-managed npm)
100+
if echo "$real_path" | grep -qE 'node_modules|\.nvm/'; then
120101
local current_ver
121102
current_ver=$(get_current_version)
122103

0 commit comments

Comments
 (0)