From d1b122f1c46b4ba51c16f83484d5c1779ed51d41 Mon Sep 17 00:00:00 2001 From: Olusammytee Date: Sun, 22 Feb 2026 13:42:40 -0500 Subject: [PATCH] fix(tui): shut down cleanly on terminal close and SIGINT --- packages/opencode/src/cli/cmd/tui/thread.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/thread.ts b/packages/opencode/src/cli/cmd/tui/thread.ts index 3b839f658..5f1830f13 100644 --- a/packages/opencode/src/cli/cmd/tui/thread.ts +++ b/packages/opencode/src/cli/cmd/tui/thread.ts @@ -128,11 +128,18 @@ export const TuiThreadCommand = cmd({ await client.call("reload", undefined) }) // kilocode_change start - graceful shutdown on external signals + let shuttingDown = false const shutdown = async () => { + if (shuttingDown) return + shuttingDown = true await client.call("shutdown", undefined).catch(() => {}) } - process.on("SIGHUP", shutdown) - process.on("SIGTERM", shutdown) + process.once("SIGHUP", shutdown) + process.once("SIGTERM", shutdown) + process.once("SIGINT", shutdown) + process.once("disconnect", shutdown) + process.stdin.once("end", shutdown) + process.stdin.once("close", shutdown) // kilocode_change end const prompt = await iife(async () => {