fix(zsh): stop auto-tmux spawning a second session beside continuum's restore#92
Merged
Merged
Conversation
… restore
Opening a terminal created two tmux sessions (e.g. `main` and `Gerrrt`)
instead of one. Root cause: core/tmux.conf enables tmux-continuum
(`@continuum-restore 'on'`), which restores the last-saved environment
when the tmux server boots. The old auto-start ran
`exec tmux new-session -A -s <name>` as the command that BOOTED the
server, so our session was always created alongside whatever continuum
restored under its own saved name. `-A` can't merge two differently-named
sessions, and renaming the target via DOTFILES_TMUX_SESSION doesn't help
because the restored session keeps its old saved name.
Fix: boot the server first (without committing to a session) so
continuum's restore lands, then reconcile into a single session with the
wanted name:
- wanted session already present (running or restored) -> attach
- only a differently-named session present (stale save) -> rename it to
the wanted name and attach; restored windows/panes are preserved
- nothing running and nothing to restore -> create it fresh
The wait for continuum's async restore is gated on a resurrect save
actually existing (fresh machines pay no delay) and capped so a
corrupt/empty save can't hang shell startup. Opt-out knobs
(DOTFILES_NO_AUTOTMUX, DOTFILES_TMUX_SESSION) are unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JstvciiBKpooHQG3KL97CV
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the macOS OS-native zsh/zshrc auto-tmux startup flow to avoid creating a second tmux session when tmux-continuum restores a previously-saved session on server boot.
Changes:
- Boot the tmux server first (without creating/attaching a session) so continuum restore can run.
- Reconcile into a single “wanted” session by attaching if present, otherwise renaming a restored session or creating a new one.
- Add a short, capped wait for asynchronous restore only when a resurrect save file exists.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot review on PR #92: - Finish with a single race-safe `tmux new-session -A` (attach-or-create) instead of a bare `attach-session`. Since `exec` has already replaced the shell, attaching to a session that vanished mid-race (or whose rename just failed) would have killed the terminal; `-A` cannot. - Only rename when EXACTLY ONE differently-named session exists, so multiple restored sessions are never hijacked, and skip the no-op self-rename. - Treat `rename-session` failure as non-fatal (a concurrent shell may have created the wanted name first) — the create/attach still resolves it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JstvciiBKpooHQG3KL97CV
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
Opening a terminal created two tmux sessions (e.g.
mainandGerrrt) instead of one.Root cause:
core/tmux.confenables tmux-continuum (@continuum-restore 'on'), which restores the last-saved environment when the tmux server boots. The old auto-start block ran:as the command that booted the server. So our session was always created alongside whatever continuum restored under its own saved name.
-Acan only attach when the name matches, and the previous fix (making the name aDOTFILES_TMUX_SESSIONknob) can't help here — the restored session keeps its old saved name (main), so pointing the knob atGerrrtguarantees two sessions rather than one.Fix
Boot the server first (without committing to a session) so continuum's restore lands, then reconcile into a single session with the wanted name:
The wait for continuum's asynchronous restore is gated on a resurrect save file actually existing (fresh machines pay no delay) and capped at ~3s so a corrupt/empty save can't hang shell startup. The opt-out knobs (
DOTFILES_NO_AUTOTMUX,DOTFILES_TMUX_SESSION) are unchanged.For the reporter's case: set
DOTFILES_TMUX_SESSION=Gerrrtin~/.config/zsh/local.zsh— the stale restoredmainis now renamed intoGerrrt, and you land in one session with that name.Verification
zsh -n zsh/zshrcpasses.tmuxharness exercising all four paths (stale-main+wants-Gerrrt, fresh machine, already-restored-Gerrrt, default-no-knob) — each resolves to a single session with the expected name.Notes
The
@continuum-restoresetting itself lives in read-only vendoredcore/, so this fix is applied at the OS-native layer (the auto-start block, which already lives inzsh/zshrc) rather than by touching Core.🤖 Generated with Claude Code
Generated by Claude Code