Restore claude.exe after an interrupted auto-update on Windows#167
Conversation
|
Thanks for this — the diagnosis and the fix itself look solid. The only blocker is that the branch has drifted out of date with What conflicts and whyWhile this PR was open, ...(kind === "opencode" ? [selectOpenCodeBaselinePowerShell()] : []),
agent.resumePowerShellCommand,
kind === "codex" ? codexNpmPrefixPowerShellCleanup() : "",
].filter(Boolean).join("; ");Your change adds How to resolvegit fetch origin
git checkout fix/claude-exe-restore-after-interrupted-update
git rebase origin/mainWhen it stops on ...(kind === "opencode" ? [selectOpenCodeBaselinePowerShell()] : []),
...(kind === "claude" ? [repairClaudeBinaryPowerShell()] : []),
// ...rest of the array unchanged from main...
Then finish up and re-verify: git add client/electron/terminal-launch.ts
git rebase --continue
npm --prefix client run build:electron
npm --prefix client run test:electron # includes your terminal-launch tests
git push --force-with-leaseA quick re-run of your |
Claude Code's auto-updater renames the running bin/claude.exe to claude.exe.old.<timestamp> (Windows locks a running binary, so it must be moved aside before the replacement is written) and then drops in the new exe. If that second step fails, bin/ is left with only the backup and no claude.exe. Get-Command still resolves the npm shim (claude.ps1/.cmd), so the existing "not installed or not on PATH" guard passes -- but launching the shim then dies with CommandNotFoundException because it forwards to the missing bin/claude.exe, and every subsequent pane launch fails the same way until the user repairs the install by hand. Add repairClaudeBinaryPowerShell(), wired into both the fresh and resume Claude PowerShell launch paths: when bin/claude.exe is missing but a claude.exe.old.* backup exists, restore the newest backup before invoking the shim. A healthy install is left untouched (guarded on the exe being absent). Verified the generated PowerShell parses cleanly and functionally restores a simulated broken install while leaving a healthy one alone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ad931e5 to
714e72b
Compare
Problem
On Windows, launching a Claude pane through Context Workspace / Athena intermittently fails with:
Claude Code's auto-updater renames the running
bin/claude.exetoclaude.exe.old.<timestamp>(Windows locks a running binary, so it must be moved aside before the replacement is written), then drops in the new exe. When that second step is interrupted,bin/is left with only the backup and noclaude.exe:Get-Command claudestill resolves the npm shim (claude.ps1/claude.cmd), so the existingif (-not $resolvedAgent) { ... not installed or not on PATH }guard passes. The shim then forwards to the missingbin/claude.exeand dies withCommandNotFoundException— and every subsequent pane launch fails identically until the user repairs the install by hand.Closes #166.
Fix
Add
repairClaudeBinaryPowerShell(), wired into both the fresh (launchPowerShellCommand) and resume (launchResumePowerShellCommand) Claude launch paths, right after the agent-resolution guard. Whenbin/claude.exeis missing but aclaude.exe.old.*backup exists, it restores the newest backup (byLastWriteTime) before invoking the shim and prints a yellow status line. A healthy install is untouched — the copy is guarded on the exe being absent.It probes the package
bin/relative to the resolved shim, the shim dir itself (in caseGet-Commandresolves the exe directly), and the default%APPDATA%\npmglobal prefix.Testing
node --test tests/terminal-launch.test.mjs— 21 pass, including two new tests asserting the repair is present in both Claude paths and absent for codex/opencode.[Parser]::ParseFile— no syntax errors.claude.exefrom the backup and prints the message; a second run against a healthy install leaves the real exe untouched.🤖 Generated with Claude Code