Windows: codex sign-in menu exits immediately (can’t press Enter / select option)

Resolved 💬 6 comments Opened Feb 4, 2026 by CodebyAmbrose Closed Feb 5, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

Hi — I’m on Windows and can’t get past the Codex CLI sign-in screen.

What happens

Running codex shows the sign-in options (ChatGPT / Device Code / API key)

Before I can press Enter or choose an option, it immediately drops back to the terminal prompt

Running it again repeats the same screen (loop)

Tried

PowerShell and CMD (same behavior)

Environment

OS: Windows 11

<img width="731" height="221" alt="Image" src="https://github.com/user-attachments/assets/eb0940b2-a887-427b-8871-406fe513f0aa" />

codex-cli: 0.95.0

node: v22.19.0

npm: 10.9.3

Any guidance on what to check or how to get logs to diagnose why the interactive sign-in menu exits instantly?

View original on GitHub ↗

6 Comments

etraut-openai contributor · 5 months ago

Did this work on previous versions of the CLI, or is this the first time you're trying it on this machine? Just wondering whether this is a regression.

This is the first report of this issue that we've heard, so it's likely that it's something specific to your system or configuration.

There might be some useful clues in the logs. You can find it in ~/.codex/log/codex-tui.log.

Ashutosh0x contributor · 5 months ago

Root-Cause Analysis: Windows TUI Early Exit during Onboarding/Login (Issue #10661)

Problem

On Windows, some users report that when they run codex login or enter the onboarding flow, the sign-in menu (picking ChatGPT, Device Code, or API Key) exits immediately before they can interact with it. This prevents users from selecting an authentication method.

Technical Root Cause

The TUI initialization sequence in codex-rs/tui/src/tui.rs sets up raw mode and keyboard enhancement but did not explicitly clear the OS-level input buffer upon startup.

On Windows, it is common for the terminal to have buffered input. For example:

  • If the user pressed Enter to run the codex command, the trailing newline may remain in the buffer.
  • Trailing characters from a previous paste or accidental key presses during terminal initialization.

When the TUI starts and begins polling for events, it may immediately receive these "phantom" inputs (e.g., KeyCode::Enter or KeyCode::Esc). In the onboarding flow (codex-rs/tui/src/onboarding/onboarding_screen.rs), the event loop processes these events immediately. If an Enter event is captured before the user has made a selection, it can trigger a state transition that leads to an early exit or an accidental "Skip" action depending on the UI's initial focus.

Additionally, if the terminal stream encountered an error or a pipe closure, the onboarding loop lacked a robust exit condition for None results from the event stream, which could lead to unexpected behavior if the stream ended prematurely.

Proposed Resolution

  1. Flush Input Buffer on Init: Call flush_terminal_input_buffer() immediately after set_modes() in tui::init(). This implementation utilizes the Win32 FlushConsoleInputBuffer API to ensure that any keys pressed before the TUI was ready are discarded, preventing stale inputs from triggering unintended actions.
  2. Robust Event Loop: Added an explicit break in the run_onboarding_app event loop when the event stream is exhausted (None result).

Implementation Details

  • codex-rs/tui/src/tui.rs: Updated init() to invoke flush_terminal_input_buffer().
  • codex-rs/tui/src/onboarding/onboarding_screen.rs: Updated the event loop in run_onboarding_app to break on None.

Verification

  • Automated Tests: Ran cargo test -p codex-tui --lib onboarding. All 11 onboarding-related tests passed.
  • Manual Verification: Structural check confirms that FlushConsoleInputBuffer is correctly handled for the Windows target.
CodebyAmbrose · 5 months ago

@Ashutosh0x Hi — just a quick follow-up: your technique worked 100%.

After applying the steps you shared, the CLI stopped exiting early and everything is working normally now. I’ve been trying to figure this out for months, so I really appreciate your help. Thanks again!

etraut-openai contributor · 5 months ago

@Ashutosh0x, thanks for the analysis. I'd welcome a PR with a minimal targeted fix if you're interested in contributing it.

Ashutosh0x contributor · 5 months ago

Glad it worked! I'll put together a PR with these changes shortly.

CodebyAmbrose · 5 months ago

@Ashutosh0x Thanks alot,I'm really grateful Man!