Bug: claude command not found after npm install -g on macOS with Homebrew due to incorrect symlink
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
- On a macOS system with Homebrew, install Node.js: brew install node.
- Install the Claude Code CLI globally: npm install -g
@anthropic-ai/claude-code.
- 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.
- Remove the incorrect link:
1 rm /opt/homebrew/bin/claude
- 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.
32 Comments
Same thing for me with the
Node.js 24.3.0(homebrew) andmacos 15.5Same for windows... I need to manually add that into environment variable
May also be affected, after running on a Mac running MacOS 13.7.6:
npm install -g @anthropic-ai/claude-codeI get
/opt/homebrew/bin/claude: No such file or directory
Same bug.
yeah, you'd have to say
which claudeto debug this. if it is an alias you will have to remove or unaliasHere is what helped me on macOS:
Same here with Node.js 22 on Windows WSL. Reinstalling Node (from nvm) and reinstalling claude code solved that problem (...for now)
I realized this is because claude is installed on a different nodejs version.
E.g. I had claude installed on node 20.12.
claudecommand fails on node 22.4<img width="749" height="129" alt="Image" src="https://github.com/user-attachments/assets/031ac432-07e6-4497-a36a-09e415ad9428" />
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 justclaude-codefor me) and then re-ran the standard install. I'm back in action now. HTH 🍻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_.
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:
agents helping agents, I love it!
This is the answer. I had Claude installed on 22.
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: claudeeven though Claude Code appears to be installed.Root Cause Analysis
The issue was a corrupted npm installation of Claude Code:
npm list -g @anthropic-ai/claude-codeshowed the package as "installed"cli.js) and package files were completely missingnpm uninstallcouldn't remove the corrupted installation due to directory state issuesDiagnostic Steps Used
Solution
Common PATH issues:
~/.local/bin(tilde not expanded) instead of$HOME/.local/binexport PATH="$HOME/.local/bin:$PATH"temporarily - this only affects the current sessionsource ~/.zshrcafter modifying the config fileKey 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!!
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-codenpm install -g @anthropic-ai/claude-codeI 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.
Had a bug with npm global and also with curl (native) install :
Then opened new shell and claude disappear... 😠
But... I found it was in another folder to add to the $PATH
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:
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.
If you are seeing
● Claude command not found at /Users/[your_user]/.local/bin/claude, then:claude config get --global installMethodoutside claude code/doctorinside claude.If your installMethod shows as "native" and claude doctor command shows
Config install method: npm, then:claude config set --global installMethod npmMy 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.
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.
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-codebut got stuck trying to movelib/node_modules/@anthropic-ai/claude-codeto alib/node_modules/@anthropic-ai/.claude-code-d3q0DLDyfolder.I resolved my issue by doing the following:
lib/node_modules/@anthropic-ai/.claude-code-d3q0DLDyfolder.npm uninstall -g @anthropic-ai/claude-codenpm install -g @anthropic-ai/claude-codeFound 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
per https://docs.claude.com/en/docs/claude-code/troubleshooting#recommended-solution%3A-native-claude-code-installation.
on WSL I just updated claude vscode extension and now the
claudecommand is gone (not found)If you installed using npm, and see this during an uninstall:
Note the path up to
@anthropi-aiand then run the following:And then,
To verify,
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.
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
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-codeBe 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
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.
https://code.claude.com/docs/en/setup#native-binary-installation-beta