You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Opencode doesn't stop the agents when I close the app! #55214
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
Launch an agent
The agent starts doing stupid stuff like messing up your project
Close opencode to do it manually
Reopen opencode and see that the agent was working in background and your project is an unrecoverable mess
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.
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.
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.
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).
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.
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.
Activity
opencode-agent commentedon Oct 13, 2026
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:
opencode service stopto shut down the background service and anything it's running.opencode --standalone. This runs a private server that's tied to that terminal session, so it should stop when you close it.Related issues:
SarangRao20 commentedon Oct 13, 2026
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.
MinnieTheMoocher commentedon Oct 20, 2026
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.
SarangRao20 commentedon Oct 22, 2026
Can i fix, this and do a PR ?
feat(tui): prompt to stop active sessions on exit
feat(tui): prompt to stop active sessions on exit
feat(tui): prompt to stop active sessions on exit
feat(tui): prompt to stop active sessions on exit
feat(tui): prompt to stop active sessions on exit
prhasn commentedon Oct 27, 2026
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).
kcyarn commentedon Oct 29, 2026
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.
prhasn commentedon Oct 29, 2026
It is kind of insane to be honest. That someone took that decision to be default behavior with no setting to turn it off.