From 047e2c4114579548733b55efb5aaf45aacbfbdb2 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:31:09 -0800 Subject: [PATCH] fix(wsl): write the Claude account pointer through stdin, not an empty argument (#41869) wsl.exe --exec refuses an empty argument with Wsl/Service/E_INVALIDARG. When a managed WSL Claude account exists but the distro is on System default, the pointer content is the empty string, so every Claude launch in that distro failed before its terminal spawned. This hits both Windows-driven WSL panes and WSL hosts, whose account env is prepared by the desktop. Fixes #41160 --- .../wsl/claude-profile-wsl-router.test.ts | 18 +++++++++++++++++- .../profiles/wsl/claude-profile-wsl-router.ts | 7 ++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts index 863eaa8ff15..972f601bd11 100644 --- a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts +++ b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts @@ -45,8 +45,13 @@ vi.mock('../../../wsl/execution/wsl-runner', () => ({ if (guest.failure) { return { ...guest.failure, stderr: '', timedOut: false } } + // Real wsl.exe --exec refuses an empty argument before the guest runs. + if (spec.args?.some((arg) => arg === '')) { + return { code: 1, stdout: '', stderr: 'Wsl/Service/E_INVALIDARG', timedOut: false } + } const result = spawnSync('/bin/sh', ['-c', spec.script ?? '', 'sh', ...(spec.args ?? [])], { - encoding: 'utf8' + encoding: 'utf8', + input: spec.input }) return { code: result.status, stdout: result.stdout, stderr: result.stderr, timedOut: false } } @@ -141,6 +146,17 @@ describe.skipIf(!posixHost)('ClaudeWslProfileRouter', () => { expect(readFileSync(f.pointer, 'utf8')).toBe(homeB) }) + it('launches on System default while a managed WSL account still exists', async () => { + const f = fixture() + mkdirSync(join(f.pointer, '..'), { recursive: true }) + writeFileSync(f.pointer, f.profileHome) + f.wsl.Ubuntu = null + await expect(f.router.prepareLaunch('Ubuntu')).resolves.toMatchObject({ + provenance: 'wsl:Ubuntu:system' + }) + expect(readFileSync(f.pointer, 'utf8')).toBe('') + }) + it("runs an account with no login of its own on the guest's ~/.claude while that is signed in to it", async () => { const f = fixture() mkdirSync(f.profileHome, { recursive: true }) diff --git a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts index 4964813369c..42fb95f7571 100644 --- a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts +++ b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts @@ -262,10 +262,11 @@ async function writePointer(distro: string, pointer: string, home: string): Prom if (current === home) { return } + // wsl.exe --exec rejects an empty argument (E_INVALIDARG), and System default writes ''; pass content on stdin. await runGuest(distro, { - script: - 'umask 077; mkdir -p -- "${1%/*}" && printf %s "$2" > "$1.tmp" && mv -f -- "$1.tmp" "$1"', - args: [pointer, home], + script: 'umask 077; mkdir -p -- "${1%/*}" && cat > "$1.tmp" && mv -f -- "$1.tmp" "$1"', + args: [pointer], + input: home, loginPath: 'none' }) }