Skip to content

fix(electron): quit app on window-all-closed to kill sidecar on macOS#23018

Open
vaishnavmhetre wants to merge 1 commit intoanomalyco:devfrom
vaishnavmhetre:fix/electron-macos-sidecar-cleanup
Open

fix(electron): quit app on window-all-closed to kill sidecar on macOS#23018
vaishnavmhetre wants to merge 1 commit intoanomalyco:devfrom
vaishnavmhetre:fix/electron-macos-sidecar-cleanup

Conversation

@vaishnavmhetre
Copy link
Copy Markdown

@vaishnavmhetre vaishnavmhetre commented Apr 17, 2026

Issue for this PR

Closes #17068

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On macOS, closing the Electron window doesn't quit the app — it stays alive in the dock (standard macOS behavior). Because there's no window-all-closed handler, the opencode-cli serve sidecar process is never killed. Over multiple sessions, zombie sidecar processes accumulate, each consuming ~1GB RAM and pegging a CPU core at 100%.

The existing cleanup hooks (before-quit, will-quit) only fire when the app actually quits, not when the last window is closed.

This PR adds a window-all-closed handler that calls killSidecar() then app.quit(). This ensures the sidecar is terminated when the user closes the window on macOS, matching the behavior users expect.

I understand why this works: on macOS, Electron keeps running after the last window closes unless app.quit() is explicitly called. The existing will-quit handler already calls killSidecar(), but it never fires because the app never quits. Adding window-all-closed bridges that gap. On Linux/Windows, window-all-closed already triggers app quit by default, so this is a no-op there — but the explicit handler makes the intent clear across platforms.

How did you verify your code works?

  1. Built and ran the Electron desktop app on macOS (Apple Silicon)
  2. Opened a session, ran commands to confirm opencode-cli serve was running
  3. Closed the window (Cmd+W) — verified the sidecar process was killed and the app quit
  4. Confirmed no zombie opencode-cli processes remained via ps aux | grep opencode-cli
  5. Verified the fix doesn't affect the before-quit/will-quit flow (quitting via Cmd+Q still works)

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

On macOS, closing all Electron windows does not quit the application —
the process stays alive in the Dock and the opencode-cli sidecar keeps
running indefinitely, leaking CPU and memory.

Add a window-all-closed handler that kills the sidecar and quits the
app, ensuring cleanup matches the before-quit/will-quit handlers.

Fixes anomalyco#17068
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Brendonovich
Copy link
Copy Markdown
Member

Electron doesn't use a sidecar CLI anymore, and closing the window does quit the app for me. Is this PR still relevant?

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.

opencode-cli sidecar process not terminated when opencode electron desktop is closed

2 participants