Skip to content

Fix Windows launch for npm-installed agents - #676

Open
ozakidai wants to merge 1 commit into
databricks:mainfrom
ozakidai:fix/windows-command-resolution
Open

ozakidai wants to merge 1 commit into
databricks:mainfrom
ozakidai:fix/windows-command-resolution

Conversation

@ozakidai

@ozakidai ozakidai commented Sep 16, 2026

Copy link
Copy Markdown

Summary

Resolve agent executables with shutil.which before launching them with subprocess.Popen on Windows.

Windows CreateProcess does not apply PATHEXT to bare command names. As a result, npm-installed agents such as claude.cmd can be available on PATH but still fail to launch with FileNotFoundError.

The POSIX launch path remains unchanged. If executable resolution fails, the original command name is preserved.

Reproduction

On Windows, install Claude Code through npm:

npm install -g @anthropic-ai/claude-code
where.exe claude

where.exe finds the npm-installed claude.cmd, confirming that Claude Code is available on PATH.

Before this change, launching it through Unity Gateway fails:

ug claude -- --version
FileNotFoundError: [WinError 2] The system cannot find the file specified

After this change, the same command succeeds:

2.1.273 (Claude Code)

Changes

  • Resolve the agent command with shutil.which on Windows before passing it to subprocess.Popen.
  • Preserve the original arguments and existing fallback behavior.
  • Add a regression test covering an npm-style .cmd executable.

Validation environment

  • Amazon EC2 running Microsoft Windows Server 2022 Datacenter, version 10.0.20348, build 20348
  • Unity Gateway CLI 0.0.0+1.gf26daf3
  • Python 3.12.14
  • uv 0.12.15
  • Claude Code 2.1.273, installed through npm

Testing

uv run pytest --basetemp=/private/tmp/unity-gateway-pytest-full-676 -q
2264 passed, 46 skipped, 1 warning

uv run ruff check .
All checks passed

uv run ruff format --check src/ucode/launcher.py tests/test_launcher.py
2 files already formatted

A short pytest base directory was used to avoid the macOS AF_UNIX socket path length limit.

The change was also validated on Windows Server. Both the Claude Code launch and a real request through the gateway completed successfully.

This pull request addresses the agent launch path only. Other subprocess call sites described in the related issues are outside its scope.

Related to #185 and #247.

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.

1 participant