Skip to content

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

Closed
vaishnavmhetre wants to merge 1 commit into
anomalyco:devfrom
vaishnavmhetre:fix/electron-macos-sidecar-cleanup
Closed

vaishnavmhetre wants to merge 1 commit into
anomalyco:devfrom
vaishnavmhetre:fix/electron-macos-sidecar-cleanup

Conversation

@vaishnavmhetre

@vaishnavmhetre vaishnavmhetre commented Apr 17, 2026 •

Copy link
Copy Markdown

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?

@vaishnavmhetre

Copy link
Copy Markdown
Author

Thanks for the review @Brendonovich — you're right, the sidecar CLI is gone. I see spawnLocalServer now imports virtual:opencode-server and calls Server.listen() in-process, so there's no separate child process to leak anymore.

That said, the window-all-closed handler is still missing. On macOS, closing the last window leaves the Electron app running in the dock with the in-process server still consuming memory — the user has to Cmd+Q or Force Quit to actually free resources. Since there's no dock menu to reopen the window, the app just sits there invisible and unreachable.

Would it still make sense to add the window-all-closed → quit behavior so closing the window actually releases resources? Happy to update the PR description to reflect the current architecture if so, or close it if you'd prefer to handle this differently.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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