Skip to content

fix(claude-accounts): restart WSL Claude panes after an account switch - #31945

Merged
nwparker merged 2 commits into
mainfrom
nwparker/fix-31486-wsl-account-restart
Oct 22, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/fix-31486-wsl-account-restart

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​90
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

ELI5

If Claude runs inside WSL on Windows and you switch Claude accounts with "Always restart" turned on, Orca should restart those Claude panes on the new account. It didn't restart them. Now it does.

What Changed

Before: on a Windows host, switching the Claude account left every Claude pane running in WSL on the old account. The toast said "Running sessions keep their account", even with "Always restart" (or "Ask") selected.

After: WSL Claude panes are included in the restart set, the same way host panes are. Each one resumes its own conversation (claude --resume <id>) on the new account once its current turn ends.

Two separate blockers caused this. Each one alone was enough to drop every WSL pane:

  1. Foreground-process gate (src/renderer/src/lib/claude-session-account-move.ts). findMovableClaudeSessions kept a pane only if the Windows process table showed Claude in the foreground. WSL2 guest processes aren't in that table, so a WSL pane only ever shows wsl.exe. For a WSL switch, the scan now uses evidence from the execution host instead: the Claude hook status row the guest reports (already required), checked with the existing resolvePaneAgentSessionId. That check drops a pane whose guest shell has signalled, through OSC 133;D, that Claude is back at the prompt. Host panes keep the process check unchanged.
  2. Resume builder declined WSL projects (src/renderer/src/lib/agent-account-restart-startup.ts). resolveAgentAccountRestartResumeStartup returned nothing for any project whose runtime resolves to WSL: a \\wsl.localhost\... worktree, or a WSL Windows runtime default. So no Claude candidate was ever built. That guard now applies to Codex only. A WSL Claude relaunch already lands on the selected account: main's spawn path (spawn-preflight.ts → prepareClaudeAuth) sets the selected WSL profile's CLAUDE_CONFIG_DIR and account pointer. The resume command uses POSIX quoting for the guest shell.

The other suspect, matching the transcript path against wslLinuxAuthPath, turned out to be correct. Registration saves the guest CLAUDE_CONFIG_DIR (…/claude-profiles/<id>/home), and the guest hook reports <that>/projects/…. With Claude made visible to the process gate, the WSL panes matched the right account.

Why

The AGENTS.md rule is that the execution host owns agent status. For a WSL pane, the execution host is the guest, and its hooks and shell marks are the only evidence available to a Windows host. A Windows-side wsl.exe probe of the guest process table would be a new, slower mechanism. Neither the restart path nor any other agent-status consumer does that today.

SSH panes and paired-runtime (server) panes are left out on purpose, as before. A local Claude account switch doesn't change those machines' logins, and the restart executor only respawns local PTYs. That matches how Codex account restarts behave.

Linked Issue

Fixes #31486

Thanks to @Kooooojun for the detailed report, including the /proc/<pid>/environ evidence and the confirmation that a manual resume works.

Visual Proof

N/A. No UI changes. The existing toast and restart flow now include WSL panes.

Testing

  • Automated tests added/updated

  • I manually tested these changes locally (no WSL machine available; see below)

  • claude-session-account-move.test.ts: a WSL switch built from the real data shapes: UNC managedAuthPath, guest wslLinuxAuthPath, a guest transcript path, a WSL project runtime, and a Windows foreground of wsl.exe with no confirmation. It fails on main and needs both fixes. A pane that is back at the guest shell (OSC 133;D) is left out.

  • agent-account-restart-startup.test.ts: a Claude resume for a WSL runtime resolved through the real resolver, once from a UNC worktree path and once from a WSL runtime default. Fails on main. The Codex WSL test is unchanged and still passes.

  • The test files that import the changed modules pass (8 files, 110 tests), along with the full local static job.

What was not verified live: there was no Windows + WSL machine, so the end-to-end flow (switch account → WSL pane restarts → /status shows the new account) was not run. The main-side account repin for a WSL Claude spawn was confirmed by reading the code, not by running it. The reporter's manual workaround (resuming through Orca's shell wrapper lands on the new account) matches it.

