diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index 7bf72f7cdf..eef84208ff 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -305,6 +305,9 @@ pub fn restore_after_exit() -> Result<()> { if let Err(err) = terminal_stderr::finish() { first_error.get_or_insert(err); } + // Discard key events queued while shutdown was in progress so the parent shell does not + // receive CSI-u sequences that were encoded before keyboard reporting was reset. + flush_terminal_input_buffer(); match first_error { Some(err) => Err(err),