Skip to content

Track tmux windows in session list and make tmux quit behavior consistent#42

Merged
mzhaom merged 4 commits intomainfrom
feature/tmux-tracking
Feb 15, 2026
Merged

Track tmux windows in session list and make tmux quit behavior consistent#42
mzhaom merged 4 commits intomainfrom
feature/tmux-tracking

Conversation

@mzhaom
Copy link
Member

@mzhaom mzhaom commented Feb 13, 2026

Summary

  • Track w-created tmux windows in Bramble's per-worktree session list so users can switch from worktree → tmux window
  • Generate unique window names (like "happy-tiger") for tracked windows, matching build/plan session naming
  • Capture and display both window name and window ID (@1, @2, etc.) for robust identification
  • Add manager-level tracking for externally created tmux windows and refresh UI state immediately after creation
  • Make tmux quit behavior consistent via --tmux-exit-on-quit:
    • default (false): preserve Bramble-created and tracked tmux windows on quit
    • enabled (true): close both Bramble-created session windows and tracked w windows on quit

Changes

  • Added TmuxWindowID field to Session/SessionInfo types
  • Use GenerateTmuxWindowName() for unique window naming
  • Capture window name and ID using tmux new-window -n <name> -P -F "#{window_name},#{window_id}"
  • Display window ID in session list (e.g., "happy-tiger @1")
  • Only track windows when in tmux session mode (avoid false errors)

Validation

  • scripts/lint.sh ✅
  • bazel test //... --test_timeout=120 ✅
  • bazel build //... ✅

Note

Medium Risk
Touches tmux process/window lifecycle management and introduces new cleanup behavior on shutdown; mis-tracking or kill-by-ID mistakes could affect users’ tmux sessions if IDs/names are wrong.

Overview
Tracks w-opened tmux windows as sessions so they appear in the per-worktree session list, capturing and displaying both tmux window_name and stable window_id (e.g. happy-tiger @1). Window creation now uses a generated unique name plus tmux new-window -P -F output parsing, and the UI refreshes worktree/session dropdowns immediately after tracking.

Adds manager support for TrackTmuxWindow, including polling-based lifecycle cleanup using TmuxWindowExistsByID, plus an opt-in --tmux-exit-on-quit flag that (when enabled) kills Bramble-started/tracked tmux windows on app exit; tmux runners no longer kill windows on Stop() by default. Includes new/updated tests for tracking and stop semantics.

Written by Cursor Bugbot for commit 1c12660. This will update automatically on new commits. Configure here.

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

mzhaom and others added 2 commits February 13, 2026 17:15
- Generate unique window names using GenerateTmuxWindowName() for
  manually created windows, matching the pattern used for build/plan
  sessions (e.g., "happy-tiger")
- Capture and store both window name and window ID (@1, @2, etc.)
  when creating tmux windows
- Add TmuxWindowID field to Session and SessionInfo types
- Update TrackTmuxWindow to require window ID parameter
- Display window ID alongside window name in session list view
- Update tests to include window ID assertions

This addresses the window identity ambiguity issue by using unique
generated names instead of relying on default tmux naming, while
also tracking window IDs for more robust window identification.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fix false tracking error when opening tmux windows in non-tmux
session modes. Check IsInTmuxMode() before calling TrackTmuxWindow
to avoid showing error toasts when the window creation succeeded
but tracking isn't applicable.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mzhaom
Copy link
Member Author

mzhaom commented Feb 14, 2026

Thanks for the review! I've addressed both issues:

Issue 1: Tracked windows use non-unique tmux names ✅ Fixed

Commit: 0be59ff

The implementation now:

  • Generates unique window names using GenerateTmuxWindowName() (same pattern as build/plan sessions)
  • Creates windows with explicit -n flag to assign the unique name
  • Captures both window name AND window ID using -F "#{window_name},#{window_id}"
  • Stores both values in the session for robust identification
  • Displays both in the UI (e.g., "happy-tiger @1")

This ensures window names are unique and provides window ID as a fallback identifier.

Issue 2: False tracking error outside tmux session mode ✅ Fixed

Commit: 01c1f9c

Added IsInTmuxMode() check before calling TrackTmuxWindow. Now window creation succeeds without showing false error toasts in non-tmux modes.

All tests passing ✅

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Address review feedback:

1. Use window IDs for tracked window lifecycle checks
   - Add TmuxWindowExistsByID() and KillTmuxWindowByID() functions
   - Monitor goroutines now check window existence by ID, not name
   - Window IDs are stable even if user renames windows

2. Ensure TmuxExitOnQuit only affects app quit, not session exits
   - Remove killOnStop from regular session creation
   - Move window cleanup logic to Close() method
   - Windows are only killed during app quit, not on session
     completion or failure
   - This fixes the issue where failed sessions would lose their
     tmux windows even when user wanted to inspect the error

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mzhaom
Copy link
Member Author

mzhaom commented Feb 14, 2026

Thanks for the additional review! I've addressed both new issues in commit 1c12660:

Issue 1: Quit flag affects non-quit session exits ✅ Fixed

Problem: killOnStop was set at session creation based on TmuxExitOnQuit, causing windows to be killed on ANY session stop (completion, failure, or quit).

Solution:

  • Removed killOnStop from regular session creation (always set to false)
  • Moved window cleanup logic to Close() method
  • Windows are now only killed during app quit (when Close() is called), not on individual session exits
  • This preserves tmux windows when sessions fail, allowing users to inspect errors

Issue 2: Tracked windows ignore stable tmux window IDs ✅ Fixed

Problem: We captured window IDs but still used window names for lifecycle checks, making tracking fragile if windows are renamed.

Solution:

  • Added TmuxWindowExistsByID() function for stable window existence checks
  • Added KillTmuxWindowByID() function for reliable window cleanup
  • Monitor goroutines now use window ID for all lifecycle operations
  • Fallback to window name only for backward compatibility with sessions created before ID tracking

All tests passing ✅

@mzhaom mzhaom merged commit cafff2a into main Feb 15, 2026
3 checks passed
@mzhaom mzhaom deleted the feature/tmux-tracking branch February 16, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments