Bug: Desktop embedded terminal freezes when shell exits via Ctrl+D or exit command #3770

Closed
opened 2026-02-16 17:41:25 -05:00 by yindo · 3 comments
Owner

Originally created by @anntnzrb on GitHub (Dec 22, 2025).

Originally assigned to: @adamdotdevin on GitHub.

Description

The embedded terminal in the bottom panel of OpenCode Desktop freezes/hangs when the shell session terminates, either by pressing Ctrl+D or typing exit.

I don't use the Desktop or Web version regularly, so I haven't investigated this deeply. I encountered this bug on my first time trying the Desktop app.

Additional observation: In opencode web, the terminal panel failed to open entirely (this might be related to issue #5844).

OpenCode version

v1.0.190

Steps to reproduce

  1. Open OpenCode Desktop (Tauri app) or run opencode web
  2. Open a project
  3. Open the terminal panel (bottom sidebar)
  4. Either:
    • Press Ctrl+D to send EOF, OR
    • Type exit and press Enter
  5. The application freezes/hangs

Expected behavior

The terminal should gracefully handle shell exit by either:

  • Closing the terminal panel
  • Showing a "Terminal exited" message with option to restart
  • Automatically spawning a new shell session

Actual behavior

  • Tauri Desktop: Application freezes after shell exits
  • opencode web: Terminal panel doesn't open at all

Operating System

macOS (Apple Silicon M4 - MacBook Air)

Terminal

Default shell


Preliminary investigation (with LLM assistance)

A superficial analysis of the codebase suggests the issue may be related to a disconnect between backend PTY cleanup and frontend handling:

Backend (packages/opencode/src/pty/index.ts, lines 158-163):

  • When shell exits, ptyProcess.onExit() publishes pty.exited event and deletes session from state
  • WebSocket connections to subscribers may not be properly closed

Frontend (packages/desktop/src/components/terminal.tsx, lines 124-126):

  • WebSocket close handler only logs the disconnection
  • No recovery or cleanup is triggered

Global Sync (packages/desktop/src/context/global-sync.tsx, lines 183-294):

  • Event handler does not appear to listen for pty.exited or pty.deleted events

Note: This investigation was done with LLM assistance and has not been thoroughly verified.

Originally created by @anntnzrb on GitHub (Dec 22, 2025). Originally assigned to: @adamdotdevin on GitHub. ### Description The embedded terminal in the bottom panel of OpenCode Desktop freezes/hangs when the shell session terminates, either by pressing `Ctrl+D` or typing `exit`. I don't use the Desktop or Web version regularly, so I haven't investigated this deeply. I encountered this bug on my first time trying the Desktop app. **Additional observation:** In `opencode web`, the terminal panel failed to open entirely (this might be related to issue #5844). ### OpenCode version v1.0.190 ### Steps to reproduce 1. Open OpenCode Desktop (Tauri app) or run `opencode web` 2. Open a project 3. Open the terminal panel (bottom sidebar) 4. Either: - Press `Ctrl+D` to send EOF, OR - Type `exit` and press Enter 5. The application freezes/hangs ### Expected behavior The terminal should gracefully handle shell exit by either: - Closing the terminal panel - Showing a "Terminal exited" message with option to restart - Automatically spawning a new shell session ### Actual behavior - **Tauri Desktop:** Application freezes after shell exits - **opencode web:** Terminal panel doesn't open at all ### Operating System macOS (Apple Silicon M4 - MacBook Air) ### Terminal Default shell --- <details> <summary>Preliminary investigation (with LLM assistance)</summary> A superficial analysis of the codebase suggests the issue may be related to a disconnect between backend PTY cleanup and frontend handling: **Backend** (`packages/opencode/src/pty/index.ts`, lines 158-163): - When shell exits, `ptyProcess.onExit()` publishes `pty.exited` event and deletes session from state - WebSocket connections to subscribers may not be properly closed **Frontend** (`packages/desktop/src/components/terminal.tsx`, lines 124-126): - WebSocket `close` handler only logs the disconnection - No recovery or cleanup is triggered **Global Sync** (`packages/desktop/src/context/global-sync.tsx`, lines 183-294): - Event handler does not appear to listen for `pty.exited` or `pty.deleted` events **Note:** This investigation was done with LLM assistance and has not been thoroughly verified. </details>
yindo added the web label 2026-02-16 17:41:25 -05:00
yindo closed this issue 2026-02-16 17:41:25 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 22, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #5896: Bun crash when /exiting - Similar exit-related crash issue
  • #5936: Random Artifacts In Terminal After Running - Terminal issues after exiting
  • #3213: Bug: opencode run and TUI exits hang on v0.15+ - Regression related to process not exiting properly

The root cause may be related to PTY cleanup and websocket connection handling when the shell exits, as you've already noted in your investigation. Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 22, 2025): This issue might be a duplicate of existing issues. Please check: - #5896: Bun crash when `/exit`ing - Similar exit-related crash issue - #5936: Random Artifacts In Terminal After Running - Terminal issues after exiting - #3213: Bug: `opencode run` and TUI exits hang on v0.15+ - Regression related to process not exiting properly The root cause may be related to PTY cleanup and websocket connection handling when the shell exits, as you've already noted in your investigation. Feel free to ignore if none of these address your specific case.
Author
Owner

@anntnzrb commented on GitHub (Dec 22, 2025):

Thanks for the suggestions! After reviewing, I don't believe these are duplicates:

  • #5896 (Bun crash when /exiting): That issue is about a Bun crash when using the /exit command in the CLI/TUI. This issue is about the embedded terminal (Ghostty) in the Desktop bottom panel freezing when the shell exits via Ctrl+D or the shell's exit command.

  • #5936 (Random Artifacts In Terminal After Running): That issue is about visual artifacts in the terminal on Windows after closing OpenCode TUI. This issue is specifically about the Desktop app freezing, not visual glitches.

  • #3213 (opencode run and TUI exits hang): That issue is about the CLI mode (opencode run) and TUI hanging. This issue is specific to the Desktop (Tauri) and opencode web embedded terminal panel.

The key distinction is that this bug occurs in the Desktop/Web embedded terminal component, not in the CLI/TUI.

@anntnzrb commented on GitHub (Dec 22, 2025): Thanks for the suggestions! After reviewing, I don't believe these are duplicates: - **#5896 (Bun crash when `/exit`ing):** That issue is about a Bun crash when using the `/exit` command in the CLI/TUI. This issue is about the **embedded terminal** (Ghostty) in the Desktop bottom panel freezing when the **shell** exits via `Ctrl+D` or the shell's `exit` command. - **#5936 (Random Artifacts In Terminal After Running):** That issue is about visual artifacts in the terminal on Windows after closing OpenCode TUI. This issue is specifically about the Desktop app freezing, not visual glitches. - **#3213 (`opencode run` and TUI exits hang):** That issue is about the CLI mode (`opencode run`) and TUI hanging. This issue is specific to the **Desktop (Tauri) and `opencode web`** embedded terminal panel. The key distinction is that this bug occurs in the **Desktop/Web embedded terminal component**, not in the CLI/TUI.
Author
Owner

@AlexandrosLiaskos commented on GitHub (Dec 23, 2025):

For me the terminal never opens. In wsl the deb worked, but in windows app, both the stable and beta didn't even open a terminal

Image
@AlexandrosLiaskos commented on GitHub (Dec 23, 2025): For me the terminal never opens. In wsl the deb worked, but in windows app, both the stable and beta didn't even open a terminal <img width="1335" height="825" alt="Image" src="https://github.com/user-attachments/assets/aa720979-0157-4a05-95d0-6384c45a5cdd" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3770