Skip to content

Windows: cmd/PowerShell windows stay visible for each shell command during a session (CLI 0.157.1) #48876

Closed as duplicate

Description

@guangxiangdebizi

What version of Codex CLI is running?

codex-cli 0.157.1 (npm install -g @openai/codex@latest, confirmed with codex --version)

What subscription do you have?

ChatGPT login. The CLI does not print the plan tier.

Which model were you using?

gpt-6-astra

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64

What terminal emulator and version are you using?

Cursor integrated terminal. Windows default console delegation was Automatic, so each new console was handed to Windows Terminal (CASCADIA_HOSTING_WINDOW_CLASS).

Codex doctor report

not included

What issue are you seeing?

This still happens on the latest CLI, and it happens for the whole session, not only at launch.

Every non-interactive shell command Codex runs (powershell.exe, cmd.exe, git.exe, and the command-safety PowerShell parser) allocates its own visible console. The window stays on screen until that command exits, so a multi-second command leaves a cmd/PowerShell window sitting on the desktop. Parallel tool calls open several at once. With the default terminal set to Automatic, Windows Terminal also opens a real window for the same process. The owner of that window is WindowsTerminal.exe under svchost.exe, so it is not a child of codex.exe.

Related open reports: #18984, #26613, #23856, #23892, #37599. Those cover the parser flash, background polling, and the code-mode host. This report is the session-long case on CLI 0.157.1, plus a workaround that was verified locally and the upstream change that removes the need for it.

What steps can reproduce the bug?

  1. On Windows 11, install @openai/codex 0.157.1 and leave the default terminal on Automatic.
  2. Run codex in a trusted repo and let it execute shell commands (git, rg, python, gh, or any PowerShell pipeline).
  3. Watch the desktop while the turn is running, not only during process start.

What is the expected behavior?

Non-interactive children should keep piped stdin/stdout/stderr and should not create a visible console or a Windows Terminal window. An interactive codex session and any terminal the user opened themselves should stay visible.

Additional information

The elevated Windows sandbox path already passes CREATE_NO_WINDOW (windows-sandbox-rs CreateProcessWithLogonW). The normal shell, command-safety parser, hooks, and code-mode host spawns do not. -WindowStyle Hidden does not help: the console host is created before that argument runs. Hiding every CASCADIA_HOSTING_WINDOW_CLASS window is also unsafe, because those windows belong to WindowsTerminal.exe, not to Codex.

Proposed upstream fix

On every non-interactive Windows Command that already uses piped stdio, set CREATE_NO_WINDOW before spawn():

#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x0800_0000;

#[cfg(windows)]
command.creation_flags(CREATE_NO_WINDOW);

Apply that in at least:

  • codex-rs/shell-command/src/command_safety/powershell_parser.rs (the long-lived AST parser)
  • the Windows shell exec path that launches powershell.exe / cmd.exe / git.exe for a tool call
  • hook execution (pwsh.exe -NoProfile -Command ...)
  • Connection::spawn() for codex-code-mode-host

Keep the existing pipes. Do not disable command-safety or shell execution. CREATE_NO_WINDOW still creates the console handles the child needs for redirected stdio; it only skips the visible window. A shared helper is better than one call site, because each of the issues above is a separate spawn.

Verified local workaround

Until that ships, two user-level changes stop the windows without wrapping Git or changing PATH:

  1. Set the current-user console delegation to Windows Console Host so new consoles are not brokered to Windows Terminal:

    • key: HKCU\Console\%Startup
    • DelegationConsole and DelegationTerminal = {B23D10C0-E52E-411E-9D5B-C09FDF709C7D}

    Windows Terminal can still be opened manually. Existing Terminal windows stay open.

  2. Run a small out-of-process guard. On EVENT_OBJECT_SHOW / EVENT_OBJECT_CREATE, plus a 200ms scan, hide a top-level window only when all of the following are true:

    • class is ConsoleWindowClass or PseudoConsoleWindow
    • the process ancestry contains a console launcher (cmd.exe, powershell.exe, pwsh.exe, git.exe, or another tool Codex just spawned) and also codex.exe or ChatGPT.exe
    • the nearest non-conhost process is not the interactive codex.exe itself

    Leave a conhost.exe whose only ancestor is codex.exe alone, and leave a cmd.exe the user launched outside Codex. That distinction matters: a blanket hide of every console window also hides the user's own terminal.

Checked on this machine after upgrading to CLI 0.157.1:

  • a cmd.exe whose parent was codex.exe produced no new visible window
  • a cmd.exe launched from the user session stayed visible (ConsoleWindowClass)
  • the guard log recorded the Codex child as rule=CodexShell and did not record the user window

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugtool-callswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions