install.sh: repoint dangling claude symlink to latest installed version

The committed ~/.local/bin/claude symlink targets a specific Claude Code
version path (whatever was current when this snapshot was taken). On any
host that has Claude Code installed at a different version, that symlink
arrives dangling.

Old behavior: just delete the dangling link and rely on the Claude
installer to recreate it. That doesn't help when the host has Claude
installed but at a version other than the one in the snapshot, and we
also support skipping the installer via DRUNKENDOTFILES_SKIP_CLAUDE=1
(used when the binary is already on disk but at a different version).

New behavior: when the deployed symlink is dangling, scan
~/.local/share/claude/versions/ and repoint the symlink to the highest
installed version (semver sort). Only fall back to deleting the link if
no version is installed at all.
This commit is contained in:
2026-05-06 09:45:52 +00:00
parent 6188583ee9
commit 5208e9a5bb

View File

@@ -162,11 +162,29 @@ log "Deploying personal dotfiles"
for f in "${PERSONAL_FILES[@]}"; do deploy_file "$f"; done for f in "${PERSONAL_FILES[@]}"; do deploy_file "$f"; done
for d in "${PERSONAL_DIRS[@]}"; do deploy_dir "$d"; done for d in "${PERSONAL_DIRS[@]}"; do deploy_dir "$d"; done
# .local/bin/claude is a relative symlink to ../share/claude/versions/... # .local/bin/claude is a relative symlink to ../share/claude/versions/<version>.
# If that target isn't present on this machine, remove the dangling link so # The version baked into the repo snapshot is whatever was current when this
# Claude Code's own installer (next step) can manage it. # was last committed; on a fresh host that exact version probably isn't
if [ -L "$HOME/.local/bin/claude" ] && [ ! -e "$HOME/.local/bin/claude" ]; then # installed. Resolve as follows:
rm "$HOME/.local/bin/claude" # 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 fi
# 4. Install Claude Code (Anthropic's CLI). Skip if already installed or # 4. Install Claude Code (Anthropic's CLI). Skip if already installed or