Skip to content

[claude-trace] Windows compatibility: getClaudeAbsolutePath() fails #60

Description

@thomas-jimmy-chen

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():

  1. Use process.platform === "win32" ? "where claude" : "which claude" for cross-platform lookup
  2. Add .split(/\r?\n/)[0] since Windows where may return multiple lines
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions