[feature] allow overwriting existing sessions instead of skipping them
Current implementation behavior: All sessions are created with idempotent logic — existing sessions will be skipped entirely. This is inconsistent with the operational logic of the tmux recurrent plugin on Linux, which brings inconvenience and easily causes confusion. I want to allow overwriting existing sessions instead of skipping them; the relevant code is attached here.
Show-Progress -current ($si + 1) -total $totalSessions -sessionName $sessionName
--
# Check if session already exists (idempotent)
$null = & $PSMUX has-session -t $sessionName 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " Session '$sessionName' already exists, skipping" -ForegroundColor Yellow
… $summary = "psmux-resurrect: restored $restoredCount/$totalSessions, skipped $($skipped.Count) (already running)"
Hey @gigberg, thanks for including the exact code you were looking at, that made this quick to act on. Before implementing anything I went and checked your claim about tmux resurrect's actual behavior against its real source (scripts/restore.sh in tmux plugins/tmux resurrect), since I wanted to know precisely what "consistent with the Linux plugin" would mean rather than assume.
What I found is that tmux resurrect doesn't quite skip OR overwrite outright, it merges. Its restore_pane function checks pane, then window, then session existence in that order, and adds windows and panes into an existing session if one is already running rather than creating a fresh one, with pane level kill and recreate only in a specific "restoring from scratch" mode. That's a meaningfully bigger change than a straight overwrite, so rather than build that whole merge algorithm, I went with the simpler, explicit thing your snippet was actually asking for: an opt in that kills and recreates the whole session from the save.
Landed in commit 2ab425da27cb3c2e4a31b15607b8c66cd0c22421 on main. New option, off by default so nobody's current behavior changes:
set -g @resurrect-overwrite 'on'
With it on, a saved session name that's already running gets killed and rebuilt from the save (on top of #32's immutable %id pane targeting, which just landed too, so overwritten sessions get the same correctness improvements as fresh ones). Without it, behavior is exactly what you have today, skip and move on. Documented in plugin.conf, the psmux-resurrect.ps1 header, and the README, plus a new hermetic test (tests/test_resurrect_overwrite.ps1) asserting the skip path never calls kill-session or new-session, the overwrite path calls kill-session strictly before new-session, and overwrite mode doesn't call kill-session at all when there's nothing to kill. I also ran both paths end to end against the real binary: default restore left a live session's own changes untouched, overwrite mode killed and rebuilt it from the save correctly.
If a true tmux resurrect style merge (adding missing windows into a running session instead of an all or nothing kill) would still be useful to you, happy to hear about your use case in a new issue, that's a real follow up worth considering separately. For now this should unblock the workflow you described. Closing this out.