From 27675a5224c7ca4c8a9472fc2652d1442813b92f Mon Sep 17 00:00:00 2001 From: "H. Sinan Alioglu" Date: Wed, 8 Apr 2026 16:27:43 +0200 Subject: [PATCH] fix(cli): clean up stdin after sessions command readline interface closes The sessions command uses readline.createInterface() to prompt for session selection, but was not cleaning up stdin listeners after rl.close(). This left stdin in a corrupted state with lingering readline listeners, causing duplicate terminal I/O and making the CLI unusable when the TUI subsequently initialized. Add proper stdin cleanup after rl.close() to match the pattern used after onboarding, removing data/keypress listeners, resetting raw mode, and pausing stdin for a clean state handoff to the TUI. Closes #3718 --- src/cli.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cli.ts b/src/cli.ts index 5009f23b7..cda4df9dd 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -281,6 +281,14 @@ if (cliFlags.messages[0] === 'sessions') { }) rl.close() + // Clean up stdin state left by readline.createInterface(). + // Without this, downstream TUI initialization gets corrupted listeners and exhibits + // duplicate terminal I/O. Match the pattern used after onboarding cleanup. + process.stdin.removeAllListeners('data') + process.stdin.removeAllListeners('keypress') + if (process.stdin.setRawMode) process.stdin.setRawMode(false) + process.stdin.pause() + const choice = parseInt(answer, 10) if (isNaN(choice) || choice < 1 || choice > toShow.length) { process.stderr.write(chalk.dim('Cancelled.\n'))