Skip to content

fix(wsl): suppress alerts when the Windows Terminal window is focused - #156

Merged
mohak34 merged 3 commits into
mohak34:mainfrom
Nicholas-hosein-pw:main
Dec 1, 2026
Merged

mohak34 merged 3 commits into
mohak34:mainfrom
Nicholas-hosein-pw:main

Conversation

@Nicholas-hosein-pw

Copy link
Copy Markdown
Contributor

Summary

Fixes suppressWhenFocused when running OpenCode inside WSL with Windows Terminal.
Related: #155

With "suppressWhenFocused": true, completion notifications appeared even while the OpenCode terminal window was focused.

Notification delivery already recognizes WSL and uses Windows notifications, but focus detection only selects the Windows backend when process.platform === "win32". Inside WSL, the runtime reports linux, so it follows the Linux desktop focus path instead.

Changes

  • Add a WSL Windows Terminal focus backend, selected under WSL when WT_SESSION is set.
  • Capture the foreground Windows Terminal window at startup, or the sole terminal window when only one exists.
  • Check the captured window handle and process ID before treating it as focused.
  • Run PowerShell queries asynchronously with a five-second timeout and share in-flight queries across concurrent checks.
  • Await asynchronous focus results during delivery.
  • Preserve existing tmux, WezTerm and Zellij pane checks.
  • Keep notifications enabled when startup capture is ambiguous, a query fails, the captured window closes, or the session is accessed through SSH.
  • Add regression tests and update the README, behavior spec and changelog.

No new configuration option is required. The fix uses the existing suppressWhenFocused setting.

Host coverage and limitations

  • OpenCode 1: applies to focus-suppressed alerts and event commands.
  • OpenCode 2: applies to terminal-side alerts. Server-side event commands remain independent of focus.
  • Detection is window-level, not tab-level. Another tab in the same Windows Terminal window still counts as focused.
  • When multiple Windows Terminal windows are open, start OpenCode with its intended terminal window focused.
  • The captured window is not replaced with another terminal at event time.

Verification

Tested on WSL2 / Ubuntu 24.04 with Windows Terminal and OpenCode 1.18.35, without tmux, Zellij or WezTerm:

  • Loaded this fork’s built plugin directly.
  • Confirmed no popup appears while the OpenCode terminal window is focused.
  • Confirmed a popup appears when another application window is focused.
  • 122 targeted tests passed; one native-Windows test skipped.
  • Typecheck and build passed.
  • A live, read-only Windows focus probe returned the terminal-window information.
  • Built V1 plugin smoke test passed using an isolated configuration and stubbed notification delivery.

Regression tests cover focused and unfocused windows, ambiguous startup, closed or replaced windows, failed and malformed queries, spawn failures, concurrent queries, asynchronous delivery, SSH, and inactive panes. Existing Linux, KDE and GNOME focus tests also passed.

Live popup behavior was verified on OpenCode 1. OpenCode 2 is covered by shared-code and automated checks but was not manually tested. Native Windows and macOS were not manually tested.

Implemented with OpenAI gpt-6.1-sol via OpenCode.

mohak34 and others added 2 commits December 1, 2026 20:02
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mohak34
mohak34 merged commit f52e51e into mohak34:main Dec 1, 2026
@mohak34

mohak34 commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thanks for this. It's merged and out as 1.3.0-beta.0 on the npm beta tag.

I added two commits on top: the WSL window capture now runs in the background so it no longer delays OpenCode startup, and the probe output parser validates its input more strictly. Your logic is unchanged.

Could you test it on your WSL + Windows Terminal setup? Set the plugin in opencode.json to:

{ "plugin": ["@mohak34/opencode-notifier@1.3.0-beta.0"] }

Then check:

  1. Start OpenCode with its Windows Terminal window in front. Send a prompt and keep the window focused: no popup.
  2. Send another prompt and switch to a different app: popup appears.
  3. If anything looks off, run with OPENCODE_NOTIFIER_DEBUG=1 and paste the WSL focus: lines.

One behavior change to watch for: right after OpenCode starts, alerts are not suppressed for the second or so until the window capture finishes.

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.

2 participants