GIT_BIN="$HOME/.guix-profile/bin/git"
+# Determine worktree state and compute an abbreviated name
+# (first 7 characters of the session ID, like a git short hash).
+wt_abbrev=""
if echo "$PWD" | $GUIX_BIN/grep -q '/worktrees/'; then
- echo "🌿 $CLAUDE_CODE_SESSION_ID"
+ wt_abbrev=$(echo "$CLAUDE_CODE_SESSION_ID" | $GUIX_BIN/cut -c1-7)
+ echo "🌿 $wt_abbrev"
else
if [ -x "$GIT_BIN" ]; then
branch=$($GIT_BIN -C "$PWD" branch --show-current 2>/dev/null)
| $GUIX_BIN/sed \
's/.*"Name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')
- if echo "$PWD" | $GUIX_BIN/grep -q '/worktrees/'; then
- suffix="🌿 $CLAUDE_CODE_SESSION_ID"
- if ! echo "$current_name" | $GUIX_BIN/grep -qF "$suffix"; then
+ if [ -n "$wt_abbrev" ]; then
+ # In a worktree: prepend the abbreviation as prefix.
+ prefix="🌿 $wt_abbrev"
+ if ! echo "$current_name" | $GUIX_BIN/grep -qF "$prefix"; then
"$PASEO" agent update "$agent_id" \
- --name "$current_name $suffix" >/dev/null 2>&1
+ --name "$prefix $current_name" >/dev/null 2>&1
fi
else
+ # Outside a worktree: strip any worktree prefix.
if echo "$current_name" | $GUIX_BIN/grep -q '🌿'; then
clean_name=$(echo "$current_name" \
- | $GUIX_BIN/sed 's/ 🌿 [a-f0-9-]*$//')
+ | $GUIX_BIN/sed 's/^🌿 [a-f0-9]\{1,8\} //')
"$PASEO" agent update "$agent_id" \
--name "$clean_name" >/dev/null 2>&1
fi