restart_claude_desktop hardening: Linux pkill can kill Claude Code sessions; macOS kill/relaunch race; Windows MSIX shortcut missing #33

Closed
opened 2026-07-12 12:44:12 -04:00 by the_og · 0 comments
Owner

Found in audit of main @ 06326e5. Three platform problems in bcc_core.py restart_claude_desktop() (~L1826–1905).

1. Linux — harmful and wrong target (worst of the three).
_restart_claude_desktop_linux() runs pkill claude — no -x, so it substring-matches and can kill the user's running Claude Code CLI processes (active sessions, agents) and anything else with "claude" in the name. It then launches claude detached — which on Linux is the Claude Code CLI, not Claude Desktop; spawning it headless/detached does nothing useful. There is no official Claude Desktop for Linux.
Fix: at minimum use pkill -x against an actual desktop binary name and launch the real desktop entry point if one is configured; realistically, hide/disable the Restart button on Linux (gate _offer_restart_button() on platform) until there is a real target.

2. macOS — kill/relaunch race.
pkill -x Claude is fire-and-forget and open -a Claude runs immediately after. If the old instance hasn't exited yet, open can re-activate the dying instance (config never reloaded) or the relaunch lands mid-teardown. Fix: after pkill, poll for process exit (e.g. pgrep -x Claude up to ~5 s) before open -a Claude. Run off the UI thread if the wait is added (button handler currently calls it synchronously — MainWindow._restart_claude_desktop).

3. Windows — relaunch fails for MSIX/Store installs.
Relaunch uses the Start-menu shortcut %APPDATA%\Microsoft\Windows\Start Menu\Programs\Claude.lnk. For an MSIX/Store install (which BCC now explicitly detects — see detect_msix_claude) that shortcut doesn't exist, so taskkill succeeds and the relaunch fails: BCC kills Claude and can't bring it back. Fix: check the shortcut exists before killing; if absent, try explorer.exe shell:AppsFolder\<PackageFamilyName>!App for the detected MSIX package, or refuse with a clear message instead of killing first.

Acceptance

  • Linux: Restart button never appears (or a correct implementation is proven); no pkill pattern that can match claude CLI processes remains.
  • macOS: restart waits for the old process to exit before relaunching (bounded); UI stays responsive.
  • Windows: when the shortcut is missing, Claude is not killed; either the MSIX launch path is used or the user gets an actionable error.
  • Unit tests for the decision logic (platform gating, shortcut-existence check) — process-level effects can stay untested.
**Found in audit of `main` @ 06326e5.** Three platform problems in `bcc_core.py` `restart_claude_desktop()` (~L1826–1905). **1. Linux — harmful and wrong target (worst of the three).** `_restart_claude_desktop_linux()` runs `pkill claude` — no `-x`, so it substring-matches and can kill the user's running **Claude Code CLI** processes (active sessions, agents) and anything else with "claude" in the name. It then launches `claude` detached — which on Linux is the Claude Code CLI, not Claude Desktop; spawning it headless/detached does nothing useful. There is no official Claude Desktop for Linux. Fix: at minimum use `pkill -x` against an actual desktop binary name and launch the real desktop entry point if one is configured; realistically, hide/disable the Restart button on Linux (gate `_offer_restart_button()` on platform) until there is a real target. **2. macOS — kill/relaunch race.** `pkill -x Claude` is fire-and-forget and `open -a Claude` runs immediately after. If the old instance hasn't exited yet, `open` can re-activate the dying instance (config never reloaded) or the relaunch lands mid-teardown. Fix: after pkill, poll for process exit (e.g. `pgrep -x Claude` up to ~5 s) before `open -a Claude`. Run off the UI thread if the wait is added (button handler currently calls it synchronously — `MainWindow._restart_claude_desktop`). **3. Windows — relaunch fails for MSIX/Store installs.** Relaunch uses the Start-menu shortcut `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Claude.lnk`. For an MSIX/Store install (which BCC now explicitly detects — see `detect_msix_claude`) that shortcut doesn't exist, so `taskkill` succeeds and the relaunch fails: BCC kills Claude and can't bring it back. Fix: check the shortcut exists **before** killing; if absent, try `explorer.exe shell:AppsFolder\<PackageFamilyName>!App` for the detected MSIX package, or refuse with a clear message instead of killing first. **Acceptance** - Linux: Restart button never appears (or a correct implementation is proven); no `pkill` pattern that can match `claude` CLI processes remains. - macOS: restart waits for the old process to exit before relaunching (bounded); UI stays responsive. - Windows: when the shortcut is missing, Claude is **not** killed; either the MSIX launch path is used or the user gets an actionable error. - Unit tests for the decision logic (platform gating, shortcut-existence check) — process-level effects can stay untested.
the_og added the P1 label 2026-07-12 12:44:12 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: the_og/better-claude-config#33