Skip to content

Commit f7d6603

Browse files
committed
fix(claude): skip migration when native binary exists
- guide.sh: Check for working native binary at ~/.local/bin/claude before triggering full migration; if exists, just clean up stale npm/nvm versions - install_claude.sh: Add source guard to allow cleanup_npm_versions to be called without triggering main install logic This prevents repeated migration attempts when both native and npm installations exist, and handles the case where Claude Code may self-reinstall via npm.
1 parent 5c9af2a commit f7d6603

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

scripts/guide.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,28 @@ process_tool() {
177177
local auto_update="$(config_get_auto_update "$catalog_tool")"
178178

179179
# Check if migration needed (deprecated install method)
180+
# But skip migration if native binary already exists and works
180181
local needs_migration=""
181182
if [ "$tool" = "claude" ] && { [ "$method" = "nvm" ] || [ "$method" = "npm" ]; }; then
183+
# Check if native binary exists and works
184+
if [ -x "$HOME/.local/bin/claude" ]; then
185+
local native_ver
186+
native_ver=$("$HOME/.local/bin/claude" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)
187+
if [ -n "$native_ver" ]; then
188+
# Native exists - just clean up stale nvm, don't trigger full migration
189+
printf "\n==> %s %s\n" "" "$display"
190+
printf " installed: %s (native at ~/.local/bin/claude)\n" "$native_ver"
191+
printf " Cleaning up stale npm/nvm installation...\n"
192+
# Source cleanup function and run it
193+
if [ -f "$ROOT/scripts/install_claude.sh" ]; then
194+
(
195+
source "$ROOT/scripts/install_claude.sh" 2>/dev/null
196+
cleanup_npm_versions 2>/dev/null
197+
) || true
198+
fi
199+
return 0
200+
fi
201+
fi
182202
needs_migration="true"
183203
fi
184204

scripts/install_claude.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,14 @@ uninstall_claude() {
340340
fi
341341
}
342342

343-
case "$ACTION" in
344-
install) install_claude ;;
345-
update|upgrade) upgrade_claude ;;
346-
uninstall) uninstall_claude ;;
347-
reconcile) install_claude ;;
348-
*) echo "Usage: $0 {install|update|upgrade|uninstall|reconcile}" ; exit 2 ;;
349-
esac
343+
# Only run main logic when executed directly, not when sourced
344+
# This allows other scripts to source this file for cleanup_npm_versions
345+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
346+
case "$ACTION" in
347+
install) install_claude ;;
348+
update|upgrade) upgrade_claude ;;
349+
uninstall) uninstall_claude ;;
350+
reconcile) install_claude ;;
351+
*) echo "Usage: $0 {install|update|upgrade|uninstall|reconcile}" ; exit 2 ;;
352+
esac
353+
fi

0 commit comments

Comments
 (0)