codex icon indicating copy to clipboard operation
codex copied to clipboard

Windows: bundled runtime ships a git without bash.exe and never adds usr\bin to PATH, so shell=bash / shell=sh always degrade to cmd.exe

Open IndexEeve opened this issue 2 weeks ago • 8 comments

What version of Codex CLI is running?

codex-cli 0.171.0-alpha.13, bundled with Codex Desktop 26.1117.3838.0 (app\resources\codex.exe). The standalone codex-cli 0.167.0-alpha.4.1 behaves the same way.

What subscription do you have?

N/A — this is shell discovery and runtime packaging, no model or subscription is involved (the resolution code path is provider-independent).

Which model were you using?

N/A (not model-dependent).

What platform is your computer?

Microsoft Windows NT 10.0.26300.0 x64

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

No terminal: reproduced from codex exec (stdout is not a TTY) and from the Codex Desktop app.

Codex doctor report

Trimmed for privacy; the relevant fields:

os                      Windows 10.0.26300 (Windows 11 Professional) [64-bit]
console input code page 936
sandbox backend         elevated
runtime version         0.171.0-alpha.13

What issue are you seeing?

On Windows, Codex ships a POSIX-capable git in its primary runtime, but that runtime cannot actually provide a POSIX shell, so shell: "bash" and shell: "sh" can never resolve from it and fall through to cmd.exe.

The bundled runtime tree (...\OpenAI.CodexPrimaryRuntime.v26-1117-835-0...\dependencies\native\git\, also %USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\native\git\ in older installs) looks like this:

native\git\
├── cmd\        git.exe, git-upload-pack.exe, git-receive-pack.exe, scalar.exe
├── etc\
├── ucrt64\
└── usr\
    ├── bin\    awk, cat, grep, ls, sed, ... and sh.exe   <-- no bash.exe
    └── ...
  • There is no bin\ directory at all, and dir /s /b ...\native\git\bash.exe finds nothing.
  • ...\native\git\usr\bin\sh.exe does exist (~2.4 MB).
  • The tool-process PATH that Codex builds adds ...\dependencies\native\git\cmd, but never ...\dependencies\native\git\usr\bin. So even the sh.exe that is shipped is invisible to which("sh").

Resolution consequences (codex-rs/shell-command/src/shell_detect.rs):

  • get_bash_shell() → which("bash"), then BASH_FALLBACK_PATHS = ["/bin/bash", "/usr/bin/bash"] (meaningless on Windows) → None.
  • get_sh_shell() → which("sh"), then SH_FALLBACK_PATHS = ["/bin/sh"] → on Windows that is a drive-relative path (<current-drive>:\bin\sh), which does not exist in practice → None.
  • get_shell_by_model_provided_path() then does .unwrap_or_else(ultimate_fallback_shell), and ultimate_fallback_shell() is cmd.exe on Windows — silently, with exit_code: 0.

So on a Windows machine without a user-installed Git, Codex has no POSIX shell at all, even though its own runtime ships the MSYS binaries and one is one directory away.

What steps can reproduce the bug?

  1. Install Codex Desktop on a Windows machine that does not have Git for Windows installed (or remove <Git>\bin from PATH), i.e. where bash returns nothing.

  2. Inspect the bundled runtime:

    dir /s /b "%LOCALAPPDATA%\..\..\.cache\codex-runtimes\codex-primary-runtime\dependencies\native\git\bash.exe"
    dir /b  "C:\Program Files\WindowsApps\OpenAI.CodexPrimaryRuntime.*\dependencies\native\git\usr\bin\sh.exe"
    

    → no bash.exe anywhere; sh.exe present.

  3. In Codex, ask the agent to run echo BASHOK; uname -s with shell: "bash" (or shell: "sh").

  4. Observed command event:

    {"type":"item.completed","item":{"id":"item_2","type":"command_execution",
     "command":"cmd.exe /c 'echo BASHOK; uname -s'",
     "aggregated_output":"BASHOK; uname -s\r\n","exit_code":0,"status":"completed"}}
    

    uname never ran; the tool result looks successful.

This also explains why a standard Git for Windows install does not help: the installer's default option adds only <Git>\cmd to PATH, while bash.exe lives in <Git>\bin (<Git>\cmd\bash.exe does not exist). The Windows-only C:\Program Files\Git\... fallbacks proposed in #40328 fix that specific layout, but not machines with no user Git, portable installs, or non-standard install roots.

What is the expected behavior?

Any one of these would close the gap:

  1. Ship a bash.exe in the runtime git (a copy/hardlink of usr\bin\sh.exe is enough for POSIX semantics — sh.exe is already MSYS bash), and/or add ...\dependencies\native\git\usr\bin to the tool PATH so which("sh") works.
  2. Add Windows fallback discovery based on the git Codex itself resolves: if which("git") is <X>\cmd\git.exe, also probe <X>\bin\bash.exe and <X>\usr\bin\bash.exe; and add the standard %ProgramFiles%\Git\... paths.
  3. Regardless of discovery, stop substituting cmd.exe silently: return a tool error the model can read (e.g. "shell bash is not available; found: powershell, cmd") instead of cmd.exe with exit_code: 0 (#40328).

Additional information

Related: #40328 (explicit Git Bash shell falls back to cmd.exe), #16579 (configurable default session shell). This report is only about the runtime/PATH side — the shipped runtime cannot supply a POSIX shell even to itself, independent of what the user has installed.

Security note: the existing behaviour that a model-provided path only selects the shell type and is never executed directly (#39607) should be preserved by any of the above — discovery would only ever use Codex's own resolved paths.

IndexEeve avatar Nov 21 '26 15:11 IndexEeve

is this expected that the Windows Bundled runtime ship a github with a bash.exe? sh.exe is more advanced why not just use that? what happen is that cmd.exe was used for you, when clearly sh.exe is a thing i recomend that you also check how sh is defined for example ""Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh).""" https://linux.die.net/man/1/sh what ever you tried to do didnt work because the lack of bash? are you trying to just make new git commits? there is https://cli.github.com/ also github-cli which works beautifully see https://cli.github.com/manual/ for example you can take your coding agents (for example codex and tell it [please use gh please see the latest pull requests ]) (critism i have on github i think they should allow some ratelimiting of visiting of the github pages because many users dont bother to sign in using github-cli )

JSON Fields
assignees, author, blockedBy, blocking, body, closed, closedAt, closedByPullRequestsReferences, comments, createdAt, id, isPinned, issueType, labels, milestone, number, parent, projectCards, projectItems, reactionGroups, state, stateReason, subIssues, subIssuesSummary, title, updatedAt, url

Examples
$ gh issue list --label "bug" --label "help wanted"
$ gh issue list --author monalisa
$ gh issue list --app dependabot
$ gh issue list --assignee "@me"
$ gh issue list --milestone "The big 1.0"
$ gh issue list --search "error no:assignee sort:created-asc"
$ gh issue list --state all
$ gh issue list --type Bug

you seems like an experimental users you might like NU https://www.nushell.sh/book/thinking_in_nu.html#but-it-s-not-bash which works fine on windows for me (as of evaluation i did on it)

also the codex app - is now available on Linux

if you are thinking of migrating from Windows to Linux - i recommend you use Linux Fedora (highly credited for being better than the issues that plagues Debian ) codex app works beautifully on linux too <3

glook9001 avatar Nov 23 '26 11:11 glook9001

Thanks — let me close the "why not just use sh.exe" question with concrete data, because it's the right question to ask and the answer is a bit surprising.

Scope note first: this report is not about git commits or gh. git and gh work fine on the affected machine; the bug is only about how exec_command resolves shell on Windows.

1. In Git for Windows, sh.exe is bash.exe

Not "more advanced" — literally the same binary. On a normal Git for Windows 2.55 install the two files are byte-identical:

bash.exe  2449886 bytes  SHA256 5490D0DA5E7CF9D92068CC48FCC590F2BCF8564ADD8FF91C3B5FE541EB2D72E3
sh.exe    2449886 bytes  SHA256 5490D0DA5E7CF9D92068CC48FCC590F2BCF8564ADD8FF91C3B5FE541EB2D72E3

The copy that ships in the Codex runtime behaves the same way:

> ...\dependencies\native\git\usr\bin\sh.exe -c 'echo "BASH_VERSION=$BASH_VERSION"; echo "0=$0"'
BASH_VERSION=5.3.15(2)-release
0=/usr/bin/sh

So Codex already has an sh shell type, and "switch to sh" does not dodge anything — it hits the same two blockers below.

2. What the bundled runtime actually contains

...\OpenAI.CodexPrimaryRuntime.v26-1117-835-0...\dependencies\native\git\:

cmd\        git.exe, git-receive-pack.exe, git-upload-pack.exe, scalar.exe
usr\bin\    82 files (57 exes): awk, cat, cp, cut, diff, echo, env, expr, find, grep,
            head, ls, mkdir, mktemp, mv, printf, pwd, rm, sed, sh, sort, ssh*, tail,
            test, touch, tr, uname, uniq, wc, xargs, ...
  • There is no bash.exe anywhere in the whole package (dir /s /b <pkg>\bash.exe → File Not Found), and no bin\ directory either.
  • tar.exe is absent too — this is a trimmed MSYS, not a full Git Bash.
  • So "just use sh.exe" means "use the one MSYS binary that happens to be spelled sh", which is exactly the file that is shipped and exactly the file that Codex cannot reach.

3. Two independent blockers — fixing only one does nothing

blocker evidence
A No bash.exe file name exists in the runtime, so which("bash") can never match it dir /s /b <pkg>\bash.exe → nothing
B usr\bin is never on the tool PATH, so which("sh") cannot match the file that does exist the PATH Codex assembles ends with ...\dependencies\native\git\cmd; there is no ...\native\git\usr\bin entry anywhere

Consequences:

  • Copying sh.exe → bash.exe inside usr\bin alone does not help (still not on PATH).
  • Adding usr\bin to PATH alone does not help either (nothing named bash, and SH_FALLBACK_PATHS = ["/bin/sh"] is a POSIX path that resolves to <current-drive>:\bin\sh on Windows).
  • Codex's own fallback lists are Unix-only — BASH_FALLBACK_PATHS = ["/bin/bash", "/usr/bin/bash"] — so no Windows location is ever probed.

4. Even the shipped sh.exe becomes a broken environment without PATH

Run directly, outside Codex, with usr\bin not on PATH:

> ...\native\git\usr\bin\sh.exe -c 'uname -s'
sh.exe: /usr/bin/sh: line 1: uname: command not found

uname.exe is sitting right next to sh.exe, but MSYS does not add its own directory to PATH for -c. So if the runtime's shell were ever wired in, usr\bin would have to be on PATH anyway for the coreutils to work. This is the same missing PATH entry as blocker B.

Meanwhile, on a machine that has Git installed, where sh resolves to ...\Git\bin\sh.exe (user install), never to the runtime copy — which is why bash works for people who installed Git and have <Git>\bin on PATH, and fails silently for everyone else.

5. Two tangents from the previous comment, for completeness

  • nushell: detect_shell_type() only recognises zsh, bash, sh, powershell, cmd. Any other shell name (nu, elvish, a full path to fish, …) is an unknown type and falls into the same cmd.exe fallback, so switching shells would trigger this bug rather than avoid it.
  • Linux/Fedora: not related to this report; the issue is Windows shell discovery in the bundled runtime.

6. Back to the fix

The three options in the report stand, and none of them requires shipping a full Git Bash:

  1. Ship/alias bash.exe and add usr\bin to PATH (both blockers).
  2. Probe paths instead of only which(): if which("git") = <X>\cmd\git.exe, also try <X>\bin\bash.exe and <X>\usr\bin\bash.exe; plus the standard %ProgramFiles%\Git\... locations. No new binaries.
  3. Return a tool error instead of silently using cmd.exe (tracked in #40328) — no new binaries, and it makes the remaining cases debuggable instead of "successful".

All of these keep the #39607 property that a model-provided path only selects the shell type and is never executed directly.

IndexEeve avatar Nov 23 '26 12:11 IndexEeve

Thanks — let me close the "why not just use sh.exe" question with concrete data, because it's the right question to ask and the answer is a bit surprising.

Scope note first: this report is not about git commits or gh. git and gh work fine on the affected machine; the bug is only about how exec_command resolves shell on Windows.

1. In Git for Windows, sh.exe is bash.exe

Not "more advanced" — literally the same binary. On a normal Git for Windows 2.55 install the two files are byte-identical:

bash.exe  2449886 bytes  SHA256 5490D0DA5E7CF9D92068CC48FCC590F2BCF8564ADD8FF91C3B5FE541EB2D72E3
sh.exe    2449886 bytes  SHA256 5490D0DA5E7CF9D92068CC48FCC590F2BCF8564ADD8FF91C3B5FE541EB2D72E3

The copy that ships in the Codex runtime behaves the same way:

> ...\dependencies\native\git\usr\bin\sh.exe -c 'echo "BASH_VERSION=$BASH_VERSION"; echo "0=$0"'
BASH_VERSION=5.3.15(2)-release
0=/usr/bin/sh

So Codex already has an sh shell type, and "switch to sh" does not dodge anything — it hits the same two blockers below.

2. What the bundled runtime actually contains

...\OpenAI.CodexPrimaryRuntime.v26-1117-835-0...\dependencies\native\git\:

cmd\        git.exe, git-receive-pack.exe, git-upload-pack.exe, scalar.exe
usr\bin\    82 files (57 exes): awk, cat, cp, cut, diff, echo, env, expr, find, grep,
            head, ls, mkdir, mktemp, mv, printf, pwd, rm, sed, sh, sort, ssh*, tail,
            test, touch, tr, uname, uniq, wc, xargs, ...
  • There is no bash.exe anywhere in the whole package (dir /s /b <pkg>\bash.exe → File Not Found), and no bin\ directory either.
  • tar.exe is absent too — this is a trimmed MSYS, not a full Git Bash.
  • So "just use sh.exe" means "use the one MSYS binary that happens to be spelled sh", which is exactly the file that is shipped and exactly the file that Codex cannot reach.

3. Two independent blockers — fixing only one does nothing

blocker evidence A No bash.exe file name exists in the runtime, so which("bash") can never match it dir /s /b <pkg>\bash.exe → nothing B usr\bin is never on the tool PATH, so which("sh") cannot match the file that does exist the PATH Codex assembles ends with ...\dependencies\native\git\cmd; there is no ...\native\git\usr\bin entry anywhere Consequences:

  • Copying sh.exe → bash.exe inside usr\bin alone does not help (still not on PATH).
  • Adding usr\bin to PATH alone does not help either (nothing named bash, and SH_FALLBACK_PATHS = ["/bin/sh"] is a POSIX path that resolves to <current-drive>:\bin\sh on Windows).
  • Codex's own fallback lists are Unix-only — BASH_FALLBACK_PATHS = ["/bin/bash", "/usr/bin/bash"] — so no Windows location is ever probed.

4. Even the shipped sh.exe becomes a broken environment without PATH

Run directly, outside Codex, with usr\bin not on PATH:

> ...\native\git\usr\bin\sh.exe -c 'uname -s'
sh.exe: /usr/bin/sh: line 1: uname: command not found

uname.exe is sitting right next to sh.exe, but MSYS does not add its own directory to PATH for -c. So if the runtime's shell were ever wired in, usr\bin would have to be on PATH anyway for the coreutils to work. This is the same missing PATH entry as blocker B.

Meanwhile, on a machine that has Git installed, where sh resolves to ...\Git\bin\sh.exe (user install), never to the runtime copy — which is why bash works for people who installed Git and have <Git>\bin on PATH, and fails silently for everyone else.

5. Two tangents from the previous comment, for completeness

  • nushell: detect_shell_type() only recognises zsh, bash, sh, powershell, cmd. Any other shell name (nu, elvish, a full path to fish, …) is an unknown type and falls into the same cmd.exe fallback, so switching shells would trigger this bug rather than avoid it.
  • Linux/Fedora: not related to this report; the issue is Windows shell discovery in the bundled runtime.

6. Back to the fix

The three options in the report stand, and none of them requires shipping a full Git Bash:

  1. Ship/alias bash.exe and add usr\bin to PATH (both blockers).
  2. Probe paths instead of only which(): if which("git") = <X>\cmd\git.exe, also try <X>\bin\bash.exe and <X>\usr\bin\bash.exe; plus the standard %ProgramFiles%\Git\... locations. No new binaries.
  3. Return a tool error instead of silently using cmd.exe (tracked in Windows regression: explicit Git Bash exec_command.shell falls back to cmd.exe #40328) — no new binaries, and it makes the remaining cases debuggable instead of "successful".

All of these keep the #39607 property that a model-provided path only selects the shell type and is never executed directly.

you dont need bash, you got powershell,,,,,

glook9001 avatar Nov 23 '26 13:11 glook9001

maybe it doesnt uses powershell- which is an incorrect behavior...

glook9001 avatar Nov 23 '26 13:11 glook9001

PowerShell isn't the problem — shell: "powershell" works and I use it. bash/sh are wanted because Codex is POSIX-first (-lc login shells, rg/sed/awk, heredocs), and some tasks need POSIX semantics that PowerShell doesn't provide.

The bug is the silent substitution: an unresolvable bash runs under cmd.exe and returns exit_code: 0, so the model spends an extra round-trip discovering the command did nothing — 2 model calls, 2× latency and a polluted context for a single step.

Measured on one Windows machine: 104 bash requests in a single session, all executed by cmd.exe; after making bash resolvable, 714/714 ran in bash.exe and cmd.exe usage dropped to 0. That duplicated round-trip per bash step is the actual cost — not the choice of shell.

IndexEeve avatar Nov 23 '26 14:11 IndexEeve

PowerShell isn't the problem — shell: "powershell" works and I use it. bash/sh are wanted because Codex is POSIX-first (-lc login shells, rg/sed/awk, heredocs), and some tasks need POSIX semantics that PowerShell doesn't provide.

The bug is the silent substitution: an unresolvable bash runs under cmd.exe and returns exit_code: 0, so the model spends an extra round-trip discovering the command did nothing — 2 model calls, 2× latency and a polluted context for a single step.

Measured on one Windows machine: 104 bash requests in a single session, all executed by cmd.exe; after making bash resolvable, 714/714 ran in bash.exe and cmd.exe usage dropped to 0. That duplicated round-trip per bash step is the actual cost — not the choice of shell.

why not use linux? Doesnt it have the Codex App?

how did you came to having this issue in the first place

glook9001 avatar Nov 23 '26 14:11 glook9001

The bug is the silent substitution: an unresolvable bash runs under cmd.exe and returns exit_code: 0, so the model spends an extraround-trip discovering the command did nothing — 2 model calls, 2× latency and a polluted context for a single step.

surely if it discovers it cant do something - it adopt for the rest of the session?

glook9001 avatar Nov 23 '26 14:11 glook9001

I'm developing a Windows-only app,that's why I don't use Linux.

I encountered this bug the first time I opened codex,maybe due to my computer's chaos environment.

Then I asked another agent to fix it and discovered this bug.

When it fallback to cmd.exe,the model may keep using it but try bash again after several commands.

Thanks for your caring.I hope my response could answer your questions.

IndexEeve avatar Nov 23 '26 14:11 IndexEeve