Skip to content

opencode (default mode) closes entire terminal window on Linux / i3wm #24077

Closed as not planned

Description

@brenoassp

Description

Summary

Running the opencode command in its default mode (which starts both the server and the TUI in the same process) causes the entire terminal window to close — not just the opencode process exiting, but the emulator window itself disappearing. Running opencode serve and opencode attach <url> as two separate processes works perfectly, which strongly suggests the bug is in the combined server+TUI startup path.

Environment

  • opencode version: 1.14.21
  • OS: Ubuntu (Linux)
  • Window manager: i3wm
  • Shell: zsh with oh-my-zsh
  • Terminal emulators tested (all reproduce the bug): xterm, Terminator, GNOME Terminal
  • Installation path: ~/.opencode/bin/opencode
  • Installation method: curl installer (curl -fsSL https://opencode.ai/install | bash) — inferred from binary location at ~/.opencode/bin/opencode

Steps to reproduce

  1. Open any terminal emulator (xterm, Terminator, GNOME Terminal — all reproduce).
  2. Run opencode (default mode, no subcommand).
  3. The TUI briefly appears, then the entire terminal window closes.

Expected behavior

The TUI should start and remain running until the user exits it. The terminal emulator window itself should never be closed by opencode.

Actual behavior

The terminal emulator window disappears entirely. The shell process and the emulator process both terminate. On the next session, running opencode reproduces the same crash.

What works (workaround)

Splitting the server and TUI into two separate processes works reliably:

# Terminal 1
opencode serve --port 4096
# prints: http://127.0.0.1:4096
 
# Terminal 2
opencode attach http://127.0.0.1:4096

In this mode, the TUI runs normally and the terminal does not close. This strongly suggests the bug is in the code path that launches server + TUI in a single process.

Diagnostic work already done

I ran an extensive elimination pass. The following were all tested and ruled out as causes:

Hypothesis Test Result
Out-of-memory (OOM killer) free -h, dmesg | grep -i oom 20 GB RAM free, no OOM records
Terminal emulator bug (VTE) Tested in xterm (non-VTE) Crash reproduces
GPU/renderer issue Multiple emulators tested Crash reproduces in all
Wrong binary architecture file $(which opencode) + uname -m Correct architecture
Corrupted SQLite database Moved ~/.local/share/opencode/opencode.db* aside No change
Corrupted config/cache Moved ~/.config/opencode/, ~/.local/share/opencode/, ~/.cache/opencode/ aside No change
Shell environment (zsh, oh-my-zsh, fnm, nvm) env -i HOME=$HOME PATH=/usr/local/bin:/usr/bin:/bin TERM=xterm /bin/bash --noprofile --norc -c '~/.opencode/bin/opencode' Crash reproduces
External plugins opencode --pure Crash reproduces
Server alone opencode serve Works fine
TUI alone attaching to external server opencode attach http://127.0.0.1:PORT Works fine

Strace findings

Running strace -f -o /tmp/opencode-strace.log opencode and grepping for fatal signals showed no SIGSEGV, SIGABRT, SIGKILL, SIGTERM, or SIGHUP delivered to the main opencode process. Child processes exit cleanly with exit_group(0) (one exited with exit_group(1), a grep subprocess whose command resolution I couldn't reconstruct from the log alone). The process disappears without any visible crash signature.

The strace does show child processes resetting job-control signal handlers (SIGTSTP, SIGTTIN, SIGTTOU set to SIG_DFL) and redirecting stdin via dup2(3, 0) — consistent with opencode spawning shell subprocesses for tool calls during startup.

My guess at the mechanism (not confirmed): the process that starts both server and TUI may be reparenting or detaching in a way that causes the controlling-TTY session leader to die, which then propagates up to the emulator. But this is speculation — someone familiar with the opentui integration would be far better placed to diagnose the real cause.

Additional notes

  • "Reinstalling" appeared to fix it temporarily in earlier sessions. After full diagnosis, this was likely coincidental timing rather than a real fix — the crash reproduces consistently from a clean state.
  • The attach-based workaround is stable and usable indefinitely, so this is not blocking me personally, but the default opencode command being unusable on a common Linux configuration (Ubuntu + i3wm) seems worth fixing.

Plugins

linear (disabled)

OpenCode version

1.14.21

Steps to reproduce

I installed in the morning, and at night or in the next day the problem occurs when I open the opencode. The last times I just reinstalled, but this time I was able to build this workaround.

Screenshot and/or share link

No response

Operating System

Ubuntu 24.04.4 LTS

Terminal

xterm, Terminator, GNOME Terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 24, 2026
  2. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  3. srivenkateswaran6002 commented on May 9, 2026

    @srivenkateswaran6002

    Hi! I noticed this issue open, and I would love to take a look and submit a PR if no one else is currently working on it. Mind if I give it a try?

  4. ernierasta commented on Jun 3, 2026

    @ernierasta

    The same behavior here (Artix Linux, foot terminal) after update to latest version, 1.14.x (do no remember exact version I had) was ok.

  5. marenamat commented on Jun 13, 2026

    @marenamat

    For me, now with 1.17.4 running in a podman container, even if i run opencode serve in one terminal and opencode attach from another terminal in the same container, opencode attach closes the foot terminal emulator.

  6. github-actions commented on Aug 21, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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