Ghostty: raw `...u` escape-sequence fragments inserted into shell after abnormal SSH disconnect during Codex session
What version of Codex CLI is running?
codex-cli 0.118.0
What subscription do you have?
Plus
Which model were you using?
_No response_
What platform is your computer?
Darwin 25.2.0 arm64 arm
What terminal emulator and version are you using (if applicable)?
ghostty
What issue are you seeing?
After an abnormal SSH disconnect during an active Codex session in Ghostty, subsequent keypresses are inserted into the shell as raw ...u escape-sequence fragments instead of normal text input.
Example fragments I saw include:
9;5u1:3u4;1:3u
This seems specific to Codex in my setup. I have not seen the same behavior with other similar terminal coding sessions in the same Ghostty environment.
The terminal returns to normal immediately if I copy paste and run :
printf '\033[<u\033[>4;0m' && stty sane && reset
What steps can reproduce the bug?
- Open Ghostty on macOS.
- SSH into a remote machine.
- Start an active Codex session on the remote host.
- Let the SSH connection break abnormally, for example due to network interruption / timeout / broken pipe while Codex is still running.
- Return to the local shell in the same Ghostty tab/window.
- Start typing normally.
Observed result:
keypresses are inserted as raw ...u fragments instead of normal text.
Recovery:
copy paste and run
printf '\033[<u\033[>4;0m' && stty sane && reset
What is the expected behavior?
Codex should restore terminal keyboard/input state on abnormal exit or disconnect so that the parent shell remains in a normal text-input mode.
After the SSH/Codex session breaks, typing in the local shell should continue to work normally without requiring a manual terminal reset.
Additional information
- Terminal emulator: Ghostty
- Shell: zsh
- Connection type: SSH to remote host
- Remote host : Linux 6.14.0-34-generic x86_64 x86_64
- The disconnect was not a clean exit from Codex; it happened after connection loss / timeout
- I have only observed this with Codex, not with other similar tools in the same Ghostty setup
- The fact that
printf '\033[<u\033[>4;0m' && stty sane && resetfixes it suggests terminal keyboard/input mode cleanup is being skipped on abnormal disconnect - This may be related to enhanced keyboard reporting / CSI-u style input state being left enabled
2 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
I investigated this against current
main.PR #19625 added stronger keyboard-reporting cleanup for normal TUI exit, panic handling, and other shutdown paths. However, it cannot fully address this issue when the SSH transport disappears abruptly.
On a TCP reset, timeout, or broken pipe, the remote Codex process can no longer send
ESC[<uor other cleanup sequences to the local terminal. Therefore, adding more exit handlers cannot make this failure mode reliable.The existing environment variable provides a useful confirmation:
With keyboard enhancement disabled, an abnormal SSH disconnect cannot leave the local terminal in CSI-u mode.
A possible upstream policy would be:
SSH_TTY/SSH_CONNECTION);CODEX_TUI_DISABLE_KEYBOARD_ENHANCEMENT=0;The tradeoff is that modified-key features such as Shift+Enter may be less capable over SSH, so I would like maintainer feedback on whether this policy matches the intended UX.
I am happy to prepare the implementation and tests if the team agrees with this approach and invites a pull request.