Windows native mode fails with "batch file arguments are invalid" when pwsh resolves to a .cmd shim

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

Summary

On Codex Desktop for Windows, all agent commands can fail before execution with:

execution error: Io(Error { kind: InvalidInput, message: "batch file arguments are invalid" })

Environment

  • Codex Desktop (Microsoft Store): 26.306.996.0
  • Windows: 10.0.26200.7922
  • Integrated terminal shell: PowerShell 7.5.4
  • Agent mode: Windows native

What happened

Even trivial commands failed:

  • Write-Output hi
  • Get-Location
  • git status -sb
  • cmd.exe /c echo hi

The integrated terminal still appeared normal, which made this hard to diagnose.

Trigger / likely root cause

In this setup, pwsh resolved from PATH to a batch wrapper instead of the real pwsh.exe, e.g.:

C:\Users\...\AppData\Local\Programs\Python\Python313\Scripts\pwsh.cmd

Contents:

@echo off
"C:\Program Files\PowerShell\7\pwsh.exe" %*

Codex's Windows command runner appears to reject this .cmd shim when arguments are passed through it, and fails before the target command starts.

Why I think this is the trigger

  • All commands failed with the exact same error, including cmd.exe /c echo hi
  • Renaming/removing the pwsh.cmd shim fixed the issue immediately
  • Moving C:\Program Files\PowerShell\7\ earlier in PATH also fixed it
  • A patched desktop copy using newer Codex binaries still reproduced the same failure, so this did not look like a simple bundled-version mismatch

Possible repro

  1. Put a pwsh.cmd wrapper earlier in PATH than the real pwsh.exe
  2. Launch Codex Desktop on Windows in Windows native mode with PowerShell
  3. Run any agent command
  4. Observe batch file arguments are invalid

Suggested handling

It would help if Codex on Windows either:

  1. resolved pwsh.exe directly instead of accepting a .cmd shim from PATH, or
  2. surfaced a more actionable error when pwsh resolves to .cmd / .bat

Workaround

Ensure where pwsh resolves to the real pwsh.exe, not a batch wrapper.

Optional longer write-up (just as a debugging archive, not promotion):
https://aiya.de5.net/t/topic/119/1

View original on GitHub ↗

3 Comments

github-actions[bot] contributor · 5 months ago

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

  • #13840
  • #14221
  • #13340

Powered by Codex Action

CircuitCM · 5 months ago

I am running into the same issue. I have pwsh.cmd however I use this start config:
"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NonInteractive -NoProfileLoadTime
I also use tty: false.

All of these together let me remove the artificial line breaks and ANSI color codes that mess up the formatting of my scripts and act as noise. In the CLI I was able to get around this by calling my pwsh.cmd first, then calling codex. But now that I want to use the app there doesn't seem to be a simple workaround. I am also getting Failed to create unified exec process: batch file arguments are invalid when codex tries exec_command.

Is there any chance we can get support for launch scripts in addition to the executables?
<img width="746" height="482" alt="Image" src="https://github.com/user-attachments/assets/9a86220a-3def-450f-8261-fc8e6139fd0a" />

PatrickSys · 18 days ago

Confirming a current Windows Codex Desktop reproduction of the same pre-execution failure.

Environment:

  • Windows 11 Pro, x64, build 10.0.26200
  • Codex Desktop/app version: unavailable from the affected task
  • Bundled CLI version: unknown
  • Filesystem profile: unrestricted / danger-full-access
  • Approval policy: never

Reproduction matrix:

| Parent functions.shell_command call | Result |
|---|---|
| Get-Location | fails before execution |
| pwd, with login:false | same failure |
| git status --short | same failure |
| Other parent shell_command calls | same failure |

Actual error:

Script error:
execution error: Io(Error { kind: InvalidInput, message: "batch file arguments are invalid" })

Expected behavior: trivial commands should execute and return output, regardless of login mode or permission profile.

In the same task, Node REPL and a delegated subagent shell still work. This suggests the failure is isolated to the parent Desktop shell_command bridge rather than a general inability to execute commands on the host. login:false does not change the result.

Temporary workaround: use the delegated subagent shell or Node REPL. I could not verify local PowerShell PATH resolution because the failing bridge prevents that check.