Skip to content

Opencode doesn't stop the agents when I close the app! #55214

Open

Description

@italian-brainrot

Description

The agent was doing stupid things so I closed the app and reopened it a few hours later only to discover the agent was still running all of that time doing all kings of things on my computer

Plugins

None

OpenCode version

2.0.28

Steps to reproduce

  1. Launch an agent
  2. The agent starts doing stupid stuff like messing up your project
  3. Close opencode to do it manually
  4. Reopen opencode and see that the agent was working in background and your project is an unrecoverable mess

Screenshot and/or share link

No response

Operating System

Bazzite

Terminal

ptyxis 50.1

Activity

  1. opencode-agent commented on Oct 13, 2026

    @opencode-agent
    Contributor

    Thanks for the report, and sorry the agent kept changing your project after you closed OpenCode.

    This isn't a crash; it comes from how OpenCode v2 is built. The TUI is only a window onto a shared background service, and that service is what runs sessions and tools. Closing the TUI disconnects the window, but a turn that's already running keeps going in the service. I'm marking this as a feature request: closing the app (or the last client disconnecting) should stop or pause running agents, or OpenCode should at least warn you on exit that agents are still running. Maintainers will consider it.

    Things you can do now:

    • Interrupt the agent (Esc) before you quit.
    • Run opencode service stop to shut down the background service and anything it's running.
    • Start OpenCode with opencode --standalone. This runs a private server that's tied to that terminal session, so it should stop when you close it.

    Related issues:

  2. SarangRao20 commented on Oct 13, 2026

    @SarangRao20

    I took a look at the code to see why this happens. Right now the TUI just detaches on exit while the background
    service keeps the session running (until the 60-min idle timeout in LocationActivity kicks in).

    I'd like to work on a fix for this, but since CONTRIBUTING.md mentions core lifecycle/UI changes need design review
    first, wanted to run my approach by maintainers:

    My thought is to handle this at the TUI level:

    • If a user runs /exit or hits Ctrl+C/Ctrl+D while an agent is actively running a turn, show a quick confirmation
    dialog asking whether to interrupt the agent and exit, let it keep running in the background, or cancel.
    • For cases where the terminal window itself is closed (SIGHUP), have the TUI send an interrupt to the active
    session before exiting so the agent doesn't keep running blind in the background.
    • We could also add a config option (session.stop_on_exit) in case someone wants this to always auto-stop without
    asking.

    Does this direction make sense, or would you prefer this to be handled server-side when the last client disconnects
    (similar to #53068)? Happy to implement whichever matches the intended v2 design.

  3. MinnieTheMoocher commented on Oct 20, 2026

    @MinnieTheMoocher

    I am also hit by this problem and I HATE THIS BUG.
    Canceling an AI agent gone wild no longer is effective, and it messes up whole folders or even computers.
    This bug needs HIGHEST priority to be fixed.

  4. SarangRao20 commented on Oct 22, 2026

    @SarangRao20

    Can i fix, this and do a PR ?

  5. added 5 commits that reference this issue on Oct 22, 2026
    3f42f4d
    18ed9c9
    4110d4a
    5692d16
    e6544f1
  6. prhasn commented on Oct 27, 2026

    @prhasn

    This is a very serious issue. At the very least there should be a stop button similar to the one in the hosted web app (especially considering there is a bug already for ESC button being unresponsive for stopping the generation).

  7. kcyarn commented on Oct 29, 2026

    @kcyarn

    Most of my opencode usage is through scripted events. For me, this is a catastrophic breaking change. If I want a session to be resumed, I will give it the session id and direct it to resume myself. This is forced resumption of a killed session. Whether it was killed by my mcp's llm judge or me doesn't matter. The fact that it resumed without explicit consent does.

  8. prhasn commented on Oct 29, 2026

    @prhasn

    Most of my opencode usage is through scripted events. For me, this is a catastrophic breaking change. If I want a session to be resumed, I will give it the session id and direct it to resume myself. This is forced resumption of a killed session. Whether it was killed by my mcp's llm judge or me doesn't matter. The fact that it resumed without explicit consent does.

    It is kind of insane to be honest. That someone took that decision to be default behavior with no setting to turn it off.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions