Skip to content

fix(agents): npm-installed Claude CLI fails to launch on Windows - #138504

Merged
obviyus merged 7 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-138424-claude-cli-win-spawn-path
Sep 19, 2026
Merged

obviyus merged 7 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-138424-claude-cli-win-spawn-path

Conversation

@LiuwqGit

@LiuwqGit LiuwqGit commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #138424

What Problem This Solves

Fixes ordinary claude-cli agent turns failing to launch on Windows when an npm installation exposes an extensionless shell shim or a .cmd launcher.

User Impact

Windows users can complete Claude CLI turns through their npm-installed command without replacing launcher files. Native executables and non-Windows command handling are preserved. No configuration, authentication, or identity-verification policy changes are required.

Why This Change Was Made

The earlier implementation targeted the Agent SDK adapter removed by #138707. This revision preserves the contributor's commits while applying the repair to the current direct CLI transport. Its launch boundary now uses the existing shared Windows resolver and carries the resolved program together with its leading arguments. Relative commands and PATH entries are resolved against the child working directory; existing identity callers retain their previous behavior.

Evidence

The supported agent --local --session-id <fresh> --message "Reply with exactly PONG" --json --timeout 60 path was exercised on real GitHub-hosted Windows 2025 with Node 24.20.0, isolated OpenClaw state, an npm-style prefix, and a controlled external CLI speaking the Anthropic transport protocol. No auth-binding callback or exact-version policy normalized the command first; no platform mock or live provider credential was used.

Actual Windows launch Unchanged main production Candidate production
Extensionless shim plus npm .cmd write EPIPE, no run child or reply Run child launched; final reply PONG
npm .cmd resolving to Node plus script spawn EINVAL, no run child or reply Node and script argument preserved; final reply PONG
Native .exe control Final reply PONG Final reply PONG
  • Baseline run: production from 7a932d979442, proof ref 381771f2ca50.
  • Candidate run: e9f91d13d7e3, with the same three fixtures and order. All three product cases passed. Publication head 7f7212ac7e6b changes only the fixture's filesystem-error typing, not production or executable fixture bytes.
  • A macOS npm-shim control also completed with PONG. Focused local checks passed 75 tests, with the native-only case skipped; scoped lint passed.
  • Follow-up 283bcaa addresses the review's home-relative finding: the cwd-aware Windows lookup now expands the effective home before resolving, so a plugin command like ~/bin/tool.exe keeps launching. The new plugin-runner regression (execute-plugin.windows-home-relative.test.ts) failed with CLI backend executable could not be resolved: ~/bin/tool.js before the change; after it, the same ordinary plugin turn spawns the resolved Node program from the effective home and completes with the child's reply. The full focused suite (38 tests), scoped lint, tsgo:core, and the agents-other test-type shard all pass locally; ordinary exact-head PR CI remains the wider validation gate.
  • The candidate Windows workflow is not wholly green: three later executable-identity tests failed with expected undefined to be package-tree. The baseline stopped before those cases, so this is not claimed as reproduced base-red. Their two-argument resolver calls retain exactly the previous behavior, run outside the changed execution owner, and execute in separate test processes. The identity guards and assertions remain intact.

This proves the real OpenClaw command, Windows process launch, direct transport, and final reply boundary with a controlled CLI peer. It does not claim live Anthropic authentication/model traffic, pnpm launcher coverage, or Windows resume-session coverage. Ordinary exact-head PR CI remains the wider validation gate.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 19, 2026, 6:12 AM ET / 10:12 UTC (Revision 5).

ClawSweeper review

What this changes

Resolves Windows CLI launchers through the shared executable resolver, preserves Node script arguments, and adds ordinary-agent launch coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

The Windows launch repair remains necessary and addresses the previous review, but the revised resolution order introduces a home-relative command regression.

