claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open Jiacheng-Liu opened this issue 1 year ago • 32 comments

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.

Jiacheng-Liu avatar Jul 08 '25 20:07 Jiacheng-Liu

Same thing for me with the Node.js 24.3.0 (homebrew) and macos 15.5

mtblz avatar Jul 09 '25 07:07 mtblz

Same for windows... I need to manually add that into environment variable

zhengye1 avatar Jul 15 '25 23:07 zhengye1

May also be affected, after running on a Mac running MacOS 13.7.6:

npm install -g @anthropic-ai/claude-code

I get

/opt/homebrew/bin/claude: No such file or directory

britaliano avatar Jul 16 '25 14:07 britaliano

Same bug.

$ npm install -g @anthropic-ai/claude-code

changed 2 packages in 1s
$ claude
-bash: claude: command not found
$ which npm npx node | xargs -n1 readlink
/Users/olehkopyl/.nvm/versions/node/v20.0.0/bin/npm
/Users/olehkopyl/.nvm/versions/node/v20.0.0/bin/npx
/Users/olehkopyl/.nvm/versions/node/v20.0.0/bin/node

kopyl avatar Jul 17 '25 05:07 kopyl

yeah, you'd have to say which claude to debug this. if it is an alias you will have to remove or unalias

wolffiex avatar Jul 17 '25 05:07 wolffiex

Here is what helped me on macOS:

  1. Wiping out nvm
  2. Installing node from scratch via brew

kopyl avatar Jul 17 '25 05:07 kopyl

Same here with Node.js 22 on Windows WSL. Reinstalling Node (from nvm) and reinstalling claude code solved that problem (...for now)

hlorenz avatar Jul 17 '25 11:07 hlorenz

I realized this is because claude is installed on a different nodejs version.

E.g. I had claude installed on node 20.12. claude command fails on node 22.4

Image

kuzdogan avatar Jul 22 '25 10:07 kuzdogan

I was having the same problem on osx + brew and found my way here. The workaround wasn't working for me, so I just removed everything under /opt/homebrew/lib/node_modules/@anthropic-ai (which was just claude-code for me) and then re-ran the standard install. I'm back in action now. HTH 🍻

samcschneider avatar Jul 23 '25 14:07 samcschneider

One note for folks who are having trouble: the installer and updater are not multi-process safe. We're working on tightening this up, but for now, when twiddling with your install, it's best to quit all instances of Claude Code.

wolffiex avatar Jul 23 '25 14:07 wolffiex

I had Q CLI go in and fix it for me: The issue was caused by a corrupted installation where the yoga.wasm file was missing. By completely removing the old installation and reinstalling it fresh, we' ve resolved the problem.

Summary of what was fixed:

  1. Identified the issue: Missing yoga.wasm dependency in the Claude CLI installation
  2. Removed corrupted installation: Force-removed the broken installation directory and symlink
  3. Reinstalled cleanly: Used npm to install a fresh copy of @anthropic-ai/claude-code
  4. Verified functionality: Confirmed the CLI is working with version and help commands

labeveryday avatar Jul 30 '25 19:07 labeveryday

agents helping agents, I love it!

wolffiex avatar Jul 30 '25 19:07 wolffiex

I realized this is because claude is installed on a different nodejs version.

E.g. I had claude installed on node 20.12. claude command fails on node 22.4

Image

This is the answer. I had Claude installed on 22.

nhangen avatar Aug 07 '25 21:08 nhangen

Here is how I and Claude solved it, hope this helps:

Claude Code "command not found" - Diagnosis and Solution

Problem: Getting zsh: command not found: claude even though Claude Code appears to be installed.

Root Cause Analysis

The issue was a corrupted npm installation of Claude Code:

  1. Partial Installation: npm list -g @anthropic-ai/claude-code showed the package as "installed"
  2. Missing Core Files: The main executable (cli.js) and package files were completely missing
  3. Broken Symlink: A symlink existed in the npm bin directory but pointed to non-existent files
  4. Failed Cleanup: npm uninstall couldn't remove the corrupted installation due to directory state issues

Diagnostic Steps Used

# Check if claude is in PATH
which claude

# Check npm global installation status
npm list -g @anthropic-ai/claude-code

# Check npm global prefix location
npm config get prefix

# Check if binary exists where npm expects it
ls -la /path/to/npm/global/bin/claude

# Find what files actually exist in the package directory
find /path/to/npm/global/lib/node_modules/@anthropic-ai/claude-code/ -type f

Solution

  1. Manual cleanup (since npm uninstall failed):
rm -rf /path/to/npm/global/lib/node_modules/@anthropic-ai/claude-code
  1. Use native installer (recommended approach from official docs):
curl -fsSL https://claude.ai/install.sh | bash
  1. Make PATH permanent (critical step often missed):
# Add to your shell configuration file
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc

# Reload your shell
source ~/.zshrc

Common PATH issues:

  • Using ~/.local/bin (tilde not expanded) instead of $HOME/.local/bin
  • Only running export PATH="$HOME/.local/bin:$PATH" temporarily - this only affects the current session
  • Forgetting to reload shell with source ~/.zshrc after modifying the config file

Key Takeaway

For npm installation issues with Claude Code, the native installer is the recommended solution. It bypasses npm entirely and installs to ~/.local/bin, avoiding PATH and permission issues common with global npm packages. Don't forget to make the PATH change permanent by adding it to your shell configuration file.

Ubeydu avatar Aug 08 '25 11:08 Ubeydu

Here is how I and Claude solved it, hope this helps:

Claude Code "command not found" - Diagnosis and Solution

Problem: Getting zsh: command not found: claude even though Claude Code appears to be installed.

Root Cause Analysis

The issue was a corrupted npm installation of Claude Code:

1. **Partial Installation**: `npm list -g @anthropic-ai/claude-code` showed the package as "installed"

2. **Missing Core Files**: The main executable (`cli.js`) and package files were completely missing

3. **Broken Symlink**: A symlink existed in the npm bin directory but pointed to non-existent files

4. **Failed Cleanup**: `npm uninstall` couldn't remove the corrupted installation due to directory state issues

Diagnostic Steps Used

Check if claude is in PATH

which claude

Check npm global installation status

npm list -g @anthropic-ai/claude-code

Check npm global prefix location

npm config get prefix

Check if binary exists where npm expects it

ls -la /path/to/npm/global/bin/claude

Find what files actually exist in the package directory

find /path/to/npm/global/lib/node_modules/@anthropic-ai/claude-code/ -type f

Solution

1. **Manual cleanup** (since npm uninstall failed):

rm -rf /path/to/npm/global/lib/node_modules/@anthropic-ai/claude-code

2. **Use native installer** (recommended approach from official docs):

curl -fsSL https://claude.ai/install.sh | bash

3. **Make PATH permanent** (critical step often missed):

Add to your shell configuration file

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc

Reload your shell

source ~/.zshrc

Common PATH issues:

* Using `~/.local/bin` (tilde not expanded) instead of `$HOME/.local/bin`

* Only running `export PATH="$HOME/.local/bin:$PATH"` temporarily - this only affects the current session

* Forgetting to reload shell with `source ~/.zshrc` after modifying the config file

Key Takeaway

For npm installation issues with Claude Code, the native installer is the recommended solution. It bypasses npm entirely and installs to ~/.local/bin, avoiding PATH and permission issues common with global npm packages. Don't forget to make the PATH change permanent by adding it to your shell configuration file.

It works for me, thanks!!

RyleHan avatar Aug 11 '25 17:08 RyleHan

Hi all, I updated my node version then I have done this and it worked:

macOS

rm -rf /Users/yourUserName/.npm-global/lib/node_modules/@anthropic-ai/claude-code npm install -g @anthropic-ai/claude-code

batibatii avatar Aug 12 '25 07:08 batibatii

I uninstall node v24 and install v22.18.0, finally it works : npm install -g @anthropic-ai/claude-code. it seems like that this issue happens when the node version is larger than v22.

kunkkazyc avatar Aug 14 '25 02:08 kunkkazyc

Had a bug with npm global and also with curl (native) install :

# Install native
curl -fsSL https://claude.ai/install.sh | bash -s latest

❯ which claude
/Users/xxx/.local/bin/claude

Then opened new shell and claude disappear... 😠

But... I found it was in another folder to add to the $PATH

❯ ll /Users/xxx/.local/bin/claude
lrwxr-xr-x@ - xxx 15 aoû 14:04 /Users/xxx/.local/bin/claude -> /Users/xxx/.local/share/claude/versions/1.0.81

# Add this to your path to get it work (change zshrc to your shell)
echo 'export PATH="$HOME/.local/share:$PATH"' >> ~/.zshrc

# Now it work
which claude
/Users/xxx/.local/bin/claude

giraudvalentin avatar Aug 15 '25 12:08 giraudvalentin

So after much wrangling, Claude thinks it found it:


  if(A.includes("/.local/bin/claude"))return"native";

  This is part of the installation type detection logic. The code is checking if Claude Code is running from ~/.local/bin/claude to determine if it's a "native" installation, but it's displaying an error message when it can't find the binary there.

  The check is happening during startup to determine the installation type, but the error message suggests it's looking for the binary when it doesn't exist there.

  This appears to be a bug in the Claude Code v1.0.92 binary - it's incorrectly reporting a "command not found" error during its installation type detection rather than just noting it's not a native installation.

  You could either:
  1. Report this as a bug at https://github.com/anthropics/claude-code/issues
  2. Create the symlink as a workaround: mkdir -p ~/.local/bin && ln -s $(which claude) ~/.local/bin/claude

  The second option will satisfy the check and eliminate the error message.```

Of course, option 2 changes it to an error about claude pointing to an invalid symlink and no manner of fiddling w/symlink targets seems to satisfy it.

therealbill avatar Aug 26 '25 20:08 therealbill

If you are seeing ● Claude command not found at /Users/[your_user]/.local/bin/claude, then:

  • Run claude config get --global installMethod outside claude code
  • Run /doctor inside claude.

If your installMethod shows as "native" and claude doctor command shows Config install method: npm, then:

  • Run claude config set --global installMethod npm

My guess is that this happens when you tried switching from npm installation to native without noticing some claude session was still running which messes up the configuration.

mrns avatar Aug 30 '25 14:08 mrns