codex - 💡(How to fix) Fix Windows: Codex 0.123.0 injects both PATH and Path into the shell environment, breaking PowerShell Env provider and causing intermittent shell startup failures [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19171Fetched 2026-04-24 05:59:29
View on GitHub
Comments
2
Participants
3
Timeline
10
Reactions
1
Timeline (top)
labeled ×5unlabeled ×3commented ×2

Error Message

Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.

Root Cause

Because Windows environment variables are case-insensitive, PowerShell's Env: provider treats this as a duplicate-key collision and fails with:

Code Example

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

---

Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.

---

codex --version

---

codex-cli 0.123.0

---

npm list -g @openai/codex --depth=0

---

@openai/codex@0.123.0

---

cmd /c "set PATH & set Path"

---

Get-ChildItem Env:

---

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

---

reg query "HKCU\Environment"
   reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.123.0

What subscription do you have?

ChatGPT Pro

Which model were you using?

gpt-5.4

What platform is your computer?

Microsoft Windows x64

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

Codex Desktop app on Windows, with the npm-installed codex also on PATH

What issue are you seeing?

On Windows, Codex appears to construct a malformed process environment for shell execution by injecting both PATH and Path into the same process environment block.

Because Windows environment variables are case-insensitive, PowerShell's Env: provider treats this as a duplicate-key collision and fails with:

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

In earlier threads on the same machine, this also correlated with Codex shell startup failures before command execution, including:

Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.

So the root problem here appears to be malformed Windows env var merging in Codex, not a repo-specific issue.

What steps can reproduce the bug?

In a Codex Windows session:

  1. Confirm the installed CLI version:

    codex --version

    Observed:

    codex-cli 0.123.0
  2. Confirm the npm package version:

    npm list -g @openai/codex --depth=0

    Observed:

  3. Inspect the effective process environment from within the Codex shell context:

    cmd /c "set PATH & set Path"

    Observed: both PATH= and Path= are present in the same process environment.

  4. Try enumerating the PowerShell env provider:

    Get-ChildItem Env:

    Observed:

    Get-ChildItem : An item with the same key has already been added.
  5. Compare against the actual Windows environment sources:

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

    Observed: only Path exists in the registry sources, not a separate uppercase PATH.

What is the expected behavior?

Codex should normalize Windows environment variables case-insensitively before spawning the shell.

Expected behavior:

  • only one canonical Path entry should be present in the spawned process environment
  • Get-ChildItem Env: should succeed normally
  • shell startup should not intermittently fail due to malformed env state

What do you see instead?

Codex spawns a shell environment that includes both PATH and Path, which breaks PowerShell env enumeration and appears to contribute to intermittent shell startup failures.

Additional information

Concrete local evidence:

  • where codex resolves the npm global install first:
    • C:\Users\hnili\AppData\Roaming\npm\codex
  • In the Codex shell process, both PATH and Path are present.
  • In HKCU\Environment and HKLM\...\Environment, only Path exists.
  • So the duplicate is being introduced during Codex environment construction, not inherited directly from Windows registry state.

This looks distinct from the broader 8009001d symptom reports because it provides a narrower repro and a likely root cause.

Possibly related:

  • #19100
  • #13917
  • #14057
  • #18465

extent analysis

TL;DR

The most likely fix is to modify the Codex CLI to normalize Windows environment variables case-insensitively before spawning the shell, ensuring only one canonical Path entry is present.

Guidance

  • Verify that the issue is indeed caused by the duplicate PATH and Path environment variables by checking the process environment in the Codex shell context using cmd /c "set PATH & set Path".
  • Inspect the Codex CLI code to identify where the environment variables are being constructed and modified, focusing on any case-sensitive operations that may introduce the duplicate PATH variable.
  • Consider implementing a case-insensitive merge of environment variables in the Codex CLI to prevent duplicate keys, ensuring that only one Path entry is present in the spawned process environment.
  • Test the modified Codex CLI with the provided reproduction steps to confirm that the issue is resolved and Get-ChildItem Env: succeeds without errors.

Example

No code snippet is provided as the issue requires modification of the Codex CLI codebase, which is not publicly available.

Notes

The provided information suggests that the issue is specific to the Codex CLI on Windows and is not a general PowerShell or Windows environment variable issue. The root cause appears to be the introduction of a duplicate PATH variable during Codex environment construction.

Recommendation

Apply a workaround by modifying the Codex CLI to normalize Windows environment variables case-insensitively, as this addresses the identified root cause and is likely to resolve the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING