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
[BUG] Opencode process survives terminal close — missing SIGHUP handler causes orphaned process accumulation #12767
When a terminal session (tab/window) is closed, the opencode process and its child LSP servers are not terminated. They remain running as orphaned processes (TTY = ??), accumulating over time and consuming significant memory.
This indicates opencode does not handle the SIGHUP signal, which the OS sends to foreground processes when their controlling terminal is closed.
Environment
OS: macOS 26.2 (Apple Silicon, arm64)
OpenCode: v1.1.53
Terminal: iTerm2 / Terminal.app (reproducible in both)
Steps to Reproduce
Open a terminal tab and run opencode in a project directory
Let it fully initialize (LSP servers spawn: pyright, bash-language-server, etc.)
Close the terminal tab/window (not Ctrl+C, just close the tab or quit the terminal app)
Open a new terminal and run: ps aux | grep opencode
Observed Behavior
The closed session's opencode process and all its child LSP servers remain alive as orphaned processes:
$ ps -o pid,ppid,tty,stat,etime,command | grep opencode | grep -v grep
87902 70932 ?? S 06-18:21:02 opencode # 6+ days, no TTY
36784 22543 ?? S 02-15:52:45 opencode # 2+ days, no TTY
Key observations:
TTY = ?? — controlling terminal is gone
STAT = S — sleeping, not zombie (still holding resources)
Parent PIDs point to orphaned zsh shells (re-parented to PID 1)
Each main process retains its child LSP servers (pyright, bash-language-server, yaml-language-server)
In my case, 10 main opencode processes + 8 child LSP servers = 18 total processes consuming ~3.2 GB RAM, most of which were from old, disconnected sessions.
Expected Behavior
When the controlling terminal is closed (SIGHUP sent):
opencode should catch SIGHUP and perform graceful shutdown
All child LSP server processes should be terminated
No orphaned processes should remain
Root Cause Analysis
opencode does not appear to register a SIGHUP handler. The standard process lifecycle for an interactive CLI tool should handle:
Signal
Expected Action
SIGHUP
Graceful shutdown (terminal closed)
SIGTERM
Graceful shutdown (kill request)
SIGINT
Immediate exit (Ctrl+C)
Without SIGHUP handling, every terminal close event leaks one opencode process + N LSP child processes.
Impact
Memory leak: ~150-800 MB per orphaned session, accumulating indefinitely
Process table pollution: 2-5 processes per orphaned session
Activity
github-actions commentedon Feb 9, 2026
This issue might be a duplicate of existing issues. Please check:
Related issues that could be caused or exacerbated by orphaned process accumulation:
Feel free to ignore if none of these address your specific case.
fix(opencode): exit process on SIGHUP (anomalyco#12767)
fix(opencode): add cwd-scoped process kill on exit for Linux/macOS
2026-02-26: Fix OpenCode Process Cleanup on Linux/macOS (#93)
whcxxb commentedon Feb 27, 2026
Additional macOS repro data (2026-02-27):
OpenCode version:
1.2.6kill -TERMdoes not fully stop orphaned OpenCode processes.Commands:
Observed after
SIGTERM:51015)51017 .../opencode-darwin-arm64/bin/opencode -m anthropic/claude-3-5-sonnet-20241022 --prompt hi51323 .../opencode-darwin-arm64/bin/opencodeThis suggests shutdown/signal cleanup is incomplete for child processes on macOS.
github-actions commentedon Apr 29, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.