From 5208e9a5bb88453bf64952f17c731fbea1756e63 Mon Sep 17 00:00:00 2001 From: dissimulo Date: Wed, 6 May 2026 09:45:52 +0000 Subject: [PATCH] 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. --- install.sh | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) 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