Windows native TUI intermittently inserts escape-sequence tails ([I/[C/[D/[A]) and becomes unusable
What version of Codex CLI is running?
codex-cli 0.139.0
Installed via npm on native Windows.
I have not upgraded to 0.141.0 because the 0.141.0 release notes and the related open issues do not appear to mention a fix for this Windows TUI input / VT sequence leakage problem. I can test a newer version if maintainers think a relevant fix has landed.
What platform is your computer?
Native Windows 11, x64.
codex doctor --json reports:
{
"codexVersion": "0.139.0",
"overallStatus": "warning",
"system.environment": {
"os": "Windows 10.0.26200 (Windows 11 CoreCountrySpecific) [64-bit]",
"os type": "Windows",
"os version": "10.0.26200",
"os language": "zh-CN"
},
"terminal.env": {
"terminal": "Windows Terminal",
"WT_SESSION": "present",
"console input code page": "65001",
"console output code page": "65001"
},
"installation": {
"install context": "npm on windows-x86_64",
"managed by npm": "true"
}
}
What terminal emulator and shell are you using?
- Windows Terminal
- PowerShell 7.6.2 (
pwsh) - Native Windows
codexprocess, not WSL
What issue are you seeing?
After using an interactive Codex CLI session for a while, the TUI input composer can enter a broken state where terminal control/key sequences are inserted as literal text and normal editing/control keys stop working.
Observed symptoms include:
- Arrow keys are inserted as visible text such as
[A,[B,[C,[D. - Focus transitions can insert
[I/[O-style text. - Delete may insert
[3~-style text. - Backspace behaves incorrectly; in one failure mode it appears to insert/move like spaces rather than deleting normally.
Ctrl-Cand other control key handling can stop working.- Once this happens, the session becomes effectively unusable and the only reliable recovery is closing the terminal window and resuming from a new one.
This appears related to the same class of Windows TUI input / VT sequence leakage issues discussed in:
- #24929
- #28301
- #12542
However, the #12542 final root cause does not seem to match my environment: my PATH uses a native Windows Git (MinGit 2.54.0) and does not have a wslgit shim before Git.
Steps to reproduce
I do not yet have a deterministic minimal reproducer, but the issue happens during normal long-running interactive CLI use on native Windows:
- Open Windows Terminal.
- Start PowerShell 7.
- Run
codex. - Use the session normally for a while.
- Switch focus between Windows Terminal and other windows and/or continue editing in the composer.
- Eventually the composer may start inserting literal control-sequence tails such as
[I,[C,[D,[A,[3~, and control keys stop working correctly.
Expected behavior
The TUI should continue parsing focus events, arrow keys, Delete, Backspace, Enter, and Ctrl-C as terminal/input events. Escape-sequence tails should not be inserted into the composer as literal text.
Actual behavior
The composer starts receiving and inserting escape-sequence tails as ordinary text, and the TUI input state becomes unusable.
Workarounds tried
I set the environment variable both in the current process and user environment:
[Environment]::SetEnvironmentVariable(
'CODEX_TUI_DISABLE_KEYBOARD_ENHANCEMENT',
'1',
'User'
)
The current shell also reports:
$env:CODEX_TUI_DISABLE_KEYBOARD_ENHANCEMENT
# 1
This seems to reduce or change the failure surface but does not fully solve the problem.
Additional local checks
codex doctor --jsonreports installation is consistent.- The terminal is detected as Windows Terminal.
- The active Git in PATH is native Windows Git:
C:\Users\<USER>\Tools\MinGit-2.54.0\cmd\git.exe
No wslgit shim appears before Git in PATH.
Notes
Given #24929 and #28301 are still open and 0.141.0 release notes do not mention a Windows TUI input / focus reporting / VT input fix, I am filing this as an additional native Windows data point from 0.139.0 rather than upgrading first.
3 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Adding another native Windows data point from a current/latest install.
Environment
codex-cli 0.142.510.0.26200, x641.24.11321.0codex doctor: installation, config, state DBs, and auth are healthy; terminal is detected as Windows Terminal; npm latest is also0.142.5.Observed symptoms
During normal interactive
codexuse on native Windows, the composer can intermittently enter a broken input state where terminal control-sequence tails are inserted as literal text. The most visible examples are:Observed behavior includes:
[B/[A/ etc. in the input box instead of moving through history or moving the cursor.[O/[I-style focus reports in the composer.This matches the class of issues described here and in #24929 / #28301, but I wanted to note that the symptom is still being seen on
0.142.5, not only on the older0.139.0report above.Local interpretation
This looks less like Windows Terminal producing invalid input, and more like the Codex TUI input layer / raw-mode / Windows VT-input handling occasionally becoming unsynchronized. Windows Terminal appears to be emitting normal focus/key escape sequences, but Codex sometimes receives or handles only the sequence tail and inserts it into the composer as text.
codex --no-alt-screenis a useful mitigation to reduce terminal-state fallout, but it does not look like a full root-cause fix if the underlying Windows TUI input mode can still desynchronize.Potential fix direction
The mitigation described in #28301 sounds aligned with this data point: Windows-gated handling that avoids or defensively clears
ENABLE_VIRTUAL_TERMINAL_INPUT, avoids focus-change reporting on native Windows when using crossterm's Windows event stream, and re-checks the input mode after event stream setup / polling transitions.On Windows, the issue was resolved by moving the standard Git for Windows path C:\Program Files\Git\cmd to the first position in the Windows PATH environment variable, ahead of C:\Windows\System32.
Codex is configured to use Bash. After placing the Git Bash path first in PATH, Codex used the Git Bash environment instead of the Windows Bash environment. The key failures and escape-sequence leakage stopped, including when switching between windows. No other changes were made.