Skip to content

Commit 6ad1cfc

Browse files
committed
fix(claude): auto-migrate from deprecated npm package to native installer
The npm package @anthropic-ai/claude-code is stuck at v1.0.x while the native installer is at v2.x. npm update reports "up to date" even though the package is abandoned. Changes: - Detect outdated npm installations by comparing to GitHub releases - Show clear message that npm package is deprecated - Provide manual migration instructions - Automatically uninstall npm and install native version
1 parent c6ddfd1 commit 6ad1cfc

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

scripts/install_claude.sh

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ install_npm() {
8080
return 1
8181
}
8282

83+
# Get latest version from GitHub
84+
get_latest_version() {
85+
curl -fsSIL -H "User-Agent: cli-audit" -o /dev/null -w '%{url_effective}' \
86+
"https://github.com/anthropics/claude-code/releases/latest" 2>/dev/null | awk -F'/' '{print $NF}' | sed 's/^v//'
87+
}
88+
89+
# Compare versions (returns 0 if v1 < v2)
90+
version_lt() {
91+
[ "$(printf '%s\n%s' "$1" "$2" | sort -V | head -1)" = "$1" ] && [ "$1" != "$2" ]
92+
}
93+
94+
# Migrate from npm to native installer
95+
migrate_npm_to_native() {
96+
echo "[claude] Migrating from npm to native installer..." >&2
97+
echo "[claude] Removing npm package..." >&2
98+
npm uninstall -g @anthropic-ai/claude-code 2>/dev/null || true
99+
hash -r 2>/dev/null || true
100+
echo "[claude] Installing native version..." >&2
101+
install_native
102+
}
103+
83104
# Upgrade existing installation
84105
upgrade_claude() {
85106
local claude_bin
@@ -96,8 +117,28 @@ upgrade_claude() {
96117

97118
# Detect installation method and upgrade accordingly
98119
if echo "$real_path" | grep -q 'node_modules'; then
99-
echo "[claude] Detected npm installation, upgrading via npm..." >&2
100-
npm update -g @anthropic-ai/claude-code || install_native
120+
local current_ver latest_ver
121+
current_ver=$(get_current_version)
122+
latest_ver=$(get_latest_version)
123+
124+
echo "[claude] Detected npm installation (v${current_ver:-unknown})" >&2
125+
126+
# Check if npm version is significantly outdated
127+
# The npm package is deprecated - native installer is now recommended
128+
if [ -n "$latest_ver" ] && [ -n "$current_ver" ] && version_lt "$current_ver" "$latest_ver"; then
129+
echo "[claude] npm package is outdated (latest: $latest_ver)" >&2
130+
echo "[claude] The npm package is deprecated. Native installer recommended." >&2
131+
echo "" >&2
132+
echo "[claude] To migrate manually:" >&2
133+
echo " npm uninstall -g @anthropic-ai/claude-code" >&2
134+
echo " curl -fsSL https://claude.ai/install.sh | bash" >&2
135+
echo "" >&2
136+
echo "[claude] Attempting automatic migration..." >&2
137+
migrate_npm_to_native
138+
else
139+
echo "[claude] Upgrading via npm..." >&2
140+
npm update -g @anthropic-ai/claude-code || install_native
141+
fi
101142
elif echo "$real_path" | grep -q 'Cellar\|homebrew'; then
102143
echo "[claude] Detected Homebrew installation, upgrading via brew..." >&2
103144
brew upgrade --cask claude-code || brew reinstall --cask claude-code

0 commit comments

Comments
 (0)