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

Open 💬 32 comments Opened Jul 8, 2025 by Jiacheng-Liu
💡 Likely answer: A maintainer (wolffiex, collaborator) responded on this thread — see the highlighted reply below.

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.

  1. 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.

View original on GitHub ↗

32 Comments

mtblz · 1 year ago

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

zhengye1 · 1 year ago

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

britaliano · 1 year ago

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

kopyl · 12 months ago

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
wolffiex collaborator · 12 months ago

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

kopyl · 12 months ago

Here is what helped me on macOS:

  1. Wiping out nvm
  2. Installing node from scratch via brew
hlorenz · 12 months ago

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

kuzdogan · 11 months ago

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

<img width="749" height="129" alt="Image" src="https://github.com/user-attachments/assets/031ac432-07e6-4497-a36a-09e415ad9428" />

samcschneider · 11 months ago

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 🍻

wolffiex collaborator · 11 months ago

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_.

labeveryday · 11 months ago

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
wolffiex collaborator · 11 months ago

agents helping agents, I love it!

nhangen · 11 months ago
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 <img alt="Image" width="749" height="129" src="https://private-user-images.githubusercontent.com/13069972/469149430-031ac432-07e6-4497-a36a-09e415ad9428.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTQ2MDEzMDksIm5iZiI6MTc1NDYwMTAwOSwicGF0aCI6Ii8xMzA2OTk3Mi80NjkxNDk0MzAtMDMxYWM0MzItMDdlNi00NDk3LWEzNmEtMDllNDE1YWQ5NDI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA4MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwODA3VDIxMTAwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcxZjRiNjMxYWVmZWYyZGU4ODkzMWNiNDY3NWU5ODg1ZDc5ZDE3ODQ0Y2Y2ODIxMDM3MTA5MzU4ZTRkZDcxOTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ldVrpJCS1fN70uN-lcMQWrleB-b7vuc1YmSSZOgv3f0">

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

Ubeydu · 11 months ago

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.

RyleHan · 11 months ago
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!!

batibatii · 11 months ago

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

kunkkazyc · 11 months ago

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.

giraudvalentin · 11 months ago

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
therealbill · 10 months ago

So after much wrangling, Claude thinks it found it:

```⏺ Found it! The issue is in the Claude Code binary itself. Look at line in the cli.js file:

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.

mrns · 10 months ago

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.

Nezir66 · 10 months ago

For me, the problem was the Node version. I upgraded from v22.13.1 to v22.19.0, and after that I ran "npm install -g @anthropic-ai/claude-code" and then it worked.

goodiet · 10 months ago

Claude Code was working very nicely for a few months but I started getting "command not found" next morning. I ran npm update -g @anthropic-ai/claude-code but got stuck trying to move lib/node_modules/@anthropic-ai/claude-code to a lib/node_modules/@anthropic-ai/.claude-code-d3q0DLDy folder.

I resolved my issue by doing the following:

  1. Remove the lib/node_modules/@anthropic-ai/.claude-code-d3q0DLDy folder.
  2. Run npm uninstall -g @anthropic-ai/claude-code
  3. Run npm install -g @anthropic-ai/claude-code
samdasoxide · 10 months ago

Found an alternative solution in the docs using a native installation that doesn't depend on npm or node.js

achantavy · 9 months ago
Found an alternative solution in the docs using a native installation that doesn't depend on npm or node.js

Yeah, this helped, thank you. In particular I did

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

per https://docs.claude.com/en/docs/claude-code/troubleshooting#recommended-solution%3A-native-claude-code-installation.

JobaDiniz · 9 months ago

on WSL I just updated claude vscode extension and now the claude command is gone (not found)

jesshart · 9 months ago

If you installed using npm, and see this during an uninstall:

╰─$ npm uninstall -g @anthropic-ai/claude-code
npm error code ENOTEMPTY
npm error syscall rename
npm error path /Users/<masked_user>/.nvm/versions/node/v22.17.1/lib/node_modules/@anthropic-ai/claude-code
npm error dest /Users/<masked_user>/.nvm/versions/node/v22.17.1/lib/node_modules/@anthropic-ai/.claude-code-YrYV34KZ
npm error errno -66
npm error ENOTEMPTY: directory not empty, rename '/Users/<masked_user>/.nvm/versions/node/v22.17.1/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/<masked_user>/.nvm/versions/node/v22.17.1/lib/node_modules/@anthropic-ai/.claude-code-YrYV34KZ'
npm error A complete log of this run can be found in: /Users/<masked_user>/.npm/_logs/2025-10-06T19_32_59_542Z-debug-0.log

Note the path up to @anthropi-ai and then run the following:

╰─$ rm -r /Users/<masked_user>/.nvm/versions/node/v22.17.1/lib/node_modules/@anthropic-ai/

And then,

╰─$ npm uninstall -g @anthropic-ai/claude-code

up to date in 93ms

To verify,

╰─$ which claude
claude not found
hasani114 · 9 months ago

I seem to have this problem not right after I install but randomly. I thought it had something to do with the Claude Code IDE extension on VS Code (which is getting stuck in "Install...") but I removed that extension and reinstalled Claude Code again from scratch (after removing everything in node_modules). It worked temporarily, but when I went back to start Claude after the initial session, the command stopped working. I could not find anything in opt/homebrew/bin for claude code.

Not sure why this is happening as all other tools work correctly.

jesshart · 9 months ago

In general, if on Mac or Linux, the official docs recommend using the native installer now when running into installation issues: https://docs.claude.com/en/docs/claude-code/troubleshooting#linux-and-mac-installation-issues%3A-permission-or-command-not-found-errors

MusTanwTR · 7 months ago

This works for me -

Remove the existing installation
sudo rm -rf /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code

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

Or if you prefer a cleaner approach for uninstallation:-
npm uninstall -g @anthropic-ai/claude-code

jesshart · 7 months ago
This works for me - Remove the existing installation sudo rm -rf /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code Then reinstall npm install -g @anthropic-ai/claude-code Or if you prefer a cleaner approach for uninstallation:- npm uninstall -g @anthropic-ai/claude-code

Be advised that Anthropic no longer recommends installing with npm.

<img width="807" height="627" alt="Image" src="https://github.com/user-attachments/assets/75ec4c4a-d41d-4678-b8bf-565fc58d0515" />

https://code.claude.com/docs/en/setup#standard-installation

github-actions[bot] · 6 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.