Known limitations

  • A Claude that died without its SessionEnd hook can still be restarted. A WSL Claude killed by a signal, for example while its tab is parked, can leave its hook row behind. Normal exits send SessionEnd and the row is dropped. A Windows host can't see the guest process, so a stale row still counts as a running session. The worst case is that the pane resumes that conversation in place on the new account, with no data loss.
  • Restored rows aren't fully filtered out. resolvePaneAgentSessionId doesn't strictly reject rows restored after an Orca restart. For a restoredUnconfirmed row it falls back to the pane's sleeping-session record. An idle done row restored after a restart counts as live, because only non-terminal states are marked unconfirmed. The outcome is the same: possibly one resume in place on the new account.

AI Disclosure

Review

  • Codex (gpt-6.1-sol, high), base pinned at ea60ec5d:
    • Round 1 raised one P2: the stale row after a parked WSL Claude is killed. Dismissed as the known limitation above (worst case is a resume in place).
    • Round 2 on this head: clean.
  • Independent Opus reviews:
    • Round 1 found a P1, the resume builder's WSL guard, which is fixed in the second commit.
    • A fresh Opus review of this head: clean, no P0–P2 findings.
  • Docker managed-orcad lane: not run. The change touches only renderer account-switch restart selection, not SSH, managed-server, terminal routing or ownership.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

No wire or IPC changes, so client/host version mismatches aren't affected. Mobile has no Claude account-switch restart flow. Folder workspaces go through the same lane and runtime resolution as worktrees.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

A Windows host cannot see processes inside WSL, so the foreground gate dropped
every WSL pane from the restart set. WSL panes now use the guest's hook status
and shell marks, the evidence the execution host owns.

Reported-by: Kooooojun
The account-restart resume builder declined every WSL project runtime, so a
WSL worktree or a WSL Windows runtime default left no Claude candidate to
restart. Keep that guard for Codex only; a WSL Claude launch reads the
guest's selected-account pointer.
@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c9ba7e7e-9224-425d-affc-0a5a432c705a
📥 Commits

Reviewing files that changed from the base of the PR and between ca9abc6 and 4c0bf7b.

📒 Files selected for processing: 4
  • src/renderer/src/lib/agent-account-restart-startup.test.ts
  • src/renderer/src/lib/agent-account-restart-startup.ts
  • src/renderer/src/lib/claude-session-account-move.test.ts
  • src/renderer/src/lib/claude-session-account-move.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📝 Walkthrough

Claude restart startup now proceeds for Claude when a Windows project resolves to a WSL runtime. WSL session selection now includes panes with a non-null agent session ID without checking foreground processes. Tests cover WSL runtime resolution, Claude session resume metadata, and selecting an active WSL pane.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 4c0bf

The restart path is configured to resume Claude in the selected WSL runtime. No blocking issue was established; live Windows–WSL validation would provide additional confidence.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: restarting Claude panes running in WSL after an account switch.
Description check Passed The description is complete and matches the repository template. It explains the user impact, implementation, rationale, linked issue, testing, limitations, review status, and cross-platform considera…
Linked Issues check Passed For #31486, the production changes address both reported blockers. findMovableClaudeSessions uses guest hook and shell evidence for WSL targets, while non-WSL targets retain foreground-process inspe…
Out of Scope Changes check Passed The four changed files stay within #31486. The two production changes select WSL Claude panes and build their resume startup. The two test changes verify those behaviors. No unrelated product area or …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files.
Full details: Description check

Explanation

The description is complete and matches the repository template. It explains the user impact, implementation, rationale, linked issue, testing, limitations, review status, and cross-platform considerations. It also documents that live Windows and WSL testing was not available.

Full details: Linked Issues check

Explanation

For #31486, the production changes address both reported blockers. findMovableClaudeSessions uses guest hook and shell evidence for WSL targets, while non-WSL targets retain foreground-process inspection. resolveAgentAccountRestartResumeStartup now permits WSL Claude resumes and keeps the WSL restriction for Codex. The restart command remains claude --resume &lt;id&gt;. Tests cover an active WSL pane, exclusion after the guest shell mark, and WSL runtime resolution for UNC worktrees and WSL defaults.

Full details: Out of Scope Changes check

Explanation

The four changed files stay within #31486. The two production changes select WSL Claude panes and build their resume startup. The two test changes verify those behaviors. No unrelated product area or unsupported runtime behavior is changed.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit d8aeb1f into main Oct 22, 2026
32 checks 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.

[Bug]: "Always restart" does not restart Claude terminal panes on a WSL runtime after an account switch

1 participant