Repository navigation
Conversation
i8ramin
marked this pull request as draft
October 22, 2026 18:57
…ue 13167. Tab groups of tmux tabs were lost on reattach because nothing stored them in tmux. Each tab now writes its group's ID, name, color and collapsed flag into its entry in the existing @per_tab_settings option, as g=, gn=, gc= and gx= keys. Every member carries the group's attributes, as window arrangements do, so no new tmux option is needed. Older versions ignore the unknown keys. On attach, the keys are applied as each tab opens. Once the last pending window has opened (or failed to), each window with newly opened tabs enforces group contiguity, normalizes collapsed state and updates its tab bar, as arrangement restore does. A reopened tab joining a group that is already open takes the open members' attributes. Reading a setting only ever adds a group, so an entry written by an older version never ungroups a tab. Tab bar updates request a save, coalesced to one check per run-loop pass, which writes the option only if the open tabs' settings changed. savePerTabSettings no longer saves while detaching or switching sessions, or before the session's option has been read, so switching sessions can't write the old session's settings into the new one. It merges open tabs into the cached settings, so windows without a tab (hidden, opening or being reopened) keep their entries until the window closes, and it skips tabs from other tmux servers and tabs left open after a detach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i8ramin
force-pushed
the
tmux-tab-groups
branch
from
October 22, 2026 19:12
98fdfff to
4e97942
Compare
i8ramin
marked this pull request as ready for review
October 22, 2026 19:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: https://gitlab.com/gnachman/iterm2/-/issues/13167 (duplicate: https://gitlab.com/gnachman/iterm2/-/issues/13069)
Related: https://gitlab.com/gnachman/iterm2/-/issues/13085 (Python API for tab groups)
Problem
With
tmux -CC, tab titles, tab colors and window affinity survive detach and reattach, but tab groups don't. After reattaching, users rebuild every group (membership, name, color, collapsed state) by hand.Change
Each tmux tab already has an entry in the
@per_tab_settingssession option (currently onlyt=<base64 title>). This change adds four keys to that entry:g=gn=gc=#rrggbborp3#rrrrggggbbbb(-hexStringPreservingColorSpace, as the Python API uses)gx=1Every member tab carries its group's attributes, the same way window arrangements store them, so no new tmux option is needed.
-[TmuxController applyRestoredTabGroups]calls the new-[PseudoTerminal tmuxTabGroupsDidLoadForTabs:]with the tabs that just opened. It runs the same steps as arrangement restore: enforce contiguity, normalize collapsed state, update the tab bar. Layout updates also end inwindowDidOpen:, so only windows that were actually pending count.-[PseudoTerminal updateTabGroups]calls the new-[TmuxController tabGroupsDidChange]. BecauseupdateTabGroupsruns on every tab bar update, this coalesces to one check per run-loop pass and saves only if the open tabs' settings changed since the last save.g=never ungroups a tab, so an entry written by an older version can't undo grouping done since.Changes to
savePerTabSettingsthat this depends on:@per_tab_settingshas been read. Before, when the client switched sessions, closing the old session's tabs could write their settings into the new session's option before it was read.%window-close, and on attach for windows that no longer exist.Backward compatibility
The 3.7.3 parser ignores unknown keys in
@per_tab_settings, so older builds attach fine. See the known limitation below about older builds saving.Testing
ModernTests/PTYTabTmuxTabGroupSettingsTests.swift(6 tests, all passing withtools/run_tests.expect ModernTests/PTYTabTmuxTabGroupSettingsTests): group attributes round-trip, title and group round-trip together, unknown keys are ignored, a setting without a group leaves an existing group alone, an ungrouped tab with no title produces no setting, and group colors (sRGB, Display P3 and a system color) save to the same value after repeated restore-and-save cycles.Manual tests with a dev build against an isolated tmux server (
tmux -L tgtest), with "Open tmux windows as tabs in an existing window":@per_tab_settingsis updated right away (gx=1present). After another detach and reattach the option still has the new name andgx=1.@per_tab_settings. Attach to the first, thentmux switch-client -tthe second, then switch back. Each session's option still holds only its own group, and a collapsed group whose session has an ungrouped tab selected stays collapsed.Known limitations
@per_tab_settingswill drop the group keys.🤖 Generated with Claude Code
https://claude.ai/code/session_01WL2PvY6a8osQsVf8xCE1eU