Priority: P1
Reviewed head: 7f7212ac7e6b2511673ce1231ffedfc30de8103a

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong Windows boundary proof supports the central repair, but a concrete executable-path compatibility regression blocks merge.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied Windows before/after evidence exercises the changed shared runner through ordinary agent commands, real subprocess I/O, and the Anthropic transport, observing PONG for both repaired npm launch shapes and the native control. The publication commit preserves those production bytes. The log-download restriction is a reviewer limitation, not missing contributor proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The supplied Windows before/after evidence exercises the changed shared runner through ordinary agent commands, real subprocess I/O, and the Anthropic transport, observing PONG for both repaired npm launch shapes and the native control. The publication commit preserves those production bytes. The log-download restriction is a reviewer limitation, not missing contributor proof.
Evidence reviewed 9 items Introduced regression: The new Windows lookup receives the raw command and child cwd before generic executable normalization. Its path.resolve call turns ~/bin/tool.exe into a workspace-relative literal tilde path, preventing subsequent home expansion.
Existing home-relative contract: resolveExecutablePathCandidate expands a leading tilde before resolving relative paths. Existing executable-path coverage explicitly requires home-relative commands to resolve, and plugin backend command preparation only trims the registered command.
Still necessary on main and latest release: Both fetched main and v2026.9.5 retain the generic-only lookup in the plugin execution owner; neither includes this Windows launcher normalization.
Findings 1 actionable finding [P1] [P1] Expand home-relative commands before Windows cwd resolution
Security None None.

How this fits together

The shared CLI runner prepares executable commands for plugin-owned agent transports. The Anthropic plugin launches the resulting process and returns its streamed response to OpenClaw.

flowchart LR
  A[Agent request] --> B[Shared CLI runner]
  B --> C[Windows executable lookup]
  C --> D[Executable and script arguments]
  D --> E[Anthropic process transport]
  E --> F[Agent reply]
Loading

Before merge

  • [P1] Expand home-relative commands before Windows cwd resolution (P1) - For a plugin backend whose command is ~/bin/tool.exe, an ordinary Windows turn now passes that raw string to the Windows resolver with a cwd. The new path.resolve(cwd, command) produces &lt;workspace>\~\bin\tool.exe, so resolveExecutablePath never sees the leading tilde and throws even when the executable exists under HOME. Previously this owner called the generic resolver directly, which expands home prefixes; that behavior also has existing coverage in executable-path.test.ts. Preserve that normalization before the Windows lookup and cover it through the plugin execution path.
  • Resolve merge risk (P1) - Existing plugin backends using home-relative executable paths can stop launching on Windows after merging this resolution order.
  • Resolve merge risk (P1) - The supplied candidate workflow reports three later executable-identity failures; their cause is not established as a regression from this diff.
  • Complete next step (P2) - Preserve home-relative executable paths before Windows cwd resolution and add regression coverage through the plugin runner.

Findings

  • [P1] [P1] Expand home-relative commands before Windows cwd resolution — src/agents/cli-runner/execute-plugin.ts:443-447
Agent review details

Security

None.

PR surface

Source +25, Tests +355. Total +380 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 32 7 +25
Tests 3 356 1 +355
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 388 8 +380

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +25 lines; tests and support net +355 lines Production growth reuses the existing resolver; most added code supplies actual process-launch regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138424
Summary: This PR remains a candidate repair for the reported Windows Claude CLI launch failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Preserve home-relative executable resolution (recommended)
    Normalize the home prefix before Windows cwd resolution and add a regression through the plugin runner.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve home-relative plugin executable paths before Windows cwd resolution using the existing home-normalization owner; add a failing-before/passing-after runner regression without weakening npm shim, argument, or identity coverage.

Technical review

Best possible solution:

Retain the shared Windows launcher repair while preserving existing home expansion and proving compatibility through the plugin execution boundary.

Do we have a high-confidence way to reproduce the issue?

Yes: source establishes the Windows launcher failure and the introduced home-relative path regression; the supplied native Windows runs demonstrate the original launch failure and repair. No tests were executed during this read-only review.

Is this the best way to solve the issue?

The shared-resolver approach is appropriate, but the current ordering must preserve home expansion before converting relative commands into absolute paths.

Full review comments:

  • [P1] [P1] Expand home-relative commands before Windows cwd resolution — src/agents/cli-runner/execute-plugin.ts:443-447
    For a plugin backend whose command is ~/bin/tool.exe, an ordinary Windows turn now passes that raw string to the Windows resolver with a cwd. The new path.resolve(cwd, command) produces &lt;workspace>\~\bin\tool.exe, so resolveExecutablePath never sees the leading tilde and throws even when the executable exists under HOME. Previously this owner called the generic resolver directly, which expands home prefixes; that behavior also has existing coverage in executable-path.test.ts. Preserve that normalization before the Windows lookup and cover it through the plugin execution path.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fba076b49e53.

Labels

