Repository navigation
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
I can't reproduce this locally. Are you using any plugins? |
|
here my current setup for bug replication if you dont have it natively on your setup:
I was not able to replicate it on Linux. |
|
Drafting it, still able to replicate the bug in some cases |
|
prompt was just "grep for hello world in this folder" |
|
Still reproducible on v2.0.11 (Windows 11, Desktop build). Worth flagging that there is a second, independent spawn path that this patch does not cover, so hiding The path I can reproduce deterministically is local stdio MCP launchers. With Two That makes this much easier to reproduce/observe than the transient case, and easy to distinguish from the background-service windows:
For what it's worth regarding "plugins": my setup has plugins enabled, but none of them spawn anything — the parents are unambiguously the serve process and Suggestion: mention in the description that the MCP spawn path (and descendant reaping — see #46253 and #47727) needs the same |
|
I have exactly the same thing: windows flashing very quickly several times per hour, sometimes even within 1 minute. According to logs, this happens in groups of 5 windows and it is indeed related to the MCP's you're connected with: as OpenCode says: OpenCode's background service spawns every local MCP server via cmd.exe /d /s /c ... (confirmed in the live process tree). Each spawn briefly allocates a visible console window. Your global config made codegraph, lystbot, lemma local servers, plus their npx/shim chains — so one location refresh ≈ 5+ cmd.exe flashes. It can be solved by removing the MCP's, but well, that's not the idea. It started for me when I updated to the v2 desktop version. Never had it before. |
|
Repro confirmed on Spawns in
Sanitized sample: timestamp=... message="spawning process" command="C:\Program Files\Git\cmd\git.EXE" args="["diff-files",...]" cwd="" role=server Process layout when it flashes: A/B on the same machine (spawns still logged in all three, only the visible window differs):
How I tested the contender-side change: shallow-cloned branch Suggestion: both clean paths already exist in the product, so consider exposing one as a supported no-flash option — either document |
|
Tldr quick fix: add the hidden window flag to all hooks on your harnesses. For PowerShell this is -WindowStyle hidden I ended up cancelling this and resolving it on my end. Here is the explanation for future readers as I see a lot of activity here still In opencode v2 every terminal call is made in a new child process terminal window Even if we merged this, it turns out it does not solve the problem entirely. I did make another pr to fix it completely but it turned out to be quite complex and felt like the wrong approach to the problem. The windows are now properly hidden for native opencode2 commands. However any additional tools that you have like hooks for pre-commit or shell guards will not be hidden. You have to modify every tool in your harness to spawn a hidden window. This biggest offender for me was the git rev-parse in a hook to check if we were in a git repo, and then enforce repo conventions if we are. This spawned a bunch of recursive windows. |
|
idk i can't reproduce it, i'll reopen for now and try to figure out exactly what's causing it |
|
@neriousy |

Issue for this PR
Closes #42440
Fixes #42440
Type of change
What does this PR do?
On Windows,
spawnServiceContenderstarts the background service as a detached process (DETACHED_PROCESS). Because the detached service has no console attached, Windows kernel allocates a new visible console window (ConsoleWindowClass/conhost.exe) whenever the service spawns a child process (such as tool calls or background updater checks).Depending on the user's settings, this will either translate into a black window appearing and disappearing after 40-150ms, or a new tab in the currently active terminal, taking focus and then disappearing, bringing the user to the last tab instead of the currently used tab
This PR adds
windowsHide: true(CREATE_NO_WINDOW) tospawnServiceContenderand internal desktop helper spawns while keepingdetached: true, so the service starts without creating console windows and still persists across spawner CLI process exits.This problem is at its worse when OpenCode 2 was started from Powershell 7.x (pwsh.exe)
This problem is new to Opencode 2, not present in Opencode 1
How did you verify your code works?
packages/client/test/service-survival.test.tsto assert that the spawned service contender survives parent process exit and receives environment variables (bun test test/service-survival.test.tspasses).bun typecheckacross all packages (0 errors).EnumWindowsscanning during CLI and tool executions — zero visible console windows appear.Screenshots / recordings
Difficult to screenshot as it only appears for 40 ms, but it takes focus. When it's a tab, it doesnt bring you back to your initial focused tab, but to the last one instead.

Checklist