opencode icon indicating copy to clipboard operation
opencode copied to clipboard

OpenCode Desktop starts multiple windows when launched once from a script

Open andrey-golovko opened this issue 1 week ago • 2 comments

Summary

OpenCode Desktop can start multiple Desktop windows and multiple backend instances when it is launched once from a script.

This happens without:

  • double-clicking
  • running the script multiple times
  • hotkeys
  • parallel execution

The script starts OpenCode.exe exactly once, yet multiple Desktop windows appear.


Environment

  • OS: Windows 10 / Windows 11
  • OpenCode Desktop: latest Windows build
  • Installation paths:
    %LOCALAPPDATA%\OpenCode\OpenCode.exe
    %LOCALAPPDATA%\OpenCode\opencode-cli.exe
    
  • Launch method:
    • PowerShell script
  • Script execution count:
    • once

Steps to Reproduce (single run)

  1. Create a PowerShell script with a single launch command:

    & "$env:LOCALAPPDATA\OpenCode\OpenCode.exe" "C:\project"
    
  2. Run the script once from PowerShell.

  3. Observe that multiple OpenCode Desktop windows may open.


Observed Behavior

  • More than one Desktop window is shown.

  • Process list contains multiple instances:

    OpenCode.exe
    OpenCode.exe
    
  • Multiple backend instances are spawned:

    opencode-cli.exe serve --port=64840
    opencode-cli.exe serve --port=64854
    opencode-cli.exe serve --port=64870
    
  • The script itself launches OpenCode.exe only once.


Expected Behavior

  • A single script execution should result in:
    • exactly one Desktop window
    • exactly one backend instance

Analysis / Findings

Investigation shows that OpenCode Desktop appears to re-launch or self-spawn during startup.

Indicators:

  • Multiple OpenCode.exe processes exist even though the parent script started it once.
  • At least one OpenCode.exe instance has another OpenCode.exe as its parent.
  • Desktop seems to perform an internal restart / re-exec (possibly for setup, update, or backend initialization), but the original instance does not exit.

This results in multiple UI windows instead of a clean handoff.


Why This Is a Bug

Even if Desktop needs to restart itself internally:

  • the original instance should exit, or
  • the new instance should take over,

but multiple visible Desktop windows must not remain active.

Single-instance behavior should be enforced inside the application, not in user scripts.


Workaround

Users must implement a global OS-level mutex in their launcher scripts, for example:

$mutex = New-Object System.Threading.Mutex($false, "Global\OpenCodeDesktopSingleton")
if (-not $mutex.WaitOne(0)) { exit }

This workaround prevents the issue, confirming that the problem is related to missing single-instance protection in Desktop.


Proposed Fix

Implement a single-instance guard inside OpenCode Desktop:

  • Use a global named mutex on Windows (e.g. Global\OpenCodeDesktop)
  • On detecting an existing instance:
    • bring the existing window to foreground
    • exit immediately

This is standard behavior for IDEs and desktop developer tools.


Impact

  • Confusing user experience (multiple windows from one launch)
  • Difficult automation and scripting
  • Backend and MCP duplication
  • Unnecessary resource usage

Additional Notes

  • The issue reproduces without any bootstrap backend.
  • The issue reproduces without proxy configuration.
  • The issue is not caused by user double-clicking or concurrent launches.

andrey-golovko avatar Jan 06 '26 13:01 andrey-golovko