fix(server): resolve Claude SDK executable path on Windows npm installs#3740
fix(server): resolve Claude SDK executable path on Windows npm installs#3740nsxdavid wants to merge 2 commits into
Conversation
The Claude Agent SDK spawns `pathToClaudeCodeExecutable` directly, with no
shell and no Windows PATH/PATHEXT resolution. Passing the raw configured
binary path ("claude") therefore fails on Windows when Claude Code is
installed via npm: the bare name is not found, and the npm launcher shim
(claude.cmd) fails with spawn EINVAL since Node 20.12 blocks .cmd spawns
without a shell.
This broke both the capabilities probe (provider stuck on "Could not verify
Claude authentication status from initialization result." despite a fully
authenticated CLI) and SDK-backed chat sessions, while `claude --version`
kept working because CLI probes go through resolveSpawnCommand.
Add resolveClaudeSdkExecutablePath: on Windows, resolve the configured
command against PATH/PATHEXT and, when it lands on an npm launcher shim,
follow it to the packaged entry (bin/claude.exe, or cli.js for older
package versions). Non-Windows behavior is unchanged. Wire it into the
capabilities probe and the Claude adapter.
Verified on Windows 11 with npm-installed Claude Code 2.1.201: probe now
returns account + slash commands in ~1.5s where it previously failed in 9ms.
Log a warning when a Windows launcher shim resolves but no packaged entry is found next to it, so future npm package layout changes surface in logs instead of failing silently. Extend tests to cover .bat/.ps1 shims and mixed-case extension normalization.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved Straightforward Windows-specific bug fix for resolving npm launcher shims to actual executables. The change is well-scoped with comprehensive test coverage and only affects path resolution on Windows platforms. You can customize Macroscope's approvability policy. Learn more. |
Addresses cause A (Windows spawn failure) in #2653.
What Changed
Why
The Claude Agent SDK spawns pathToClaudeCodeExecutable directly, with no shell and no Windows PATH/PATHEXT resolution. Both SDK call sites passed the raw configured binary path (default: bare "claude"). On Windows with an npm-installed CLI that fails two ways:
Result: the provider is stuck on "Needs attention - Could not verify Claude authentication status from initialization result." despite a fully authenticated CLI, and SDK-backed sessions are broken. The version probe kept working because CLI commands go through resolveSpawnCommand, which handles .cmd via shell: true. That is why the card shows the correct version while auth verification fails.
This fixes the probe's root cause rather than adding an auth-status fallback (the approach in #3559, closed).
Validation
Checklist
Note
Medium Risk
Changes how the Claude binary is chosen on Windows for SDK sessions and auth verification; incorrect resolution could still break provider status or sessions, but scope is limited to Windows and both call sites share one helper with tests.
Overview
Fixes Windows npm installs where the Claude Agent SDK could not spawn the configured
claudecommand (bare name or.cmd/.bat/.ps1shims) because the SDK spawns without a shell or PATH/PATHEXT resolution.Introduces
resolveClaudeSdkExecutablePath, which on Windows resolves the binary viaSpawnExecutableResolution, then follows npm launcher shims tobin/claude.exeorcli.jswhen present. Non-Windows platforms return the configured path unchanged.Wires the resolved path into both Agent SDK entry points: the capabilities/auth probe in
ClaudeProviderandpathToClaudeCodeExecutableat session startup inClaudeAdapter. Adds unit tests for platform passthrough, native exe, shim following, and fallbacks.Reviewed by Cursor Bugbot for commit ef7f1d2. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix Claude SDK executable path resolution on Windows npm installs
.cmd/.bat/.ps1shims that the Claude Agent SDK cannot spawn directly; this fix resolves those shims to the actual binary (claude.exeorcli.js).resolveClaudeSdkExecutablePathin ClaudeExecutable.ts handles the resolution: on non-Windows it returns the path unchanged; on Windows it follows shims to known package entry points adjacent tonode_modules.Macroscope summarized ef7f1d2.