Skip to content

fix: codepage-safe agent binary resolution on non-English Windows#528

Merged
zomux merged 2 commits into
developfrom
hotfix/launcher-path
Jun 29, 2026
Merged

fix: codepage-safe agent binary resolution on non-English Windows#528
zomux merged 2 commits into
developfrom
hotfix/launcher-path

Conversation

@Ashin-LX-98

Copy link
Copy Markdown
Collaborator

On a non-English Windows (e.g. GBK/936 console codepage), execSync decoded where/which stdout with the wrong codepage, mangling a non-ASCII (Chinese) username in the path into garbage like
C:\Users\??.?[\AppData\Roaming\npm\claude.cmd and producing an ENOENT when the agent tried to run. Adapters also returned the unverified hit directly, and codex/gemini returned an empty string on a miss that short-circuited the Node-derived fallback tiers.

  • paths.js: add whereBinary() (chcp 65001 forces UTF-8 where output + fs.existsSync guard) and harden whichBinary() the same way.
  • Route every CLI adapter (claude/cline/codex/copilot/cursor/hermes/opencode/ gemini, plus claude's openagents MCP lookup) through whereBinary so a mangled path is rejected and resolution falls through to Node-derived (APPDATA/ homedir, correctly-encoded) tiers.
  • Bump to 0.2.144.

On a non-English Windows (e.g. GBK/936 console codepage), execSync decoded
`where`/`which` stdout with the wrong codepage, mangling a non-ASCII (Chinese)
username in the path into garbage like
`C:\Users\??.?[\AppData\Roaming\npm\claude.cmd` and producing an ENOENT when
the agent tried to run. Adapters also returned the unverified hit directly,
and codex/gemini returned an empty string on a miss that short-circuited the
Node-derived fallback tiers.

- paths.js: add whereBinary() (chcp 65001 forces UTF-8 `where` output +
  fs.existsSync guard) and harden whichBinary() the same way.
- Route every CLI adapter (claude/cline/codex/copilot/cursor/hermes/opencode/
  gemini, plus claude's openagents MCP lookup) through whereBinary so a mangled
  path is rejected and resolution falls through to Node-derived (APPDATA/
  homedir, correctly-encoded) tiers.
- Bump to 0.2.144.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openagents-workspace Ready Ready Preview, Comment Jun 29, 2026 3:31am

Request Review

@Ashin-LX-98
Ashin-LX-98 requested a review from nebukaga June 29, 2026 03:16
The previous commit prefixed the Windows `where` lookup with `chcp 65001` to
force UTF-8 output. Under `windowsHide: true` cmd runs console-less
(CREATE_NO_WINDOW), where `chcp` can fail with an invalid-handle error — and
because it was chained with `&&`, that failure would make EVERY binary lookup
return null on Windows (no agent resolvable). The CI windows matrix cells
caught this.

Replace it with a strictly-safer scheme that needs no codepage juggling:
- whereBinary: check `%APPDATA%\npm\<name>.cmd` FIRST (APPDATA is UTF-16 from
  the OS via Node — always correctly encoded, and where npm-global CLIs live),
  then fall back to an existence-guarded `where`/`which`.
- whichBinary: keep the existsSync guard, drop the chcp prefix.

A mangled non-ASCII path still fails existsSync and the caller falls through to
its Node-derived tiers, so the original `C:\Users\<中文>\…\claude.cmd` ENOENT
stays fixed without risking the common case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@zomux zomux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound codepage fix — checks %APPDATA%\npm shim first (UTF-16-safe) + existence-guards every 'where' hit so a mangled path fails safe. Spawn safety preserved (only the lookup tier centralized; adapters keep their own .cmd/cmd.exe handling). Also fixes a latent codex/gemini enriched-env bug. Nit: add a unit test for whereBinary. LGTM.

@zomux
zomux merged commit 7032ed9 into develop Jun 29, 2026
4 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants