diff --git a/install.sh b/install.sh index b1cd40a2..b8c485ee 100755 --- a/install.sh +++ b/install.sh @@ -162,11 +162,29 @@ log "Deploying personal dotfiles" for f in "${PERSONAL_FILES[@]}"; do deploy_file "$f"; done for d in "${PERSONAL_DIRS[@]}"; do deploy_dir "$d"; done -# .local/bin/claude is a relative symlink to ../share/claude/versions/... -# If that target isn't present on this machine, remove the dangling link so -# Claude Code's own installer (next step) can manage it. -if [ -L "$HOME/.local/bin/claude" ] && [ ! -e "$HOME/.local/bin/claude" ]; then - rm "$HOME/.local/bin/claude" +# .local/bin/claude is a relative symlink to ../share/claude/versions/. +# The version baked into the repo snapshot is whatever was current when this +# was last committed; on a fresh host that exact version probably isn't +# installed. Resolve as follows: +# 1. If the deployed symlink already resolves, leave it alone. +# 2. Else, if any other Claude version is present under +# ~/.local/share/claude/versions/, repoint the symlink to the highest +# one (semver sort) so users get the latest installed binary. +# 3. Else, drop the dangling link and let Claude Code's own installer +# (next step) recreate it. +claude_link="$HOME/.local/bin/claude" +claude_versions_dir="$HOME/.local/share/claude/versions" +if [ -L "$claude_link" ] && [ ! -e "$claude_link" ]; then + latest_claude="" + if [ -d "$claude_versions_dir" ]; then + latest_claude="$(ls -1 "$claude_versions_dir" 2>/dev/null | sort -V | tail -1)" + fi + if [ -n "$latest_claude" ] && [ -e "$claude_versions_dir/$latest_claude" ]; then + ln -sfn "../share/claude/versions/$latest_claude" "$claude_link" + info "Repointed ~/.local/bin/claude -> $latest_claude (latest installed)" + else + rm "$claude_link" + fi fi # 4. Install Claude Code (Anthropic's CLI). Skip if already installed or