Skip to content

fix(zsh): stop auto-tmux spawning a second session beside continuum's restore#92

Merged
Gerrrt merged 2 commits into
mainfrom
claude/dotfiles-duplicate-tmux-sessions-1gsiha
Jul 19, 2026
Merged

fix(zsh): stop auto-tmux spawning a second session beside continuum's restore#92
Gerrrt merged 2 commits into
mainfrom
claude/dotfiles-duplicate-tmux-sessions-1gsiha

Conversation

@Gerrrt

@Gerrrt Gerrrt commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Problem

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 block ran:

exec tmux new-session -A -s "${DOTFILES_TMUX_SESSION:-main}"

as the command that booted the server. So our session was always created alongside whatever continuum restored under its own saved name. -A can only attach when the name matches, and the previous fix (making the name a DOTFILES_TMUX_SESSION knob) can't help here — the restored session keeps its old saved name (main), so pointing the knob at Gerrrt guarantees 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:

  • wanted session already present (running or restored) → attach to it
  • 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 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=Gerrrt in ~/.config/zsh/local.zsh — the stale restored main is now renamed into Gerrrt, and you land in one session with that name.

Verification

  • zsh -n zsh/zshrc passes.
  • Stubbed-tmux harness 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-restore setting itself lives in read-only vendored core/, so this fix is applied at the OS-native layer (the auto-start block, which already lives in zsh/zshrc) rather than by touching Core.

🤖 Generated with Claude Code


Generated by Claude Code

… 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
Copilot AI review requested due to automatic review settings July 19, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread zsh/zshrc Outdated
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
@Gerrrt
Gerrrt merged commit 930e3d9 into main Jul 19, 2026
7 checks passed
@Gerrrt
Gerrrt deleted the claude/dotfiles-duplicate-tmux-sessions-1gsiha branch July 19, 2026 16:11
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.

3 participants