Label justifications:

  • P1: The PR repairs an established Windows Claude CLI workflow that cannot complete ordinary agent turns.
  • merge-risk: 🚨 compatibility: The new lookup order breaks previously supported home-relative executable paths in plugin-owned Windows turns.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (linked_artifact): The supplied Windows before/after evidence exercises the changed shared runner through ordinary agent commands, real subprocess I/O, and the Anthropic transport, observing PONG for both repaired npm launch shapes and the native control. The publication commit preserves those production bytes. The log-download restriction is a reviewer limitation, not missing contributor proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Windows before/after evidence exercises the changed shared runner through ordinary agent commands, real subprocess I/O, and the Anthropic transport, observing PONG for both repaired npm launch shapes and the native control. The publication commit preserves those production bytes. The log-download restriction is a reviewer limitation, not missing contributor proof.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/infra/executable-path.test.ts src/plugin-sdk/windows-spawn.test.ts src/agents/cli-runner/execute.executable-invocation.test.ts.
  • [P1] node scripts/run-vitest.mjs src/process/exec.windows.integration.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Preserve home-relative command expansion and demonstrate a failing-before/passing-after Windows plugin-runner regression.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-04T19:04:30.901Z sha da87a6555b3cf8c84d9e480c3985a387daabd688 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-04T19:57:02.815Z sha da87a6555b3cf8c84d9e480c3985a387daabd688 :: needs real behavior proof before merge. :: [P2] Preserve the Node interpreter for JS entrypoints
  • reviewed 2026-09-04T20:50:09.713Z sha fdcde1b :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-05T08:54:35.590Z sha fdcde1b :: blocked before merge. :: none

@LiuwqGit
LiuwqGit force-pushed the feat/issue-138424-claude-cli-win-spawn-path branch from da87a65 to cc1abcf Compare September 4, 2026 20:12
The claude-cli backend handed the Agent SDK the host-prepared command, which
on Windows is the bare command or npm's extensionless POSIX shim. The SDK
spawns pathToClaudeCodeExecutable directly, so Windows launches failed with
ENOENT or EINVAL. Resolve the command through the same PATH/PATHEXT and
wrapper-entrypoint resolution the CLI identity layer uses, yielding the
package's native claude.exe entrypoint; other platforms are unchanged.

Fixes openclaw#138424
@LiuwqGit
LiuwqGit force-pushed the feat/issue-138424-claude-cli-win-spawn-path branch from cc1abcf to fdcde1b Compare September 4, 2026 20:19
@LiuwqGit

LiuwqGit commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Real Windows behavior proof added to the PR body (Evidence section): on a Windows host (10.0.17763 x64, Node v24.19.0) with the reporter's npm-global layout (npm i -g @anthropic-ai/[email protected]: extensionless claude shim + claude.cmd in the prefix, native bin/claude.exe in the package), the pre-fix code reproduces the issue's exact failure (Claude Code native binary at D:\Programs\nvm\node_global\claude exists but failed to launch, no CLI process spawned), and PR head fdcde1b completes a real Agent SDK / Claude CLI turn (cli turn ... outBytes=4 outHash=95784973cc63 = sha256("PONG") prefix; CLI-side session transcript records the prompt and the PONG reply). Model traffic used the host CLI's configured endpoint (no Anthropic OAuth credentials on this host); the spawn/launch path under test is endpoint-independent. Limitations are stated in the body.

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 5, 2026
@obviyus
obviyus requested review from a team as code owners September 19, 2026 10:03
@obviyus obviyus changed the title fix(anthropic): claude-cli backend cannot launch the Claude CLI on Windows fix(agents): npm-installed Claude CLI fails to launch on Windows Sep 19, 2026
@obviyus obviyus closed this Sep 19, 2026
@obviyus obviyus reopened this Sep 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling and removed extensions: anthropic labels Sep 19, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 19, 2026
@obviyus

obviyus commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-unrelated-red
pr: 138504
head: 7f7212a
run: 35436411308 attempt: 1
failed: checks-windows-node-test-2 job=105879974923 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit 3039685 into openclaw:main Sep 19, 2026
256 of 320 checks passed
@obviyus

obviyus commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Merged as 3039685. Thanks @LiuwqGit for the report, original repair, and Windows evidence.

The fix now lives at the current direct CLI launch boundary and preserves the resolved executable plus leading arguments. Real Windows agent --local runs reproduced the npm shim/.cmd failures before the fix and returned PONG afterward; the native-executable and macOS controls also passed, using a controlled CLI peer rather than live model traffic.

