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

Open 💬 10 comments Opened Apr 25, 2026 by Tomer96
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

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

View original on GitHub ↗

10 Comments

github-actions[bot] contributor · 2 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #19171

Powered by Codex Action

Tomer96 · 2 months ago

This is not a duplicate!!!!!!

SlippyDong · 2 months ago

@Tomer96 maybe it's unrelated, but I just opened a ticket that may solve your problem: https://github.com/openai/codex/issues/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.

Tomer96 · 2 months ago

@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%.

Tomer96 · 2 months ago

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.

Tomer96 · 2 months ago

<img width="1224" height="1172" alt="Image" src="https://github.com/user-attachments/assets/eec6fd5a-5a38-4f72-8b14-2aa7ee322b67" />

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
SlippyDong · 2 months ago
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?

Tomer96 · 2 months ago

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.

hakunan116 · 1 month ago

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.

real-worlds · 5 days ago

try path=
i.e lowercase path