Skip to content

Bug: claude command not found after npm install -g on macOS with Homebrew due to incorrect symlink #3172

Description

@Jiacheng-Liu

Description

When installing @anthropic-ai/claude-code globally via npm on macOS
(with Node.js installed via Homebrew), the claude command is not
correctly added to the PATH. The installation creates an incorrect
symbolic link in the Homebrew binary directory, causing a "command not
found" error when trying to execute claude.

Environment

  • OS: macOS
  • Package Manager: Homebrew
  • Node.js Version: v23.2.0
  • npm Version: 11.4.2

Steps to Reproduce

  1. On a macOS system with Homebrew, install Node.js: brew install node.
  2. Install the Claude Code CLI globally: npm install -g
    @anthropic-ai/claude-code.
  3. Attempt to run the claude command: claude --version.

Expected Behavior

The claude command should be accessible from the shell and should print
its version number.

Actual Behavior

The shell returns a "command not found" error.

Further investigation reveals that npm creates an incorrect symbolic
link:

  • Location: /opt/homebrew/bin/claude
  • Incorrect Target:
    ../lib/node_modules/@anthropic-ai/claude-code/cli.js

This link points to a JavaScript file instead of the executable
launcher script.

Workaround

The issue can be resolved by manually replacing the incorrect symbolic
link with the correct one.

  1. Remove the incorrect link:

1 rm /opt/homebrew/bin/claude

  1. Create the correct link to the executable in the Homebrew Cellar:
    (Note: The Node.js version in the path may vary)

1 ln -s /opt/homebrew/Cellar/node/23.2.0/bin/claude
/opt/homebrew/bin/claude

After performing these steps, the claude command works as expected.
This suggests the issue lies in the package's installation script or
npm's handling of global binaries in a Homebrew environment.

Metadata

Metadata

Assignees

Labels

area:packagingbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions