Skip to content

Codex App for Windows shows different environment variables between the integrated terminal and the agent shell_command runner. #19546

Open

Description

@Tomer96

What version of the Codex App are you using (From “About Codex” dialog)?

26.422.30944

What subscription do you have?

Plus

What platform is your computer?

Windows

What issue are you seeing?

Codex App for Windows shows different environment variables between the integrated terminal and the agent shell_command runner.

Integrated terminal:
[Environment]::GetEnvironmentVariables('Process').GetEnumerator() |
Where-Object { $.Key -ceq 'Path' -or $.Key -ceq 'PATH' } |
ForEach-Object { $_.Key }

Output:
Path

Agent shell_command runner output:
Path
PATH

Impact:
MSBuild fails before compilation with:
MSB6001: Invalid command line switch for "CL.exe".
System.ArgumentException: Item has already been added. Key in dictionary: 'Path' Key being added: 'PATH'

What steps can reproduce the bug?

Codex App for Windows shows different environment variables between the integrated terminal and the agent shell_command runner.

Integrated terminal:
[Environment]::GetEnvironmentVariables('Process').GetEnumerator() |
Where-Object { $.Key -ceq 'Path' -or $.Key -ceq 'PATH' } |
ForEach-Object { $_.Key }

Output:
Path

Agent shell_command runner output:
Path
PATH

Impact:
MSBuild fails before compilation with:
MSB6001: Invalid command line switch for "CL.exe".
System.ArgumentException: Item has already been added. Key in dictionary: 'Path' Key being added: 'PATH'

What is the expected behavior?

No response

Additional information

Bug report id: a8b57032-ceca-48a9-b203-f953fdd1a6bd

Activity

  1. added
    app
    on Apr 25, 2026
  2. added
    bug
    windows-os
    tool-calls
    on Apr 25, 2026
  3. github-actions commented on Apr 25, 2026

    @github-actions
    Contributor
  4. Tomer96 commented on Apr 25, 2026

    @Tomer96
    Author

    This is not a duplicate!!!!!!

  5. SlippyDong commented on Apr 25, 2026

    @SlippyDong

    @Tomer96 maybe it's unrelated, but I just opened a ticket that may solve your problem: #19550

    If you're using Powershell (and the agent as well) and Powershell was installed through Winget or Microsoft Store, the agent struggles with certain tool calls and seems to be unable to run certain commands for pnpm or node among others. I noticed that when I uninstalled Powershell 7 and then reinstalled it using a MSI installer, both the install location and path were set correctly and the tool calls stopped failing.

    It might be worth checking to see if you have Powershell installed in C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.1.0_x64__{some_version} or if you have it installed in C:\Program Files\PowerShell\7

    If you have the WindowsApps version, just uninstall it and download the MSI package from Microsoft and install that.

  6. Tomer96 commented on Apr 25, 2026

    @Tomer96
    Author

    @SlippyDong Hello.

    I do not have the MS version of PWSH. I have the latest pwsh released install from the official repo: https://github.com/PowerShell/PowerShell/releases/tag/v7.6.1 (specific PowerShell-7.6.1-win-x64.msi)

    This is a fuckup in the Codex app for Windows for sure 100%.

  7. Tomer96 commented on Apr 25, 2026

    @Tomer96
    Author

    It's important to note that this issue is observed only with the Codex app for Windows. The Codex extension for VS Code or the Codex CLI does NOT have such issues with double path injection; they use a normalized Path.

  8. Tomer96 commented on Apr 25, 2026

    @Tomer96
    Author
    Image

    needed to add a dedicated rule under AGENTS.md so the model can start listening.

    with-clean-path.ps1

    param(
        [Parameter(ValueFromRemainingArguments = $true)]
        [string[]]$Command
    )
    
    $vars = [System.Environment]::GetEnvironmentVariables("Process")
    $pathValue = if ($vars.Contains("Path")) {
        [string]$vars["Path"]
    } elseif ($vars.Contains("PATH")) {
        [string]$vars["PATH"]
    } else {
        ""
    }
    
    Remove-Item Env:PATH -ErrorAction SilentlyContinue
    Remove-Item Env:Path -ErrorAction SilentlyContinue
    $env:Path = $pathValue
    
    if ($Command.Count -eq 0) {
        [System.Environment]::GetEnvironmentVariables("Process").GetEnumerator() |
            Where-Object { $_.Key -ceq "Path" -or $_.Key -ceq "PATH" } |
            ForEach-Object { $_.Key }
        exit 0
    }
    
    & $Command[0] @($Command | Select-Object -Skip 1)
    exit $LASTEXITCODE
  9. SlippyDong commented on Apr 25, 2026

    @SlippyDong

    It's important to note that this issue is observed only with the Codex app for Windows. The Codex extension for VS Code or the Codex CLI does NOT have such issues with double path injection; they use a normalized Path.

    Ah, sorry, I did not notice this distinction. I never used Codex app itself. Are there any benefits over using the IDE extension?

  10. Tomer96 commented on Apr 25, 2026

    @Tomer96
    Author

    I've been using Codex CLI, Codex IDE extension, and now the Codex App extensively over the past year, and I think the correct answer for the current state of the Codex app is absolutely no. The app is not yet as stable and robust as I would like it to be.

  11. removed
    app
    on Apr 25, 2026
  12. hakunan116 commented on Jun 5, 2026

    @hakunan116

    I can reproduce this on a newer Codex Desktop build as well.

    Environment observed:

    • Windows / PowerShell 5.1 command runner
    • Codex Desktop package path: OpenAI.Codex_26.602.3474.0_x64__2p2nqsd0c76g0
    • App server process: codex.exe app-server --analytics-default-enabled
    • Command runner copied to: %USERPROFILE%\.codex\.sandbox-bin\codex-command-runner-0.137.0-alpha.4.exe

    Observed in the agent shell command environment:

    cmd /c set path

    prints both entries in the same process environment:

    PATH=...
    Path=...
    

    The values are effectively identical. This causes PowerShell environment enumeration to fail:

    Get-ChildItem Env:

    with:

    Get-ChildItem : An item with the same key has already been added.
    

    I also checked the persisted Windows environment sources:

    reg query HKCU\Environment
    reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

    Both only show Path, not a separate uppercase PATH, so the duplicate appears to be introduced while Codex constructs the child process environment.

    Parent process chain observed for the shell command:

    powershell.exe
    <- codex.exe app-server --analytics-default-enabled
    <- Codex.exe
    <- explorer.exe
    

    Relevant detail: Codex launches shell commands with powershell.exe -NoProfile -Command ..., so a PowerShell profile workaround cannot reliably fix this for agent shell commands.

    Suggested fix: when constructing child environments on Windows, normalize keys case-insensitively and emit exactly one canonical Path entry instead of passing both PATH and Path.

  13. real-worlds commented on Jul 15, 2026

    @real-worlds

    try path=
    i.e lowercase path

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

    bugtool-callswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions