Repository navigation
fix: go back to the tab's tmux session after its session ends - #88
Merged
LukeGus merged 1 commit intoNov 16, 2026
Merged
Conversation
When a tab's server session ends (the 30 minute timeout after the computer slept, or a dropped SSH connection), the tab logs in again and Auto tmux treats it like a new tab: with several sessions on the host it shows the session picker, although the tab knew which session it was showing. The tab now remembers its tmux session and sends it with the new login. Auto tmux attaches it again when the host still has it, and otherwise does what it did before. tmux sessions get renamed (by hand or by a hook), so the backend reports tmux's creation time with each attach and create, and the match uses that time, with the name only as a tie breaker or when the time is unknown. A reattach to a live session also tells the tab its tmux session, so a tab restored after an app restart knows it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI review | Looks safe to merge Adds logic to remember a tab's tmux session and reattach to it after a connection drop or session expiry, using creation time to survive session renames. Input validation, state management, and tests are correct. Reviewed 50afb27. AI can be wrong, a maintainer still decides. Comment |
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.
Problem
With Auto tmux on, a terminal tab whose session on the server has ended logs in again like a brand new tab. On a host with more than one tmux session that means the "TMUX SESSIONS" picker, although the tab knew which session it was showing. The usual way to get there: the computer sleeps for longer than the session timeout (30 minutes by default), the server ends the detached sessions, and on wake every tab asks which session to open. The tmux sessions themselves are fine the whole time.
Cause
After
sessionExpired(or a dropped SSH connection) the tab sends a freshconnectToHostthat carries only the tab'stmuxAttachSessionprop, which is empty for an ordinary tab. The tab keeps the name of its tmux session intmuxSessionNameRefbut never sends it, so the backend runsplanTmuxAttachas for a new tab.Fix
The tab remembers its tmux session and sends it as
tmuxReattachwith a freshconnectToHost. The Auto tmux path attaches it again when the host still has it. When the session is gone, nothing changes: create one, attach the only one, or show the picker.tmux sessions get renamed, by hand or by tools that name a session after what runs in it, so the name alone is not enough. The backend now reports tmux's creation time (
created, already in the session list) withtmux_session_createdandtmux_session_attached, and the match uses that time first. The name only breaks a tie between sessions created in the same second, or is used alone when the time is unknown. A session that got the old name but has a different creation time is not taken.tmux-attach-plan.ts:findTmuxSession(pure) andreadTmuxSessionRef(checks the value from the client).terminal-socket.ts:connectToHostacceptstmuxReattach, and the Auto tmux path tries it beforeplanTmuxAttach. The picker'stmux_attachaccepts thecreatedthe list showed.sessionAttachednow carriestmuxSessionon both reattach paths, so a tab restored after an app restart learns its session from the live server session.session-manager.ts:tmuxSessionCreatednext totmuxSessionName.Terminal.tsxwithtmux-reattach.ts: the tab keeps{ name, created }, forgets it on Detach tmux and when the picker is cancelled, and sends it with a fresh login. Reattaching to a live session is unchanged.Not covered: a tab opened for a named session (
tmuxAttachSession, for example from Tmux Monitor) still asks for that name. A tab restored after the app was closed for longer than the session timeout still asks once, because the remembered session lives in the tab's memory.Testing
findTmuxSessionandreadTmuxSessionRefcases; a socket test (a renamed session found by its creation time, a gone session showing the picker as before, a malformed value ignored,createdsent on create,tmuxSessionsent on reattach, the picker'screatedkept); frontend tests for what the tab remembers and sends.reconnect-mouse.test.tsgets the new ref in its context.scripts/patch-ssh2-agent.cjsand a build), typecheck, Prettier, andvalidatepass. The new socket test fails without the change.🤖 Generated with Claude Code