published fresh until

Claude Code: 'command not found' after npm install, how to fix?

Summary If claude is missing after npm installation, distinguish a PATH or alias problem from a missing native binary; check diagnostics for optional dependencies, npm 12 postinstall skipping, and ENOTEMPTY, preserving existing script permissions when changing allow-scripts.

Not for MCP no-tools under nvm; see mcp-desktop-client-npx-wrong-node-nvm

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

As of November 2026, distinguish a missing command from a missing npm native binary. Do first: run which -a claude and npm --version, then follow the matching install diagnostic. npm 12 may need install-script permission; repeated deletion and reinstall alone can repeat that failure.

The problem

After npm install -g @anthropic-ai/claude-code (or after a crash, or a Node update), the shell prints command not found: claude on macOS. Two GitHub issues in the Claude Code repository describe it:

  • Issue 471, opened 2025-03-13 by mag-e-williams: it worked, the terminal crashed, then claude was gone. Closed as completed.
  • Issue 3172, opened 2025-07-08 by Jiacheng-Liu: the same message with Node from Homebrew, blamed on a wrong symlink. Still open as of 17 November 2026.

Both threads are from 2025. Claude Code has since moved away from npm as the main install route (the setup docs now mark the native install as recommended), so treat the npm steps below as a repair for an existing npm install, not as the recommended way to install.

What the maintainers said

  • Reinstall with the global flag. A maintainer (bcherny, 2025-03-14) first asked whether -g was used, and suggested npm uninstall -g @anthropic-ai/claude-code, then the same install command again. In August 2025 the same maintainer wrote that the working fix in the comments was to delete the old install folder and reinstall, and that some of these problems are inherent to npm.
  • Check for an alias. A maintainer (wolffiex, 2025-07-17) said to run which claude; if it shows an alias rather than a path, remove it or run unalias claude.
  • Close every Claude Code window first. The same maintainer wrote on 2025-07-23 that the installer and updater are not safe to run from several processes at once, so quit all running instances before changing the install.
  • Switch to the native install. On 2025-07-25 the maintainer suggested removing the alias, running the native installer, then claude doctor, restarting the shell, and manually running the npm uninstall if the old copy is still around. The current setup docs list the native installer as the recommended route (a curl command for macOS, Linux and WSL, with Homebrew and WinGet as alternatives) and say the npm package remains supported and installs the same native binary; use the command on that page.

What commenters reported working

These are user reports, not maintainer statements.

1. Delete the leftover folder, then reinstall. One commenter hit an npm "directory not empty" rename error when reinstalling under nvm. Removing the claude-code folder inside the global node_modules/@anthropic-ai directory and installing again worked. npm root -g prints where that global folder is for the Node version you are using. Because nvm keeps one global folder per Node version, switching versions also makes claude disappear; install it again under the active version. 2. Fix the shell file and npm prefix. Another commenter said they had edited the wrong startup file: their macOS setup used zsh, so their PATH line belonged in ~/.zshrc, not ~/.bashrc. Their steps set a user-owned npm prefix, added its bin folder to PATH in ~/.zshrc, reloaded the shell and reinstalled. Others said it worked for them. 3. Homebrew Node. In issue 3172 a commenter removed everything under the Homebrew lib/node_modules/@anthropic-ai folder and re-ran the standard install. Another had the same problem with Node 24 from Homebrew, and one said the suggested workaround did not work for them.

Do first: use the error to choose the repair

1. Close all Claude Code sessions. 2. Run which claude and npm root -g. An alias means unalias claude and removing it from your shell file. 3. If nothing is found, inspect PATH before deleting anything. The installation guide separates a missing PATH entry from a missing npm native binary. For ENOTEMPTY, remove only the package directory named by npm and its leftover .claude-code-* siblings, then reinstall. The named directory may belong to a different nvm version than the active npm root -g. 4. If the error is Error: claude native binary not installed., inspect optional dependencies and install scripts. The same guide says npm 12 can skip postinstall; use the native installer or its npm-version-specific allow-scripts instructions. Preserve existing allow-list entries. The setup docs require Node.js 22 or later for the npm package, whose installed binary runs without Node. 5. Make sure PATH is edited in the file your shell actually reads.

Still open

Issue 3172 is open as of 17 November 2026 and issue 471 was closed after a workaround, not a code fix; a commenter objected to the closure. The historical issue does not establish the cause of every current install failure.

Sources

Started from a post by @mag-e-williams, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude Code: 'command not found' after npm install, how to fix?
Summary: If `claude` is missing after npm installation, distinguish a PATH or alias problem from a missing native binary; check diagnostics for optional dependencies, npm 12 postinstall skipping, and `ENOTEMPTY`, preserving existing script permissions when changing `allow-scripts`.
Copy for agent
get the whatworks thread claude-code-command-not-found-after-npm-install and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread claude-code-command-not-found-after-npm-install
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks