Skip to content

Windows: hide command-safety PowerShell parser process to avoid pwsh.exe console flashes #18984

@WanderlustCoder

Description

@WanderlustCoder

Summary

On Windows, @openai/codex 0.122.0 (native codex.exe) spawns a command-safety PowerShell parser process as:

pwsh.exe -NoLogo -NoProfile -NonInteractive -EncodedCommand <...>

When codex.exe itself is launched hidden by a parent process, the descendant pwsh.exe still briefly flashes a visible console window. This appears to be because the PowerShell parser child process is spawned without Windows hide/no-window creation flags.

Evidence

Captured on Windows 11 on 2026-04-22 while running TORQUE factory Codex tasks:

torque-server (node.exe, windowsHide:true)
  └── codex.exe  (spawned directly, not through codex.cmd / node wrapper)
        └── pwsh.exe -NoLogo -NoProfile -NonInteractive -EncodedCommand <...>

The parent windowsHide:true is applied to codex.exe. The pwsh.exe descendant still flashes a visible console. We already bypassed the npm/node wrapper (@openai/codex/bin/codex.js) and spawn the bundled native binary directly; the remaining visible window is from the native binary's own child process.

Likely call site

In the current upstream tree, the command-safety parser process is started in:

codex-rs/shell-command/src/command_safety/powershell_parser.rs

Specifically, PowershellParserProcess::spawn() builds:

let mut child = Command::new(executable)
    .args([
        "-NoLogo",
        "-NoProfile",
        "-NonInteractive",
        "-EncodedCommand",
        encoded_parser_script(),
    ])
    .stdin(Stdio::piped())
    .stdout(Stdio::piped())
    .stderr(Stdio::null())
    .spawn()?;

I do not see a Windows-specific creation_flags() call on this Command before .spawn().

Suggested fix

On Windows, apply CREATE_NO_WINDOW to the PowerShell parser child process:

#[cfg(windows)]
use std::os::windows::process::CommandExt;

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

let mut command = Command::new(executable);
command
    .args([
        "-NoLogo",
        "-NoProfile",
        "-NonInteractive",
        "-EncodedCommand",
        encoded_parser_script(),
    ])
    .stdin(Stdio::piped())
    .stdout(Stdio::piped())
    .stderr(Stdio::null());

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

let mut child = command.spawn()?;

An equivalent STARTF_USESHOWWINDOW + SW_HIDE setup would also work, but CREATE_NO_WINDOW is the simplest fit for a non-interactive helper process.

Reproducer

  1. On Windows 11, install @openai/codex@0.122.0.
  2. From a parent process, spawn the native bundled codex.exe with hidden-window semantics. For example, Node child_process.spawn(..., { windowsHide: true }).
  3. Run several Codex tasks that trigger shell command-safety checks.
  4. Observe that pwsh.exe -NoLogo -NoProfile -NonInteractive -EncodedCommand <...> children appear in the process tree and briefly flash visible console windows.

Expected: the parser pwsh.exe children still run, but no visible console window appears, even briefly.

Actual: a visible PowerShell console flashes for the parser child despite the parent being hidden.

Notes

This is not a request to change the npm wrapper. The wrapper has already been bypassed in the reproducer. The requested fix is in the Rust/native binary's PowerShell parser spawn path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtool-callsIssues related to tool callingwindows-osIssues related to Codex on Windows systems

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions