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 7 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. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d4110b3. Configure here.

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 probing; incorrect resolution could break Claude provider startup, but scope is limited to Windows shim handling with fallbacks and tests.
Overview
Fixes Claude Agent SDK startup on Windows when the configured binary is a bare
claudename or an npm launcher shim (.cmd/.bat/.ps1), which the SDK cannot spawn without a shell.Adds
resolveClaudeSdkExecutablePathinClaudeExecutable.ts: on win32 it usesSpawnExecutableResolution(PATH/PATHEXT), then if the result is a shim it looks beside the shim for@anthropic-ai/claude-codeentry points (bin/claude.exefirst, elsecli.js). Other platforms return the configured path unchanged; unknown shim layouts fall back to the original path with a warning.Wires the resolved path into both SDK call sites:
ClaudeAdapter(pathToClaudeCodeExecutableat session start) andClaudeProvidercapabilities probe (probeClaudeCapabilities), replacing rawclaudeSettings.binaryPath.Unit tests cover non-Windows passthrough, native
.exe, shim following, extension normalization,cli.jsfallback, and failure paths via injectableClaudeExecutableFileCheck.Reviewed by Cursor Bugbot for commit b213574. 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 b213574.