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
Provide a way to stop all running scripts when OpenCode is interrupted #3057
Summary
Currently, when OpenCode determines it should run a script and begins execution, pressing Ctrl-C only interrupts OpenCode itself. Any script or process started by OpenCode continues running in the background, requiring manual intervention to locate and terminate it.
After reviewing related issues, it appears that pressing the Escape key might stop the script, but this behavior wasn't clear in the moment. When I pressed Ctrl-C, I was expecting all processes—including the child script—to stop, especially since Ctrl-C is a common panic escape. Instead, only OpenCode was interrupted and the script continued running in the background.
Steps to reproduce
Use OpenCode to initiate a fix that results in running a script.
Interrupt OpenCode with Ctrl-C while the script is running.
Observe that the script continues running independently (unless Escape is used, which may stop it, but this isn't obvious).
Expected behavior
Interrupting OpenCode with Ctrl-C should terminate any scripts or processes it has spawned, or there should be an easy way for users to stop all related processes. This should be the default behavior for Ctrl-C since it's the familiar way to kill a running process during a panic.
Actual behavior
Only OpenCode itself is stopped; scripts or processes it started continue to run in the background.
Suggested improvement
Make Ctrl-C terminate both OpenCode and any child processes/scripts it started by default. If Escape is an alternative, clarify its behavior in the documentation or UI, but Ctrl-C should be the reliable panic escape that kills everything.
This issue might be a duplicate of existing issues. Please check:
Provide means to disable Ctrl-C #2999: Similar request for Ctrl-C handling - discusses problems with Ctrl-C behavior and the need to disable or modify its functionality
bug: /compact is not interruptable #2928: Related to interruption issues - specifically mentions that /compact operations cannot be interrupted, indicating similar process control problems
opencode does not exit on ^D #3025: Related exit/termination behavior - addresses the need for proper process termination with ^D, showing similar concerns about process lifecycle management
Feel free to ignore if none of these address your specific case.
Apply the same cleanup pattern from shell/shell.ts to lsp/client.ts:
asyncshutdown(){connection.end()connection.dispose()constproc=input.server.processconstpid=proc.pidtry{process.kill(-pid,"SIGTERM")awaitBun.sleep(200)// Check if still running, then SIGKILLprocess.kill(-pid,"SIGKILL")}catch{proc.kill("SIGKILL")}}
These ensure child processes are properly killed when LSP/PTY sessions are disposed. The bash tool abort race condition (where void kill() is fire-and-forget) is a separate issue that will need a follow-up PR.
I am having to manually kill processes that opencode 'forgets' running forever, and they remain consuming my cpu for no reason processing something that I don't know what might be, even if I have used+closed opencode hours ago. I suspect it's those times that opencode runs a task in a sub agent (not sure what its called) and it hangs, and then I close opencode and that's probably what leaves those processes there without being killed.
Today I used tools @general @explore and chrome web devtools mcp, not sure if any are related. Also not sure if it's the main opencode process or sub processes that remain running in background. Probably sub processes that opencode spawns. I always close opencode by closing the terminal or ctrl c then close terminal. On mint ubuntu 24
(on screenshot below I had 3 opencode processes (killed 1) running, but I didn't have any opencode terminal open, closed hours ago)
Activity
github-actions commentedon Oct 9, 2025
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
rekram1-node commentedon Oct 9, 2025
ah nice catch we should definitely fix thx
anntnzrb commentedon Dec 21, 2025
LSP processes have the same problem
The shell cleanup in
shell/shell.tsalready has proper SIGKILL escalation:However, LSP processes in
lsp/client.tslack this:Missing from LSP cleanup:
process.kill()notprocess.kill(-pid), so child processes (e.g.,tsserverspawned bytypescript-language-server) surviveReproduction
When using git worktrees with parallel operations, each worktree spawns its own LSP set. After the session ends, orphaned
tsserverprocesses remain:Suggested fix
Apply the same cleanup pattern from
shell/shell.tstolsp/client.ts:Related: #5525 (same root cause, Windows-specific report)
anntnzrb commentedon Dec 21, 2025
Opened PRs to address part of this issue:
Shell.killTree()+detached: true)killPtyTree()helper)These ensure child processes are properly killed when LSP/PTY sessions are disposed. The bash tool abort race condition (where
void kill()is fire-and-forget) is a separate issue that will need a follow-up PR.gkp1 commentedon Jan 31, 2026
I am having to manually kill processes that opencode 'forgets' running forever, and they remain consuming my cpu for no reason processing something that I don't know what might be, even if I have used+closed opencode hours ago. I suspect it's those times that opencode runs a task in a sub agent (not sure what its called) and it hangs, and then I close opencode and that's probably what leaves those processes there without being killed.
Today I used tools @general @explore and chrome web devtools mcp, not sure if any are related. Also not sure if it's the main opencode process or sub processes that remain running in background. Probably sub processes that opencode spawns. I always close opencode by closing the terminal or ctrl c then close terminal. On mint ubuntu 24
(on screenshot below I had 3 opencode processes (killed 1) running, but I didn't have any opencode terminal open, closed hours ago)
github-actions commentedon Apr 1, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.