Skip to content

WSL CLI startup from /home/... stalls ~60s in cmd.exe set TERM_PROGRAM probe #22176

Closed

Description

@Anong0u0

What version of Codex CLI is running?

codex-cli 0.130.0

What subscription do you have?

ChatGPT Plus via ChatGPT sign-in auth (auth_mode: chatgpt).

This startup stall happens before the first model request or tool call, so the plan tier does not appear to affect reproduction.

Which model were you using?

When I normally use Codex in this environment, I use gpt-5.4 with high reasoning effort.

For this specific bug, the stall occurs during interactive CLI startup before the first prompt/model request, so the model choice does not appear to affect reproduction.

What platform is your computer?

Ubuntu 22.04.2 LTS on WSL2:

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 x86_64

Windows host:

Microsoft Windows NT 10.0.19045.0 x64
cmd.exe ver: Microsoft Windows [Version 10.0.19045.6456]

WSL component versions:

WSL 2.6.3.0
kernel 6.6.87.2-1
WSLg 1.0.71

What terminal emulator and version are you using (if applicable)?

Primary repro is in an interactive WSL shell with:

zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

I also reproduced the same behavior under script(1) pseudo-TTY capture for strace, which suggests this is not specific to one terminal frontend.

What issue are you seeing?

Starting interactive Codex CLI from a WSL Linux cwd such as /home/... stalls for about 60 seconds before the UI becomes usable.

strace consistently shows Codex spawning:

cmd.exe /d /s /c "set TERM_PROGRAM"

during startup. When the launcher cwd is a WSL Linux path, that probe is followed by an approximately 60 second wait, and only after that do I see output referencing a \\wsl.localhost\\Ubuntu-22.04\\home\\... path and TERM_PROGRAM.

Control test:

  • Launching the same unmodified Codex build from a Windows-backed cwd such as /mnt/c/Windows/System32
  • while still targeting the same Linux repo via -C /home/...

does not show the equivalent 60 second stall.

Additional observation:

  • Pre-setting TERM_PROGRAM=foo does not prevent the cmd.exe probe.
  • Codex still executes cmd.exe /d /s /c "set TERM_PROGRAM" and still stalls when launched from /home/....

Based on the traces, the practical trigger appears to be the cwd from which Codex is launched in WSL, not the workspace path eventually used by -C.

What steps can reproduce the bug?

Minimal repro:

  1. Install Codex CLI normally on WSL.
  2. Open a WSL shell in a Linux-backed directory such as:
cd /home/<user>/<repo>
  1. Start interactive Codex:
codex --no-alt-screen
  1. Observe that startup stalls for roughly 60 seconds before the UI becomes usable.

Control repro:

  1. From a Windows-backed cwd instead, for example:
cd /mnt/c/Windows/System32
  1. Start the same Codex build, but point it back at the same Linux repo:
codex -C /home/<user>/<repo> --no-alt-screen
  1. Observe that the equivalent ~60 second stall does not occur.

Instrumented repro used for trace capture:

CODEX_JS="$(npm root -g)/@openai/codex/bin/codex.js"

cd /home/<user>/<repo>
timeout 75s strace -f -ttT -o home_launch.strace \
  script -q -c "node $CODEX_JS --no-alt-screen" /dev/null

cd /mnt/c/Windows/System32
timeout 20s strace -f -ttT -o windows_cwd_launch_home_C.strace \
  script -q -c "node $CODEX_JS -C /home/<user>/<repo> --no-alt-screen" /dev/null

Representative trace lines from the slow /home/... launch:

execve("/mnt/c/Windows/system32/cmd.exe",
  ["cmd.exe", "/d", "/s", "/c", "set TERM_PROGRAM"], ...)
...
<... poll resumed>) = 1 ([{fd=8, revents=POLLIN}]) <60.024460>
read(7, "'\\\\wsl.localhost\\Ubuntu-22.04\\ho"..., 4096) = 158

Representative trace lines from the control launch from /mnt/c/...:

execve("/mnt/c/Windows/system32/cmd.exe",
  ["cmd.exe", "/d", "/s", "/c", "set TERM_PROGRAM"], ...)

but no corresponding \\wsl.localhost\\... output and no matching ~60 second wait in the same probe path.

What is the expected behavior?

Interactive Codex startup on WSL should not block for ~60 seconds just because the launcher cwd is a Linux path such as /home/....

If Codex needs terminal detection in WSL, I would expect one of these behaviors instead:

  • Use a Linux-native probe in WSL rather than spawning cmd.exe
  • Or launch the Windows helper with a safe Windows cwd
  • Or skip the probe when TERM_PROGRAM is already present

Additional information

Observed facts from my local traces:

  • cmd.exe /d /s /c "set TERM_PROGRAM" is executed during startup
  • the slow path reproduces when Codex is launched from /home/...
  • the slow path does not reproduce in the same way when Codex is launched from /mnt/c/... and given -C /home/...
  • pre-setting TERM_PROGRAM=foo does not suppress the cmd.exe probe
  • I reproduced this on the current installed CLI here: codex-cli 0.130.0
  • before drafting this report, I searched for related WSL / UNC / cmd.exe / TERM_PROGRAM issues and did not find a clear exact duplicate for this specific CLI startup stall

Practical workaround:

