Skip to content

[Bug] OpenCode steals foreground focus and disrupts user workflow when testing/running apps (Window Activation / Focus Stealing) #57578

Closed as not planned

Description

@koddek

Description

Description

When OpenCode executes tasks in the background that involve launching, testing, or inspecting an application, the target application window forcefully launches into the foreground active window. This steals OS-level keyboard/mouse focus from whichever window the user is currently working in (e.g., code editor, browser, notes).

Actual Behavior

  • Running an app or background test in OpenCode pops the application window directly on top of active work.
  • Focus is stolen from the active window, causing mid-sentence typing interruptions.
  • The user has to manually re-focus their active application every time OpenCode runs or tests a UI build.

Expected Behavior

OpenCode should execute background app checks, previews, and UI tests without taking active window focus away from the user's primary workspace.

Testing and UI inspection tasks should run:

  • Headless or Off-Screen: Virtual framebuffers or hidden rendering contexts so no physical window disrupts the desktop.
  • Without Focus Activation: If a GUI window must open, it should launch in a non-activating background layer (SHOWNOACTIVATE / non-activating window flags) so typing and work in the foreground are never interrupted.

Steps to Reproduce

  1. Open a workspace in OpenCode.
  2. Trigger an action or agent task that executes or tests a target application.
  3. Switch to another app and begin typing or editing.
  4. Observe: The application spawned by OpenCode pops into the active foreground, stealing focus and interrupting work.

Here are the additional details to help debug this issue:

  1. OpenCode version: OpenCode Desktop Version 2.1.2 (running on macOS, Apple Silicon / M1).
  2. Interface: OpenCode Desktop App.
  3. What took focus & command ran:
    • The app taking focus is the desktop application under development in the workspace (for example, myapp.app).
    • The focus-stealing occurs when OpenCode runs/launches the compiled desktop app binary during background test/build cycles (e.g., executing the app directly via shell commands or open myapp.app without the -g background flag).
    • It is not the OpenCode built-in browser taking focus—it is the local macOS target application being tested.
  4. Summary of behavior:
    I was actively dictating text and working in another application (such as Notepad/TextEdit) while OpenCode was running background tasks on my project in the OpenCode Desktop app. While OpenCode was executing/testing the local desktop app build (myapp.app), the launched app window forcefully opened in the OS foreground. This stole system-level keyboard focus mid-dictation/mid-typing, causing text input to drop or lose target window state, and interrupting active media playback (like YouTube) by popping over the workspace.

Key issue:
When OpenCode spawns or runs target macOS application binaries to verify or test UI work, it launches them as activated foreground processes rather than executing them quietly in the background (e.g., using open -g on macOS, non-activating window flags, or headless preview wrappers).

Activity

  1. opencode-agent commented on Oct 21, 2026

    @opencode-agent
    Contributor

    Thanks for the report! To work out what's going on, we need a few more details:

    1. OpenCode version: the output of opencode --version.
    2. Interface: are you using the TUI (and in which terminal), the desktop app, or the web app?
    3. What took focus: what was the exact command or tool call the agent ran (for example npm run dev, open MyApp.app, an Xcode/Electron build, the built-in browser), and which app's window came to the front?
    4. In a couple of sentences, in your own words: what you did, what you expected, and what you saw.

    This matters because when the agent runs a command, whether the launched app takes focus is mostly up to that app and macOS. For example, open MyApp.app brings the app to the front, but open -g MyApp.app launches it in the background. So we need to know what is being launched to tell whether OpenCode is causing this.

    You can reply here with the details or edit the issue. If you edit it, please also leave a comment saying you've updated it so we know you're done.

    I didn't find an exact duplicate. These are related, ordered by likelihood:

  2. koddek commented on Oct 21, 2026

    @koddek
    Author

    i updated the issue with the additional information

  3. opencode-agent commented on Oct 24, 2026

    @opencode-agent
    Contributor

    We're closing this for now because we haven't heard back. To tell whether OpenCode is causing the focus stealing, we need your OpenCode version, which interface you're using (TUI/desktop/web), and the exact command or app that came to the front. On macOS, the launched app usually decides whether it takes focus.

    If it still happens, please reply here with those details or open a new issue, and we'll take another look. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions