opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[Bug] OpenCode2 CLI Endlessly Pops Up Windows on Windows

Open TGSAN opened this issue 2 months ago • 11 comments

Description

After installing with bun install -g --trust @opencode/cli, run opencode2 in cmd or PowerShell. When opencode2 starts the background server, a foreground window keeps popping up and immediately closing (the window constantly steals focus, making it almost impossible to use).
Even if you exit the foreground CLI, it cannot be stopped. By inspecting with Process Explorer, I found that the background opencode.exe server process continuously launches tasklist.exe, and tasklist.exe creates a foreground console window that steals focus.

Plugins

No plugins that can run on V2 (none are compatible)

OpenCode version

v2.0.18

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

Windows 11 25H2 x64

Terminal

Windows Terminal

TGSAN avatar Sep 28 '26 15:09 TGSAN


This issue might be a duplicate of an existing issue. Please check:

  • #50868: the background service spawns a child process that opens a visible Windows console window.

github-actions[bot] avatar Sep 28 '26 15:09 github-actions[bot]

Hey! Can you tell me what kind of bun version are you running?

neriousy avatar Sep 28 '26 15:09 neriousy

Also - what do you mean by "No plugins that can run on V2 (none are compatible)"

neriousy avatar Sep 28 '26 16:09 neriousy

Could you try temporarily removing any V1 plugins to help us rule out plugin loading? Back up or move the contents of your global ~/.config/opencode/plugins/ and any project .opencode/plugins/ directories, and remove third-party entries from the plugins arrays in your global and project opencode.json(c) files. Then run opencode service restart, launch opencode2 again, and let us know whether the window/tasklist loop still happens. You can restore the plugins and config afterward. This is a diagnostic, not yet a confirmed cause.

opencode-agent[bot] avatar Sep 28 '26 17:09 opencode-agent[bot]

Also - what do you mean by "No plugins that can run on V2 (none are compatible)"

Hi, my version of Bun I am using is v1.4.2. I tried adding the --standalone parameter to start opencode2 and found that windows no longer pop up repeatedly. I had installed the omo (oh-my-openagent) plugin, which is incompatible with V2. After removing it, this issue appears to stop occurring even without the --standalone parameter.

TGSAN avatar Sep 28 '26 21:09 TGSAN

Another data point on 2.0.28: spawn volume, plus two un-hidden local spawn paths

Measured on 2.0.28, after #52594 was closed. Environment:

  • opencode version: 2.0.28 (@opencode/cli, npm global, latest)
  • OS: Windows_NT 10.0.26200.9457 (win32 x64)
  • Terminal: Windows Terminal (WT_SESSION set), TERM=xterm-256color
  • Shell: cmd.exe (%ComSpec%); opencode shell config is bash
  • Install/channel: release, latest
  • Active plugins: opencode-gemini-auth@latest (config), local ~/.config/opencode/plugins/ponytail.ts and rtk.ts
  • Git: 2.48.1.windows.1

1. Spawn volume in opencode.log

14,438  spawn git.EXE                  (entire log)
12,907  of those target the snapshot shadow repo (--git-dir .../snapshot/<id>/.git ≈ 89%)

Per minute on 2026-10-14 while a session was active:

08:53  88     08:56  59     09:00  39
08:54 113     08:57  47     09:01  67
08:55 117                   09:02  31

≈100 git.exe per minute, ≈1.7 spawns/second. Same order as the 60–68/min in #52266, and consistent with #52433 (snapshot service, closed administratively).

2. Local plugin spawn path without windowsHide

~/.config/opencode/plugins/ponytail.ts ran this on every session.hook("context") — once per model call, 3 git invocations per hook:

execFileSync("git", argv, { cwd, stdio: "pipe", timeout: TIMEOUT_MS })   // no windowsHide

Adding windowsHide: true removes it. rtk.ts in the same directory already passes windowsHide: true, so this is the whack-a-mole described in #53730, just inside a local file I control.

3. opencode-gemini-auth spawns a detached console program without windowsHide

dist/index.js:

const child = spawn(command, args, { stdio: "ignore", detached: true });  // command = rundll32 on win32

rundll32 is console-subsystem; detached: true with no windowsHide allocates a visible console. Only on the OAuth login path, so a one-off flash rather than a recurring one.

4. #52594 is closed unmerged, and no release carries the service-level fix

  • #52594 "fix(cli): give the Windows service a hidden console": created 2026-10-01, closed 2026-10-12, draft: true, merged: false.
  • grep -c hidden-console in the 2.0.28 bundle (bin/opencode.exe, 212,916,616 bytes) returns 0, so the fix is not in this release.
  • The bundle does contain the spawner default:
let S = i.detached ?? h !== "win32"; return { ...a, detached: S, shell: i.shell, windowsHide: i.windowsHide ?? !S }

On win32 that hides spawned children unless the caller passes detached: true, which flips windowsHide to false. Both the service start and the gemini-auth call above have that shape.

Open questions

  1. Does the snapshot git runner pass through that spawner (making the ~100/min already hidden), or does it spawn directly? I could not confirm this from the minified bundle.
  2. Should windowsHide: true (or CREATE_NO_WINDOW) be forced for every child of the service regardless of caller options, rather than only defaulted? The current default is what makes plugin detached: true and execFileSync calls visible.

Symptom changes

  • Flashes stopped on my machine after two changes applied together: windowsHide: true in the local plugin, and "snapshots": false in opencode.jsonc.
  • I did not isolate them, so I cannot say which one accounts for it. The snapshot path is 89% of the spawn volume, so it is the one I would test first — restoring "snapshots": true while keeping the plugin fix would separate them.
  • --standalone, as @TGSAN found, avoids it entirely — consistent with the shared service being the console-less parent.

gammarinaldi avatar Oct 14 '26 09:10 gammarinaldi

Data point on 2.0.32: the background service has no console, measured

I reproduce this on @opencode/cli 2.0.32 (npm global, latest). Windows 11, Windows Terminal set as the default terminal application, TUI running in a Windows Terminal tab.

The --standalone result from @TGSAN and @gammarinaldi holds on 2.0.32. I probed both server types with AttachConsole(pid) on the live machine:

process has a console?
opencode.exe serve --service (background service) no — AttachConsole fails with error 6 (ERROR_INVALID_HANDLE)
opencode.exe serve --stdio --port 0 (private server, --standalone) yes
the TUI process yes

So the background service is a console-less parent. This is measured directly, not inferred from the code. Windows gives a new console to every console child that does not set CREATE_NO_WINDOW. The default terminal application shows that console. In my setup it becomes a new Windows Terminal tab, and the tab takes focus.

Test method: I ran the usual command bursts (git probes, parallel cmd and pwsh children, as reported on #52281). With --standalone: no flash, no focus steal. With the background service: new tabs appeared, titled with the path of a child exe (C:\Program Files\...), and they took focus. I have a 22 s screen recording; I can attach it on request.

One trap for other users: the background service stays alive after the TUI exits. If you start opencode again without --standalone, the client connects to that console-less service, and the flashing returns. Run opencode service stop to remove it.

stdray avatar Oct 18 '26 20:10 stdray

Thanks for the detailed report, and for tracking the windows down to tasklist.exe with Process Explorer.

I think this is a duplicate of #52266. That is the issue tracking this problem: on Windows, OpenCode 2's background service (opencode serve --service) runs detached with no console of its own. So every console program it starts without the "no window" flag opens a visible window that takes focus, which is why it continues after you exit the CLI.

Possible duplicates and closely related issues, ordered from most to least likely:

  • #52266: the same problem. Console processes started by the v2 background service each flash a visible window; this is where it is being tracked.
  • #52281: the same symptom, with cmd.exe/git windows taking focus in bursts. Commenters there traced part of it to a plugin.
  • #59478: the same symptom on 2.1.4; it was already pointed to #52266.
  • #52594: a proposed fix (closed without being merged) that refers to this issue. It says the tasklist calls here come from plugin code (omo), not from OpenCode itself.

As far as I can tell, OpenCode itself does not run tasklist, so this is most likely coming from a plugin. Even if you think none of your plugins work on v2, one listed in your config may still be loading. Removing it from your config should stop the windows. Starting with --standalone reportedly avoids the problem too, because the server then runs inside your terminal's console.

The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

opencodejr[bot] avatar Oct 28 '26 02:10 opencodejr[bot]

We haven't heard back in the past day, so I'm closing this as a duplicate of #52266. That issue tracks the same problem: on Windows, console programs (like the tasklist.exe you found) started by OpenCode 2's background service each open a visible window that takes focus.

Please follow #52266 for updates, and add a comment there if you have more details, such as which plugin turns out to be running tasklist. If your problem is actually different, reply here and we can reopen this issue. Thanks again for the Process Explorer investigation!

opencodejr[bot] avatar Oct 29 '26 02:10 opencodejr[bot]

Still reproducing on v2.2.5 (as of 2026-11-05), Windows 11 build 22000 x64 — adding independent instrumentation data from a third-party manager (oc-manager #17):

  • WMI process-creation capture + 60 ms new-visible-window polling while a subagent task runs: pairs of visible ConsoleWindowClass windows (git.exe, python.exe) flash every ~5 s; parents resolve to the detached opencode serve --service.
  • Commands observed: snapshot git.EXE --git-dir <agentdatas>/snapshot/... (ls-files/diff), git status --porcelain, git branch --show-current, python <project>/.trellis/scripts/get_context.py, pwsh -NoProfile -Command "python ./.trellis/scripts/task.py list".
  • Focus steal measured: foreground sampling during the child's lifetime hits the child PID — each spawn steals foreground focus, it is not just visual flashing.
  • Not the manager: oc-manager sets windowsHide/CREATE_NO_WINDOW on every spawn it controls; none of those flash. Only opencode's own in-process spawns (snapshot git / shell-tool children) do.

Root cause and proposed fix: #60471 (windowless console for the detached service). Note that PR is currently scoped to builds ≥ 26100 — build 22000 (21H2) would remain affected; see my comment there about a < 26100 fallback.

Zh1uyan avatar Nov 05 '26 12:11 Zh1uyan

Closing as a duplicate of #52266: same console windows flashing from processes the background service starts on Windows. Please follow that issue for updates and add any extra details there.

neriousy avatar Nov 23 '26 11:11 neriousy