cd /mnt/c/Windows/System32
codex -C /home/<user>/<repo> --no-alt-screen

I also have a local shell-level workaround that temporarily shadows cmd.exe, but I am intentionally not leading with that because the simpler control above already isolates the issue enough.

Related reports that seem adjacent but not identical:

If useful, I can attach sanitized trace snippets or provide a smaller reproducer script.

Activity

  1. added
    bug
    CLI
    windows-os
    TUI
    on May 11, 2026
  2. removed
    CLI
    on May 11, 2026
  3. novcky commented on May 22, 2026

    @novcky

    I can confirm the same startup stall from a separate WSL2 environment on a newer CLI version.

    Environment:

    codex-cli 0.133.0
    Ubuntu 24.04.4 LTS on WSL2
    Linux 6.6.114.1-microsoft-standard-WSL2
    Windows Terminal and VS Code integrated terminal both affected
    

    The behavior matches this report:

    cd /root/projects/github/Aether
    /usr/bin/time -f 'repo_real %e' cmd.exe /d /s /c set TERM_PROGRAM
    
    '\\wsl.localhost\ubuntu-24-04\root\projects\github\Aether'
    CMD.EXE was started with the above path as the current directory.
    UNC paths are not supported. Defaulting to Windows directory.
    Environment variable TERM_PROGRAM not defined
    repo_real 61.05
    

    From a Windows-backed cwd, the same command is fast:

    cd /mnt/c
    /usr/bin/time -f 'mntc_real %e' cmd.exe /d /s /c set TERM_PROGRAM
    
    Environment variable TERM_PROGRAM not defined
    mntc_real 0.06
    

    And this avoids the Codex startup delay while keeping the same project directory:

    cd /mnt/c
    codex --cd /root/projects/github/Aether

    strace confirms the startup delay is in the Windows interop request:

    execve("/mnt/c/Windows/system32/cmd.exe",
      ["cmd.exe", "/d", "/s", "/c", "set TERM_PROGRAM"], ...) = 0
    
    write(4, "...C:\\Windows\\system32\\cmd.exe\0\\\\wsl.localhost\\ubuntu-24-04\\root\\projects\\github\\Aether\0...cmd.exe\0/d\0/s\0/c\0set TERM_PROGRAM\0", 254) = 254
    
    poll([{fd=-1}, {fd=6, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=POLLIN}, {fd=3, events=POLLIN}], 5, -1)
      = 1 ([{fd=8, revents=POLLIN}]) <60.020825>
    

    Two additional observations:

    • CODEX_TUI_DISABLE_KEYBOARD_ENHANCEMENT=1 codex still triggers the cmd.exe /d /s /c set TERM_PROGRAM probe.
    • Setting Linux-side TERM_PROGRAM=Windows_Terminal also does not prevent the Windows-side probe.

    Based on codex-rs/tui/src/tui/keyboard_modes.rs, a low-risk fix could be:

    1. Check CODEX_TUI_DISABLE_KEYBOARD_ENHANCEMENT before any VS Code / Windows-side terminal detection is attempted.
    2. Prefer Linux-side TERM_PROGRAM when it is already present, especially TERM_PROGRAM=vscode, before falling back to Windows interop.
    3. If the Windows-side fallback is still needed, set a Windows-backed cwd for the child process, for example /mnt/c/Windows/System32 if it exists, so WSL does not pass a \\wsl.localhost\... cwd to Windows.

    I can help test a focused fix on this affected WSL setup if needed.

  4. zaaack commented on Jun 13, 2026

    @zaaack

    Same here. Thanks for the comment upstairs. I wrote an alias to bypass this bug, but exiting the cli is still very slow.

    #fix: https://github.com/openai/codex/issues/22176
    alias codex="export p=$(pwd); cd /mnt/c/Windows/System32; codex --cd $p --no-alt-screen; cd $p"
  5. Acheatcn commented on Aug 10, 2026

    @Acheatcn

    Still reproducible on the latest stable Codex CLI version available in my environment: 0.147.0.

    Environment:

    • Ubuntu 24.04.4 LTS on WSL2
    • WSL 2.7.11.0
    • Kernel 6.18.33.2-microsoft-standard-WSL2
    • Windows 10.0.19045.6466
    • Windows Terminal 1.24.11911.0
    • Reproduced in both Bash and zsh
    • No tmux, screen, or zellij
    • codex doctor --json: overallStatus: ok
    • Doctor reports 0.147.0 as the latest/current version

    Representative timings from strace:

    cmd.exe child:
    poll(...) <59.912354>
    
    Codex parent:
    read(...) <61.196376>
    
    Setting TERM_PROGRAM=Windows_Terminal does not prevent the probe.
    
    Both workarounds make startup immediate:
    
    1. Remove /mnt/c/Windows/system32 from PATH only for the Codex process.
    2. Launch Codex from /mnt/d and use -C to point back to the WSL project.
    
    This confirms the issue is still present in 0.147.0.
    
  6. etraut-openai commented on Oct 12, 2026

    @etraut-openai
    Contributor

    (response from codex)

    Closing as fixed by #45811 in CLI v0.162.1. The Windows TERM_PROGRAM probe in WSL now has a one-second deadline including slow launch, caches timeouts and cleans up the child. A blocked probe should no longer hold startup for about a minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TUIbugperformancewindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions