Skip to content

feat: ^X J puts terminal tabs in list order (tmux, iTerm) - #376

Merged
brtkwr merged 1 commit into
mainfrom
feat/order-tabs
Nov 20, 2026
Merged

brtkwr merged 1 commit into
mainfrom
feat/order-tabs

Conversation

@brtkwr

@brtkwr brtkwr commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Opus 5.5 ✨

Ctrl+X J puts the terminal tabs of live sessions in the order the ccs list shows them: pins first, put-away sessions last, children right after their parent. With a search typed, it uses the matches as shown.

What moves

  • tmux: windows within each tmux session.
  • iTerm: tabs within each iTerm window.
  • Only tabs holding a listed session move, and only among the places such tabs already hold. ccs's own tab, plain shells and any other tab stay where they are. I chose this over "unknown tabs go to the end" because ccs usually sits in the first tab, and moving it would be the most jarring change.
  • A tab split into panes goes where its first listed session would.
  • Background sessions, sessions in an app (T3 Code) and exited ones have no tab of their own, so they're skipped.
  • It runs only when you press it. Reordering automatically could move tabs while you type; it could become a setting later.

How, per terminal (checked on this Mac)

  • tmux 3.7b: swap-window -d, then the window that was current is selected again (-d keeps the current slot selected, which would otherwise show a different window). Tried on a throwaway tmux -L server.
  • iTerm 3.7.8: AppleScript can't do it. set index of tab errors, and move tab 3 to before tab 1 reports success but changes nothing. iTerm's API can: ccs talks to it directly over a websocket on ~/Library/Application Support/iTerm2/private/socket, gets a cookie from AppleScript's request cookie and key (no prompt), and hand-encodes protobuf ListSessions (106) and ReorderTabs (125). That adds no dependencies and needs no Python. Session ttys come from AppleScript, matched by session unique id. It needs iTerm > Settings > General > Magic > Enable Python API; without it ccs says where to turn it on. Tried end to end against a throwaway iTerm window: three tabs reordered as asked, with other windows untouched.
  • macOS Terminal: left out. ccs doesn't support Terminal.app anywhere today (focus, open tab, launch), its tabs have no index property, and move tab fails with "AppleEvent handler failed". Only GUI scripting through System Events could do it, which isn't reliable.

The key

^X J. The mnemonic letters were taken: O (orchestrator), T (table), A (auto-focus), S (snooze), L (list), M (move into topics) and R (restart). Only J, V and Z were free.

Tests

  • internal/sessions/taborder_test.go: which tab goes where (slotOrder: other tabs stay put, split tabs), tmux grouping and the swap plan, OrderTabs with stubbed tmux and a fake iTerm API, protobuf parsing of a nested split tree, and the websocket client against a fake iTerm on a pipe (handshake headers, ping/pong, skipping someone else's answer, a reorder error status, a refused handshake).
  • internal/tui/live_test.go: ^X J passes the ttys of live terminal sessions in list order and skips background, app and exited sessions; refuses outside tmux and iTerm; never runs twice at once; reports the result.
  • TestMain in both packages stubs the new terminal hooks (TmuxRun, ITermAPI, ITermSessionTTYs, ITermCookie, OrderTabs), so tests never touch a real terminal.

Docs: shortcuts(), --help, README and AGENTS.md.

🤖 Generated with Claude Code

^X J moves the tabs of live sessions into the order the ccs list shows
them: tmux windows within each tmux session, iTerm tabs within each iTerm
window. Only tabs holding a listed session move, among the places they
already hold, so ccs's own tab and plain shells stay put. A split tab goes
where its first listed session would. It runs only when pressed.

tmux uses swap-window -d, then selects the window that was current again.
iTerm's AppleScript can't move a tab (setting a tab's index errors, and
move reports success but changes nothing), so ccs talks to iTerm's API
itself: a websocket on its unix socket, a cookie from AppleScript, and
hand-encoded protobuf for ListSessions and ReorderTabs. No new
dependencies, but it needs Enable Python API on. macOS Terminal is left
out: its tabs can't be moved without scripting clicks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brtkwr
brtkwr enabled auto-merge November 20, 2026 14:27
@brtkwr
brtkwr merged commit 2a56e34 into main Nov 20, 2026
1 check passed
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