Repository navigation
Description
Description
The TUI hangs indefinitely after the server reaches init. The server process completes initialization successfully, but the TUI client never renders the interactive UI. This occurs in both TUI mode and attach mode.
Environment
- OS: Windows 10.0.26200 x64
- opencode versions tested: 1.17.19, 1.18.1 (both exhibit the same behavior)
- Terminals tested: Git Bash (MSYS2), Windows Terminal
- Installation:
bunglobal install
Reproduction
The issue reproduces with zero config, zero plugins, no LSPs, and a fresh database:
# All of these hang at "init":
opencode # TUI mode
opencode attach http://127.0.0.1:4096 # attach to running server
opencode --pure # no plugins
opencode --mini # minimal TUI# These all work perfectly:
opencode run "hello" # headless — creates session, completes
opencode serve # headless server — binds port, responds HTTP
opencode web # web UI — opens browser, fully functionalEvidence
Log output (hangs at init)
timestamp=2026-07-15T06:44:03.179Z level=INFO run=f235a4ff message="all LSPs are disabled"
timestamp=2026-07-15T06:44:03.179Z level=INFO run=f235a4ff message="all formatters are disabled"
timestamp=2026-07-15T06:44:03.179Z level=INFO run=f235a4ff message=init
# ← nothing after this, TUI never renders
Terminal escape codes emitted before hang
The TUI sends terminal capability queries and blocks:
[?2031h]10;?]11;?[>0q[?25l[s[6nP+q4d73\
[?1016$p[?2027$p[?2031$p[?1004$p[?2004$p[?2026$p[?u
]99;i=opentui-notifications:p=?;\]1337;Capabilities\
[H]66;w=1; \[6nH]66;s=2; \[6n[u[s
[?1049h[>4;1m[?2027h[?2004h[?1000h[?1002h[?1003h[?1006h[14t
These are DECRPM (mode query) requests. The TUI appears to block waiting for terminal responses that never arrive.
What works vs what hangs
| Mode | Result |
|---|---|
opencode run "hello" |
Creates session, runs prompt, completes |
opencode serve |
Binds port, serves HTTP 200 |
opencode web |
Opens browser, fully functional |
opencode (TUI) |
Hangs at init — never renders |
opencode attach |
Hangs at init — same escape codes, same hang |
Clean environment test
I verified the issue persists with:
- Fresh config directory (
~/.config/opencode/empty) - Fresh database (moved
opencode.dbto_old_db) - Fresh state (
~/.local/state/opencode/removed) --pureflag (no plugins)- Both versions 1.17.19 and 1.18.1
Diagnostics
$ opencode debug info
opencode version: 1.18.1
os: Windows_NT 10.0.26200 x64
terminal: xterm-256color
$ opencode debug startup
863.1158
Hypothesis
The opentui library sends DECRPM terminal capability queries ([?NNNN$p) during initialization and blocks waiting for responses. On my Windows system, the terminal (or the terminal emulation layer in the opentui runtime) never responds to these queries, causing a deadlock.
This may be related to:
- Bun runtime on Windows not properly emulating terminal responses
- A missing timeout on the opentui terminal query mechanism
- A regression in how the TUI client communicates with the embedded server after
init
Workaround
opencode web provides full functionality via browser.
Activity
Zireael commentedon Jul 15, 2026
Update:
--portflag workaroundSpecifying an explicit
--portresolves the hang:This changes the diagnosis. The TUI is not deadlocking on terminal capability queries. Instead, the issue is likely a race condition in the default port binding/communication path between the TUI client and the embedded server.
How the default flow likely works (and breaks)
Without
--port:initbut TUI never receives the port/connection infoWith
--port:Reproduction with explicit port
This suggests the bug is in the embedded server startup path when no port is specified — specifically in how the server communicates its chosen port back to the TUI client process.
[-]TUI hangs at init on Windows — terminal capability query deadlock[/-][+]TUI hangs on default port — works with --port flag[/+]Zireael commentedon Jul 15, 2026
Root Cause Analysis — Source Code Evidence
The bug: in-process Worker RPC path has no timeout, blocks on service graph initialization
When
opencodeis run without--port, the TUI uses an in-process Worker RPC mechanism to communicate with the server. This path has no timeout, so if the Worker blocks during service initialization, the TUI hangs forever.Code flow (default path, no --port)
1. Transport decision —
packages/opencode/src/cli/cmd/tui.ts:234Without
--port,external = false→ uses in-process Worker RPC.2. Worker fetch proxy —
packages/opencode/src/cli/cmd/tui.ts:24-393. Worker RPC handler —
packages/opencode/src/cli/tui/worker.ts:31-494. Server.Default() is lazy —
packages/opencode/src/server/server.ts:56-655. HttpApiApp.webHandler() builds the entire service graph —
packages/opencode/src/server/routes/instance/httpapi/server.ts:1-60+This initializes ~70 Effect services: Database, LSP, MCP, Provider, Session, ModelsDev (network call), Npm, etc.
6. RPC has NO timeout —
packages/opencode/src/util/rpc.ts:45-507. Worker swallows errors —
packages/opencode/src/cli/tui/worker.ts:16-21Why --port fixes it
When
--portis specified (tui.ts:238-244):The Worker starts a real HTTP server via
Server.listen(), and the TUI connects via real HTTP fetch (with built-in timeouts and retry logic) instead of the timeout-free RPC proxy.Likely trigger: ModelsDev network call
The
ModelsDevservice (imported inserver.ts:58) fetches model definitions frommodels.dev. We observed this in logs:If this network call hangs instead of failing quickly (e.g., DNS timeout on Windows can be 21+ seconds, or a firewall silently dropping packets), it blocks the entire service graph initialization → Worker
fetch()blocks → RPC blocks forever → TUI hangs.Key files
packages/opencode/src/cli/cmd/tui.ts:234hasArg("--port"))packages/opencode/src/cli/cmd/tui.ts:24-39createWorkerFetch— no timeoutpackages/opencode/src/cli/tui/worker.ts:31-49fetch()handler →Server.Default()packages/opencode/src/server/server.ts:56-65Defaultlazy init →HttpApiApp.webHandler()packages/opencode/src/server/routes/instance/httpapi/server.ts:1-60packages/opencode/src/util/rpc.ts:45-50packages/opencode/src/cli/tui/worker.ts:16-21Suggested fixes
Server.Default()lazy initialization — if the service graph doesn't initialize within N seconds, fail gracefullycall()— reject the promise after a timeout instead of hanging foreverunhandledRejectionso blocked initialization surfacesModelsDevnetwork call — ensure DNS/connect failures don't hang the entire init chaingithub-actions commentedon Sep 15, 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.