Skip to content

fix(cli): parse where output on Windows to prefer .cmd/.exe wrappers - #969

Merged
diegosouzapw merged 2 commits into
cheaper-inference:mainfrom
razllivan:fix/windows-cli-where-parsing
Apr 3, 2026
Merged

diegosouzapw merged 2 commits into
cheaper-inference:mainfrom
razllivan:fix/windows-cli-where-parsing

Conversation

@razllivan

Copy link
Copy Markdown
Contributor

Summary

  • Parse where output on Windows to prefer .cmd/.exe wrappers instead of returning the bare command name
  • Fixes healthcheck failures for npm-installed CLI tools (OpenClaw, OpenCode) on Windows

Root Cause

The fix from #863/#935 added PATHEXT and ComSpec to the minimalEnv in checkRunnable, which was necessary but not sufficient. The real bug is upstream in locateCommand — it runs where <command> on Windows but ignores the output, returning commandPath: command (bare name like "opencode").

On Windows, npm global installs create two files:

  1. opencode — Unix shell script (#!/bin/sh), not runnable on Windows
  2. opencode.cmd — Windows batch wrapper, the correct executable

where opencode returns both. Since the code never parsed the output, the healthcheck tried to run the bare name, which resolved to the Unix script first → healthcheck_failed.

Claude Code (where claude → single claude.exe) was unaffected.

Fix

Parse where output line-by-line and prefer paths with Windows executable extensions (.cmd, .exe, .bat, .com). Falls back to the first line if none match.

Validation

  • Verified where opencode returns two lines on Windows; fix selects .cmd
  • Verified where claude returns single .exe; no change in behavior
  • npm run lint — passes
  • Pre-existing test failure (auth-clear-provider-routes.test.mjs — missing yazl) is unrelated to this change

Related

The locateCommand function returned the bare command name instead of
parsing the where output. On Windows, npm global installs create both
a Unix shell script (no extension) and a .cmd wrapper. where returns
both, and the bare name resolves to the Unix script first, causing
healthcheck failures for OpenClaw and OpenCode.

Fix: parse where output and prefer paths with Windows executable
extensions (.cmd, .exe, .bat, .com).

Related: cheaper-inference#935, cheaper-inference#863

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request improves command location on Windows by parsing multiple results from the where command and prioritizing executable extensions like .cmd or .exe. Review feedback identifies a potential undefined return value if the command output is empty, a command injection vulnerability from unsafe paths in the environment, and the need to normalize MSYS2-style paths.

Comment thread src/shared/services/cliRuntime.ts Resolved
@diegosouzapw
diegosouzapw merged commit 2a8b155 into cheaper-inference:main Apr 3, 2026
1 check passed
@diegosouzapw diegosouzapw mentioned this pull request Apr 22, 2026
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.

[BUG] NPM-installed CLI tools still fail healthcheck on Windows — locateCommand ignores where output

2 participants