If you have ever tried to launch OpenAI's Codex CLI on Windows only to be greeted by the cryptic error "%1 is not a valid Win32 application," you are not alone. This issue, which plagued users of Hermes IDE version 2.3.4, stems from how npm handles global package installations on Windows. On November 1, a user reported that while codex.cmd --version worked perfectly, launching the agent via Hermes failed with OS error 193. The root cause was not a broken installation, but rather a launcher that selected the wrong file from a trio of scripts created by npm's cmd-shim utility.
The Three-File Problem
When you install @openai/codex globally on Windows, npm does not create a simple executable. Instead, it uses cmd-shim to generate three distinct files in your global npm directory (typically %AppData%\npm): codex (an extensionless shell script), codex.cmd (a batch file), and codex.ps1 (a PowerShell script). Each file is designed for a different execution environment. The extensionless codex file is intended for Unix-like shells on Windows (like Cygwin or WSL), while codex.cmd is meant for the native Windows command prompt. The Hermes launcher, however, was prioritizing the extensionless file, which Windows' CreateProcess API cannot execute directly because it lacks a PE signature.
Why Error 193 Happens
Error 193, technically known as ERROR_BAD_EXE_FORMAT, occurs when the Windows API tries to load a file that isn't a valid Win32 executable. The extensionless codex file begins with a shebang (#!/bin/sh), which CreateProcess ignores. Since the file is essentially a text script, Windows rejects it. This highlights a critical difference in how Unix and Windows handle executables: on Unix, the lack of an extension often signifies the primary executable, whereas on Windows, the extension (like .exe, .cmd, or .bat) is crucial for the OS to determine how to run the file. Other tools, such as Emdash and WezTerm, have faced similar issues where their process discovery mechanisms favored the literal name over the PATHEXT environment variable search order.
The Fix in Hermes 2.3.5
Hermes IDE version 2.3.5, released on November 6, resolved this by altering the binary resolution logic. The fix ensures that on Windows, a command name is only accepted as-is if it already ends with a valid PATHEXT extension. If the name is bare, the launcher now explicitly searches for codex.cmd (or other valid extensions) before falling back. This change prevents the launcher from ever handing the extensionless shim to CreateProcess. The update also includes a specific test case in CI to ensure that codex resolves to codex.cmd and that removing the .cmd file results in a proper failure rather than a cryptic OS error.
Key Takeaways
- npm creates three shim files (
codex,codex.cmd,codex.ps1) for global packages on Windows, each for different shells. - The extensionless shim is a text file that
CreateProcesscannot execute, causing Error 193. - Launchers must prioritize
PATHEXTextensions (like.cmd) over bare names on Windows. - Hermes 2.3.5 fixed this by rejecting bare names unless they match a valid Windows executable extension.
- Running
nodedirectly on the package script (e.g.,node bin/codex.js) is often the most robust way to avoid shim issues.
The Bottom Line
This bug serves as a stark reminder that Windows and Unix have fundamentally different execution models. If you are building a launcher or agent manager, never assume a bare command name is executable on Windows; always respect PATHEXT.