Skip to content

Commit 166ddfb

Browse files
MrFlounderclaude
andcommitted
fix(restart): preserve window name after restart
Previous approach created temp-named window, then tried to rename after killing old window. But killing the old window killed the script running the rename. New approach: 1. Rename old window to temp name (freeing the proper name) 2. Create new window with correct name immediately 3. Switch to new window 4. Kill old window via tmux run-shell (runs in tmux context) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0eb0e16 commit 166ddfb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/crabcode

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,21 +1698,25 @@ restart_workspace() {
16981698

16991699
if [ -n "$old_window" ]; then
17001700
echo " Recreating workspace layout..."
1701-
# Create new window with temp name first
1702-
local temp_name="_restart_temp_$$"
1703-
create_workspace_layout "$temp_name" "$dir" "$dev_cmd" "$claude_cmd" "$port_msg" "add"
17041701

1705-
# Kill old window
1706-
tmux kill-window -t "$SESSION_NAME:$old_window" 2>/dev/null || true
1702+
# Create new window with correct name directly
1703+
# First, rename old window to temp so we can use the proper name
1704+
local temp_old="_old_$$"
1705+
tmux rename-window -t "$SESSION_NAME:$old_window" "$temp_old" 2>/dev/null || true
17071706

1708-
# Rename temp to proper name
1709-
tmux rename-window -t "$SESSION_NAME:$temp_name" "$window_name" 2>/dev/null || true
1707+
# Now create new window with correct name
1708+
create_workspace_layout "$window_name" "$dir" "$dev_cmd" "$claude_cmd" "$port_msg" "add"
1709+
1710+
# Switch to new window
1711+
tmux select-window -t "$SESSION_NAME:$window_name"
1712+
1713+
# Kill old window (now named temp_old) via run-shell so it doesn't kill us
1714+
tmux run-shell -t "$SESSION_NAME" "tmux kill-window -t '$SESSION_NAME:$temp_old' 2>/dev/null || true"
17101715

17111716
# Record mood event
17121717
mood_record_event "restart" "workspace $num"
17131718

17141719
success "Workspace $num restarted with fresh layout!"
1715-
tmux select-window -t "$SESSION_NAME:$window_name"
17161720
else
17171721
echo -e "${YELLOW} No existing window found - creating new...${NC}"
17181722
create_workspace_layout "$window_name" "$dir" "$dev_cmd" "$claude_cmd" "$port_msg" "add"

0 commit comments

Comments
 (0)