[BUG] claude crashed in terminal, and i'm getting the error `zsh: command not found: claude` when i try to reopen by running `claude`

Resolved 💬 46 comments Opened Mar 13, 2025 by mag-e-williams Closed Aug 22, 2025
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: <!-- output of claude --version -->
  • Operating System: <!-- e.g. macOS 14.3, Windows 11, Ubuntu 22.04 -->
  • Terminal: <!-- e.g. iTerm2, Terminal App -->

Bug Description

Claude was working well, and then all of the sudden it crashed, and now when i try to run claude in my terminal to reopen the interface, im getting zsh: command not found: claude

Expected Behavior

open the claude code interface

Actual Behavior

<!-- What actually happened -->
zsh: command not found: claude

Additional Context

I;ve tried to uninstall and re-install the npm package, but im gettiing the following error when i try to uninstall

npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "workspace:": workspace:^

npm ERR! A complete log of this run can be found in: /Users/maggiewilliams/.npm/_logs/2025-03-13T20_04_40_485Z-debug-0.log
maggiewilliams@Maggies-MacBook-Pro-5 clay-base % npm uninstall @anthropic-ai/claude-code
npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "workspace:": workspace:^

View original on GitHub ↗

46 Comments

bcherny collaborator · 1 year ago

Hey! Are you using the -g flag? npm uninstall -g @anthropic-ai/claude-code && npm install -g @anthropic-ai/claude-code

mag-e-williams · 1 year ago

With that flag, im am still unable to successfully uninstall/reinstall and getting the following error:

npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /Users/maggiewilliams/.nvm/versions/node/v18.18.2/lib/node_modules/@anthropic-ai/claude-code
npm ERR! dest /Users/maggiewilliams/.nvm/versions/node/v18.18.2/lib/node_modules/@anthropic-ai/.claude-code-7cM9dxTP
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/Users/maggiewilliams/.nvm/versions/node/v18.18.2/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/maggiewilliams/.nvm/versions/node/v18.18.2/lib/node_modules/@anthropic-ai/.claude-code-7cM9dxTP'

and i am still unable to run claude, still getting the error
zsh: command not found: claude

after previously being able to run it successfully

lukashanak · 1 year ago

same thing happening for me

lukashanak · 1 year ago

Solution, this has worked for me

Remove the existing directory before reinstalling:

rm -rf ~/.nvm/versions/node/v20.13.1/lib/node_modules/@anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code
dkiselew · 1 year ago

Same here, i just closed Claude Code and after that in other directory I'm trying to execute "claude" and get "Command not found". macOS Sonoma

ijohnson-coursera · 1 year ago

Same issue here

asadakbar · 1 year ago

I didn't have an issue uninstalling, and reinstalling does not resolve the issue. I also used the -g flag.

jackwpearson · 1 year ago

I am having the same issue. Uninstall does not seem to work either

joe-cranney · 1 year ago

Having same issue

leeovery · 1 year ago

Also having this issue. Uninstalling and reinstalling is doing nothing to fix, which makes absolutely no sense, unless some funky stuff is going on during the install, which is being skipped during reinstall.

lukashanak · 1 year ago
Also having this issue. Uninstalling and reinstalling is doing nothing to fix, which makes absolutely no sense, unless some funky stuff is going on during the install, which is being skipped during reinstall.

check my answer https://github.com/anthropics/claude-code/issues/471#issuecomment-2726301474

faetalize · 1 year ago

why would you close this? just cuz someone found a workaround using rm -rf doesn't mean this bug is fixed. This needs to be reopened

rahulmanuwas · 1 year ago

You might be using .bashrc (linux/wsl) when you are supposed to be using .zshrc (macos) - I had that issue. Try these steps :

npm list -g --depth=0 > ~/npm-global-packages.txt
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
npm install -g @anthropic-ai/claude-code
Cheffromspace · 1 year ago

