Skip to content

Commit 2cc7d83

Browse files
committed
fix(opencode): prevent process.exit() from killing parent terminal on Windows
On Windows, process.exit() calls ExitProcess() which sends CTRL_CLOSE_EVENT to the console, killing the parent terminal (pwsh/cmd). This was exposed by the opentui dependency bump (0.1.99 -> 0.1.103) in v1.14.25 which changed how the TUI process terminates. Fix by avoiding process.exit() entirely on Windows: - In thread.ts: use process.exitCode = 0 and return instead - In index.ts: set exitCode and let the event loop drain; MCP subprocesses are already cleaned up by Effect finalizers Closes anomalyco#28673
1 parent 45badf7 commit 2cc7d83

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎packages/opencode/src/cli/cmd/tui.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ export const TuiThreadCommand = cmd({
283283
unguard?.()
284284
} catch {}
285285
}
286+
// On Windows, process.exit() can send CTRL_CLOSE_EVENT to the console
287+
// which kills the parent terminal process. Use exitCode instead.
288+
if (process.platform === "win32") {
289+
process.exitCode = 0
290+
return
291+
}
286292
process.exit(0)
287293
},
288294
})

‎packages/opencode/src/index.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ try {
134134
}
135135
process.exitCode = 1
136136
} finally {
137+
// On Windows, process.exit() can send CTRL_CLOSE_EVENT to the console
138+
// which kills the parent terminal process (pwsh/cmd). This is a known
139+
// regression since opentui 0.1.103.
140+
// Set exitCode and let the process drain naturally. MCP subprocesses
141+
// are cleaned up by Effect finalizers before this point.
142+
if (process.platform === "win32") {
143+
process.exitCode ||= 0
144+
return
145+
}
137146
// Some subprocesses don't react properly to SIGTERM and similar signals.
138147
// Most notably, some docker-container-based MCP servers don't handle such signals unless
139148
// run using `docker run --init`.

0 commit comments

Comments
 (0)