Exact-head review passed with no findings. PR CI completed with 149 successful jobs; its sole failed source job was an independently attributed skills-watcher timeout, documented in the landing approval. The separate Windows proof workflow's three identity-test failures remain disclosed in the PR body; no identity guard or assertion was weakened.

@LiuwqGit

Copy link
Copy Markdown
Contributor Author

Addressing the review's P1 finding (home-relative commands before Windows cwd resolution) in follow-up commit 283bcaa:

  • Fix: executePluginOwnedProcess now expands the effective home prefix (expandHomePrefix) before handing the command to the cwd-aware Windows resolver, so ~/bin/tool.exe no longer becomes a workspace-relative literal tilde path that resolveExecutablePath cannot expand. Two-argument resolver calls and non-Windows paths are unchanged.
  • Regression through the plugin execution path: src/agents/cli-runner/execute-plugin.windows-home-relative.test.ts drives executePluginOwnedProcess (Windows platform mocked on a POSIX host) with ~/bin/tool.js, an isolated HOME, a workspace cwd, and a real child process. Before the change it fails with CLI backend executable could not be resolved: ~/bin/tool.js; after it, the resolved Node program spawns from the effective home and the child's reply completes the turn.
  • Local verification: RED→GREEN as above; focused suite (38 tests) green; scoped oxfmt/oxlint clean; tsgo:core and the agents-other test-type shard pass. The failing checks-windows-node-test-2 job on the previous head was the unrelated src/skills/runtime/refresh.missing-root.integration.test.ts timeout (none of this PR's five files are involved), consistent with the landpr-approve-unrelated-red note; exact-head PR CI remains the wider gate.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 20, 2026
…nclaw#138504)

Closes openclaw#138424

## What Problem This Solves

Fixes ordinary `claude-cli` agent turns failing to launch on Windows when an npm installation exposes an extensionless shell shim or a `.cmd` launcher.

## User Impact

Windows users can complete Claude CLI turns through their npm-installed command without replacing launcher files. Native executables and non-Windows command handling are preserved. No configuration, authentication, or identity-verification policy changes are required.

## Why This Change Was Made

The earlier implementation targeted the Agent SDK adapter removed by openclaw#138707. This revision preserves the contributor's commits while applying the repair to the current direct CLI transport. Its launch boundary now uses the existing shared Windows resolver and carries the resolved program together with its leading arguments. Relative commands and PATH entries are resolved against the child working directory; existing identity callers retain their previous behavior.

## Evidence

The supported `agent --local --session-id <fresh> --message "Reply with exactly PONG" --json --timeout 60` path was exercised on real GitHub-hosted Windows 2025 with Node 24.20.0, isolated OpenClaw state, an npm-style prefix, and a controlled external CLI speaking the Anthropic transport protocol. No auth-binding callback or exact-version policy normalized the command first; no platform mock or live provider credential was used.

| Actual Windows launch | Unchanged main production | Candidate production |
| --- | --- | --- |
| Extensionless shim plus npm `.cmd` | `write EPIPE`, no run child or reply | Run child launched; final reply `PONG` |
| npm `.cmd` resolving to Node plus script | `spawn EINVAL`, no run child or reply | Node and script argument preserved; final reply `PONG` |
| Native `.exe` control | Final reply `PONG` | Final reply `PONG` |

- [Baseline run](https://github.com/openclaw/openclaw/actions/runs/35431111855): production from `cc262448fa0c`, proof ref `381771f2ca50`.
- [Candidate run](https://github.com/openclaw/openclaw/actions/runs/35433705895): `e9f91d13d7e3`, with the same three fixtures and order. All three product cases passed. Publication head `7f7212ac7e6b` changes only the fixture's filesystem-error typing, not production or executable fixture bytes.
- A macOS npm-shim control also completed with `PONG`. Focused local checks passed 75 tests, with the native-only case skipped; scoped lint passed.
- The candidate Windows workflow is **not wholly green**: three later executable-identity tests failed with `expected undefined to be package-tree`. The baseline stopped before those cases, so this is not claimed as reproduced base-red. Their two-argument resolver calls retain exactly the previous behavior, run outside the changed execution owner, and execute in separate test processes. The identity guards and assertions remain intact.

This proves the real OpenClaw command, Windows process launch, direct transport, and final reply boundary with a controlled CLI peer. It does not claim live Anthropic authentication/model traffic, pnpm launcher coverage, or Windows resume-session coverage. Ordinary exact-head PR CI remains the wider validation gate.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

2 participants