Component
apps/claude-trace — src/cli.ts → getClaudeAbsolutePath()
Problem
claude-trace fails to start on Windows with two separate errors:
Error 1: which not found
'which' is not recognized as an internal or external command
❌ Claude CLI not found in PATH
Cause: Uses which claude, but Windows doesn't have which. The equivalent is where claude.
Error 2: Bash wrapper parsed as JavaScript
SyntaxError: missing ) after argument list
at wrapSafe (node:internal/modules/cjs/loader:1638:18)
Cause: On Windows, where claude returns the npm global bin path (e.g. C:\Users\...\AppData\Roaming\npm\claude), which is a bash shell wrapper (starts with #!/bin/sh), not a JavaScript file. When Node.js tries to execute it via spawn("node", [..., claudePath]), it fails.
The actual Node.js entry point is at:
...\npm\node_modules\@anthropic-ai\claude-code\cli.js
Suggested Fix
In getClaudeAbsolutePath():
- Use
process.platform === "win32" ? "where claude" : "which claude" for cross-platform lookup
- Add
.split(/\r?\n/)[0] since Windows where may return multiple lines
- Add a
resolveToJS() helper that detects shell wrappers (file starts with #!/ or @ECHO) and resolves to the actual @anthropic-ai/claude-code/cli.js entry point via the npm node_modules path
Full fix code available in the related issue: loki-zhou/claude-trace#4
Environment
- Windows 11 Enterprise 10.0.22631
- Node.js 22.x, npm global install
- Claude Code 2.1.72
Component
apps/claude-trace—src/cli.ts→getClaudeAbsolutePath()Problem
claude-tracefails to start on Windows with two separate errors:Error 1:
whichnot foundCause: Uses
which claude, but Windows doesn't havewhich. The equivalent iswhere claude.Error 2: Bash wrapper parsed as JavaScript
Cause: On Windows,
where claudereturns the npm global bin path (e.g.C:\Users\...\AppData\Roaming\npm\claude), which is a bash shell wrapper (starts with#!/bin/sh), not a JavaScript file. When Node.js tries to execute it viaspawn("node", [..., claudePath]), it fails.The actual Node.js entry point is at:
Suggested Fix
In
getClaudeAbsolutePath():process.platform === "win32" ? "where claude" : "which claude"for cross-platform lookup.split(/\r?\n/)[0]since Windowswheremay return multiple linesresolveToJS()helper that detects shell wrappers (file starts with#!/or@ECHO) and resolves to the actual@anthropic-ai/claude-code/cli.jsentry point via the npmnode_modulespathFull fix code available in the related issue: loki-zhou/claude-trace#4
Environment