┌[jonflatt☮DESKTOP-6M0SR6A]-(/mnt/c/Users/Jonathan/source/MCPControl)-[git://feature/coordinate-transformation ✗]-
└> claude
╭─────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code research preview! │
│ │
│ /help for help │
│ │
│ cwd: /mnt/c/Users/Jonathan/source/MCPControl │
╰─────────────────────────────────────────────────╯

✔ Loaded project memory • /memory

What's new:
• Resume conversations from where you left off
from with "claude --continue" and "claude
--resume"
• Claude now has access to a Todo list that helps
it stay on track and be more organized

╭────────────────────────────────────────────────╮
│ > exit │
╰────────────────────────────────────────────────╯
Auto-updating to v0.2.94…

Total cost: $0.0000
Total duration (API): 0s
Total duration (wall): 19.4s
Total code changes: 0 lines added, 0 lines removed
┌[jonflatt☮DESKTOP-6M0SR6A]-(/mnt/c/Users/Jonathan/source/MCPControl)-[git://feature/coordinate-transformation ✗]-
└> claude
zsh: command not found: claude

Breaks after auto-update, not sure why this was closed @bcherny

nthsense · 1 year ago
You might be using .bashrc when you are supposed to be using .zshrc - I had that issue. Try these steps : `` npm list -g --depth=0 > ~/npm-global-packages.txt mkdir -p ~/.npm-global npm config set prefix ~/.npm-global echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc source ~/.zashrc npm install -g @anthropic-ai/claude-code ``

This worked for me.

nonmodernist · 1 year ago
You might be using .bashrc (linux/wsl) when you are supposed to be using .zshrc (macos) - I had that issue. Try these steps : `` npm list -g --depth=0 > ~/npm-global-packages.txt mkdir -p ~/.npm-global npm config set prefix ~/.npm-global echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc source ~/.zshrc npm install -g @anthropic-ai/claude-code ``

This worked for me as well.

tsbaker · 1 year ago

This worked for me as well

chandrakalagowda · 1 year ago

@nonmodernist Thank you. It worked for me as well....

didierphmartin · 1 year ago
You might be using .bashrc (linux/wsl) when you are supposed to be using .zshrc (macos) - I had that issue. Try these steps : `` npm list -g --depth=0 > ~/npm-global-packages.txt mkdir -p ~/.npm-global npm config set prefix ~/.npm-global echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc source ~/.zshrc npm install -g @anthropic-ai/claude-code ``

This worked for me too

TomasHubelbauer · 1 year ago

It is insane to me that this got closed. Clearly, this is multiple people's first experience with Claude Code. Anyway, for those who didn't have an NPM install from NVM and don't want to bother with adjusting the workaround with the correct path for the global NPM storage and stuff - just use Bun. It works and it works right away.

bun add -g @anthropic-ai/claude-code

smoothie-master · 1 year ago

This happened to me too. I suspect the cause is that Claude Code was installing an update when it crashed and left itself in a corrupted state. This issue should absolutely be re-opened.

mkyl · 1 year ago

I'm having this issue too. Closed claude cleanly and now:

moe@Moe-MBP ~> claude
fish: Unknown command: claude

While using it, it was installing an update.

wolffiex collaborator · 1 year ago

If you are using npm, the workaround should be npm install -g @anthropic-ai/claude-code
We will be shipping improvements here soon!

mikeanderson42 · 1 year ago

I used Claude desktop to fix mine, steps below.

Steps to Fix Claude Code

  1. First, force remove the problematic installation:

bashrm -rf ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code
rm -rf ~/.npm-global/lib/node_modules/@anthropic-ai/.claude-code-*

  1. Clear npm cache:

bashnpm cache clean --force

  1. Check if claude is still somehow installed globally:

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

  1. Reinstall Claude Code:

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

  1. Verify the installation:

bashclaude --version

  1. If it's still not working, check your PATH:

bashecho $PATH
ls -la ~/.npm-global/bin/
Alternative Solution (if above doesn't work):
If the above steps don't resolve it, try installing with a different prefix:
bash# Remove current npm prefix
npm config delete prefix

Install globally with default npm location

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

Or use npx without installing

npx @anthropic-ai/claude-code
Additional Troubleshooting:

Check for permission issues:
bashls -la ~/.npm-global/lib/node_modules/

Try running with full path:
bash~/.npm-global/bin/claude

Ensure your shell config is sourced:
bashsource ~/.zshrc

or if using bash

source ~/.bashrc

The main issue appears to be corrupted npm module directories. The force removal and clean reinstall should resolve it. Let me know which step works or if you encounter any other errors!

janbolat · 1 year ago

Installed yesterday, today having issue:

zsh: command not found: claude

janbolat · 1 year ago
If you are using npm, the workaround should be npm install -g @anthropic-ai/claude-code We will be shipping improvements here soon!

It didn't help.

zhanbolat@Zhanbolats-MacBook-Pro s_com % npm install -g @anthropic-ai/claude-code
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /Users/zhanbolat/.nvm/versions/node/v20.11.1/lib/node_modules/@anthropic-ai/claude-code
npm ERR! dest /Users/zhanbolat/.nvm/versions/node/v20.11.1/lib/node_modules/@anthropic-ai/.claude-code-fxrhFiIP
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/Users/zhanbolat/.nvm/versions/node/v20.11.1/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/zhanbolat/.nvm/versions/node/v20.11.1/lib/node_modules/@anthropic-ai/.claude-code-fxrhFiIP'

npm ERR! A complete log of this run can be found in: /Users/zhanbolat/.npm/_logs/2025-06-21T10_56_32_639Z-debug-0.log
janbolat · 1 year ago
> You might be using .bashrc when you are supposed to be using .zshrc - I had that issue. Try these steps : > `` > npm list -g --depth=0 > ~/npm-global-packages.txt > mkdir -p ~/.npm-global > npm config set prefix ~/.npm-global > echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc > source ~/.zashrc > npm install -g @anthropic-ai/claude-code > `` This worked for me.

This helped me. Thank you

zhangyuliang1994 · 1 year ago
> You might be using .bashrc (linux/wsl) when you are supposed to be using .zshrc (macos) - I had that issue. Try these steps : > `` > npm list -g --depth=0 > ~/npm-global-packages.txt > mkdir -p ~/.npm-global > npm config set prefix ~/.npm-global > echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc > source ~/.zshrc > npm install -g @anthropic-ai/claude-code > `` This worked for me too

Thanks, this worked for me too!

williamchenghu · 1 year ago
You might be using .bashrc (linux/wsl) when you are supposed to be using .zshrc (macos) - I had that issue. Try these steps : `` npm list -g --depth=0 > ~/npm-global-packages.txt mkdir -p ~/.npm-global npm config set prefix ~/.npm-global echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc source ~/.zshrc npm install -g @anthropic-ai/claude-code ``

This shall work. If you look closer, it's trying to create a new hidden folder to point npm package installations to, as well as adding the bin folder which contains executables to the PATH. This is already a great indication pointing us to the right direction in case one don't want to do such a _manual_ creation and pointing.

Then the question boils down to "where is my npm packages bin folder?". I suppose the answer may depends on one's setup. For my case, I use asdf to manage my node versions. For some reasons it doesn't rebuild shims after installing global packages. One would have to do it manually (ref. here). So after rebuilding the shim with asdf reshim nodejs, claude works instantaneously.

rkofman · 1 year ago

I was using nodenv (that I forgot about). Installed claude using the default npm install -g @anthropic-ai/claude-code command, and claude couldn't be found. After finding this thread, remembered that nodenv recommends running:

rehash - Rehash nodenv shims (run this after installing executables)

Running nodenv rehash fixed it instantly. Thank you, @williamchenghu.

toddanglin · 1 year ago

Experienced the same problem this week (macOS 15.5). So, FWIW, still not resolved. Like others, Claude was working perfectly, then I closed the terminal session, opened a new one, and: ../../.claude/local/node_modules/.bin/claude: No such file or directory

I do agree that this seems to be related to Anthropic's auto-updates that tries to run while you're actively using Claude in the terminal. None of the steps to resolve listed above worked for me, so YMMV.

For now, I've just resorted npx @anthropic-ai/claude-code ¯\_(ツ)_/¯

abury · 1 year ago

Fresh install on OSX Sequoia is also showing command not found error. Not sure if using the asdf version manager is causing issues, but probably shouldn't.
npx it is

hugocore · 1 year ago

asdf reshim nodejs after npm install fixed zsh: command not found: claude for me if you are using asdf and zsh.

abrambailey · 11 months ago

Probably won't work for everyone, but I closed and reopened iTerm and it worked.

destinflow · 11 months ago

I had a similar issue on macOS. In my case, it was caused by a broken Node.js install (due to missing ICU libraries like libicui18n) and Homebrew not yet supporting macOS 15 properly.

Here’s what worked for me:

Step-by-step Fix:

  1. Uninstall broken Node.js (if installed via Homebrew):
sudo rm -rf /opt/homebrew/Cellar/node@14
sudo rm -rf /opt/homebrew/bin/node
sudo rm -rf /opt/homebrew/bin/npm
sudo rm -rf /opt/homebrew/lib/node_modules
  1. Install Node.js using nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.zshrc  # or ~/.bashrc
nvm install 20
nvm use 20
  1. Uninstall any corrupted Claude package (if needed):

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

If you see a workspace: protocol error, it’s usually from a corrupted package-lock.json or monorepo. Clean up your global npm setup and reinstall using nvm.

  1. Reinstall Claude CLI cleanly:

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

After that, the claude command worked again without issues.

wolffiex collaborator · 11 months ago

If you're having trouble, try this:

  • unalias claude
  • curl -fsSL claude.ai/install.sh | bash
  • claude doctor

Make sure you're running the native version.
You may need to restart your shell.
You may need to manually do npm uninstall -g @anthropic-ai/claude-code

Ghedeon · 11 months ago

Same problem. Crashed and now it's zsh: command not found: claude.

lap-sys · 11 months ago

Same problem, solved by reinstalling node

Download and install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

in lieu of restarting the shell

\. "$HOME/.nvm/nvm.sh"

Download and install Node.js:

nvm install 22

install claude

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

shaikanas-deriv · 11 months ago

Fix: Claude Code Error on macOS with Homebrew

Problem Description

After installing Claude Code via npm on macOS with Homebrew, users may encounter:

  1. Initial Issue: claude: command not found after installation
  2. Secondary Issue: When trying to uninstall and reinstall:
npm error code ENOTEMPTY
npm error syscall rename
npm error path /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code
npm error ENOTEMPTY: directory not empty, rename '/opt/homebrew/lib/node_modules/@anthropic-ai/claude-code' -> '/opt/homebrew/lib/node_modules/@anthropic-ai/.claude-code-2DTsDk1V'
  1. Final Issue: After partial installation, claude command throws:
Error: Cannot find module './yoga.wasm'
Require stack:
- /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js

Root Cause

The npm installation creates a broken installation that:

  • Has missing dependencies (yoga.wasm)
  • Cannot be properly uninstalled due to ENOTEMPTY errors
  • Takes precedence in PATH over any native installation

Solution

Step 1: Check Current Installation

which claude
# Likely shows: /opt/homebrew/bin/claude

ls -la /opt/homebrew/lib/node_modules/@anthropic-ai/
# Shows broken claude-code directories

Step 2: Remove Broken npm Installation

# Remove all Claude-related files from npm
rm -rf /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code
rm -rf /opt/homebrew/lib/node_modules/@anthropic-ai/.claude-code-*
rm -f /opt/homebrew/bin/claude

# Clear npm cache
npm cache clean --force

Step 3: Install Using Native Installer

# Use Anthropic's official installer (no sudo required)
curl -fsSL https://claude.ai/install.sh | sh

Step 4: Update PATH

# Add native installation to PATH
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Step 5: Verify Installation

# Check which claude is being used
which claude
# Should show: /Users/[username]/.local/bin/claude

# Test the installation
claude --version

Why This Works

  1. Native installer bypasses npm entirely and installs to ~/.claude/local/
  2. No sudo required - installs to user's home directory
  3. Proper PATH precedence - ensures the working version is used
  4. Avoids npm issues - no ENOTEMPTY errors or missing modules

Prevention

To avoid this issue in the future:

  • Use the native installer instead of npm: curl -fsSL https://claude.ai/install.sh | sh
  • The native installer is the officially recommended installation method by Anthropic

Additional Notes

  • This issue commonly affects macOS users with Homebrew-installed Node.js
  • The error occurs because npm creates incorrect symbolic links and has packaging issues with the yoga.wasm module
  • If you must use npm, consider configuring it to install to a user directory instead of system directories

References

---

Tested on: macOS with Homebrew, Node.js v24.5.0, npm installation of @anthropic-ai/claude-code

JPBarringer · 11 months ago

I was having issues with this on a local install and it turned out to be an incomplete install (I think the updater was breaking).

The solution, for me, was to remove the node modules folder and reinstall clean. (No history loss, this is just dependencies)

This one-liner should do it.
rm -rf ~/.claude/local/node_modules && (cd ~/.claude/local && npm install)

Or use this one from the project folder to fix the issue and continue in Claude Code
rm -rf ~/.claude/local/node_modules && (cd ~/.claude/local && npm install) && claude -c

zamson · 11 months ago

I am using nvm, and an old project had the wrong version of node

nvm use 22

solved my issue

bcherny collaborator · 10 months ago

The comments have the right solution: rm -rf the old Claude Code install, and re-install with npm i -g @anthropic-ai/claude-code.

We're actively working on moving away from NPM, because some of these install issues are inherent to NPM. Try the native binary (beta) to try this out today: https://docs.anthropic.com/en/docs/claude-code/setup#native-binary-installation-beta.

JPBarringer · 10 months ago

FWIW you don't need to remove the install, just the dependencies. I think the update is breaking somewhere and leaving things in a broken state. (Just a guess though.)

In my case, install on the existing directory was throwing this error:

~/.claude/local via  v24.5.0
❯ npm install
npm error code ENOTEMPTY
npm error syscall rename
npm error path /Users/user/.claude/local/node_modules/@anthropic-ai/claude-code
npm error dest /Users/user/.claude/local/node_modules/@anthropic-ai/.claude-code-ecmSQutl
npm error errno -66
npm error ENOTEMPTY: directory not empty, rename '/Users/user/.claude/local/node_modules/@anthropic-ai/claude-code' -> '/Users/user/.claude/local/node_modules/@anthropic-ai/.claude-code-ecmSQutl'
azz0r · 10 months ago
Same problem, solved by reinstalling node # Download and install nvm: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash # in lieu of restarting the shell . "$HOME/.nvm/nvm.sh" # Download and install Node.js: nvm install 22 # install claude npm install -g @anthropic-ai/claude-code

this resolved it for me

always-beta · 10 months ago

To solve it temporarily, I used nvm to switch to another node version and reinstalled using npm install -g @anthropic-ai/claude-code

github-actions[bot] · 10 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.