[BUG] Claude command intermittently becomes unavailable ("command not found") with ENOTEMPTY errors preventing reinstallation on Ubuntu 24.04
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other:
- Claude CLI version: Unable to check -
claude --versionreturns "command not found" - Operating System: Ubuntu (Linux)
- Terminal: bash
Bug Description
Claude Code intermittently becomes unavailable with "command not found" error after previously working correctly. The issue appears related to the auto-update mechanism or crashes leaving the installation in a corrupted state. Reinstallation attempts fail with ENOTEMPTY errors.
Steps to Reproduce
- Install Claude Code:
npm install -g @anthropic-ai/claude-code - Use Claude Code normally (it works initially)
- Either: Claude crashes, auto-updates, or is exited normally
- Attempt to run
claudeagain - Receive "bash: claude: command not found" error
- Try to reinstall:
npm install -g @anthropic-ai/claude-code - Installation fails with ENOTEMPTY error
Expected Behavior
- Claude command should remain available after installation
- Reinstallation should work cleanly if needed
- Auto-updates should not break the installation
Actual Behavior
- Claude command randomly becomes unavailable
- Reinstallation fails with:
npm ERR! code ENOTEMPTY npm ERR! syscall rename npm ERR! path /home/nathank/.npm-global/lib/node_modules/@anthropic-ai/claude-code npm ERR! dest /home/nathank/.npm-global/lib/node_modules/@anthropic-ai/.claude-code-A63a10Hr npm ERR! errno -39 npm ERR! ENOTEMPTY: directory not empty, rename - Command randomly starts working again after some time
- Multiple stuck npm processes remain running
Additional Context
- npm global prefix:
/home/nathank/.npm-global - PATH includes
$HOME/.npm-global/bin - Manual cleanup required:
rm -rf ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code - Issue matches reported bug #471 affecting multiple users
- Workaround: Use full path
~/.npm-global/bin/claudeor wait for it to randomly fix itself - Shell command cache may be involved (requires
hash -rto clear)
This appears to be a systematic issue with the package's installation/update mechanism leaving directories in an inconsistent state.
This error also occurs in macOS Sequoia
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /Users/antonio/Library/Application Support/fnm/node-versions/v20.13.1/installation/lib/node_modules/@anthropic-ai/claude-code
npm ERR! dest /Users/antonio/Library/Application Support/fnm/node-versions/v20.13.1/installation/lib/node_modules/@anthropic-ai/.claude-code-w74Lbl8P
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/Users/username/Library/Application Support/fnm/node-versions/v20.13.1/installation/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/username/Library/Application Support/fnm/node-versions/v20.13.1/installation/lib/node_modules/@anthropic-ai/.claude-code-w74Lbl8P'
Got this randomly too on my dedicated server, same reproduction steps as OP
Same issue
same in ubuntu 20.04 of wsl2
This just happened to me on OSX
Hi everyone, sorry about this—it's a result of npm updates not being atomic. We are ready to start testing a new install solution that does not rely on npm at all. This is our new native builds feature. If you are brave and you feel confident debugging your system I'd love to invite you try our new install experience. When you are ready try this:
curl -fsSL claude.ai/install.sh | bash
we'll get some documentation up about this soon, but if anyone wants to test this and report back, @sid374 and I would love to hear how it goes!
Thanks for the new native installer!
One observation: the native build appears to be a few versions behind:
- npm version: 1.0.40
- native installer version: 1.0.38
❯ npm list -g @anthropic-ai/claude-code
/Users/bryan/.npm-global/lib
└── @anthropic-ai/[email protected]
❯ curl -fsSL claude.ai/install.sh | bash
Downloaded to: /Users/bryan/.claude/downloads/claude-1.0.38-darwin-arm64
Setting up Claude Code...
Setting up launcher and shell integration...
✅ Installation complete!
❯ claude --version
1.0.38 (Claude Code)
❯ which claude
/Users/bryan/.local/bin/claude
Is this version lag expected, or will both distribution methods be kept in sync going forward?
thanks for testing it! We are being a little cautious promoting native versions. we'll try to keep parity going forward though.
if you are extra brave, you can try curl -fsSL claude.ai/install.sh | bash -s latest
Update: I tried with the latest flag as you suggested:
curl -fsSL claude.ai/install.sh | bash -s latest
But now I'm seeing an even stranger issue:
❯ curl -fsSL claude.ai/install.sh | bash -s latest
Downloaded to: /Users/bryan/.claude/downloads/claude-1.0.38-darwin-arm64
Setting up Claude Code...
Setting up launcher and shell integration...
✅ Installation complete!
❯ claude --version
1.0.41 (Claude Code)
Downloaded: claude-1.0.38-darwin-arm64 (same as before)
Running claude --version: 1.0.41 (Claude Code)
This seems like the installer might be downloading a different binary than what's indicated in the filename?
Ahh yes sorry for the confusion, but what you're seeing here is actually ok. The first download is just a temporary shell and doesn't represent the final version being installed. We're going to make this less confusing.
Making liby's experience a little more confusing...
Like liby, the tool said it downloaded claude-1.0.38-darwin-arm64, and when I ran claude --version I got 1.0.41 (Claude Code). Then I ran claude, and immediately /quit. Now if I run claude --version, I get 1.0.38 (Claude Code).
Now if I run claude --version, I get 1.0.38 (Claude Code).
It was precisely this that prompted me to eventually switch back to using npm for installation.
However, I ran into an issue when trying to remove the native installation. Even after deleting:
rm ~/.local/bin/claude
rm -rf ~/.local/state/claude
Claude Code kept recreating these files on every launch, resulting in persistent "Multiple installations found" warnings.
Claude CLI Diagnostic
Currently running: unknown (1.0.44)
Path: /Users/bryan/.proto/tools/node/22.17.0/bin/node
Invoked: /Users/bryan/.npm-global/bin/claude
Auto-updates: No
Config install method: native
Config auto-updates: true
Warning: Multiple installations found
- npm-global at /Users/bryan/.npm-global/bin/claude
- native at /Users/bryan/.local/bin/claude
Press Enter to continue…
The root cause was ~/.claude.json still had "installMethod": "native". After changing it to "npm" and removing the directories again, the issue was resolved.
One remaining question: The diagnostic now shows Currently running: unknown (1.0.44) - is this "unknown" status expected for npm installations?
Claude CLI Diagnostic
Currently running: unknown (1.0.44)
Path: /Users/bryan/.proto/tools/node/22.17.0/bin/node
Invoked: /Users/bryan/.npm-global/bin/claude
Auto-updates: No
Config install method: npm
Config auto-updates: true
The "unknown" means our heuristic for figuring out if you are running the global install is incomplete. We can improve that, but this install looks healthy
Adding another issue confirmation for Ubuntu 24.04. The temporary workaround below is effective. Hope this helps others while the native installer is being finalized.
rm -rf ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code
Adding another issue confirmation for Ubuntu 24.04. The temporary workaround below is effective. Hope this helps others while the native installer is being finalized.
rm -rf ~/.npm-global/lib/node_modules/@anthropic-ai/claude-codenpm install -g @anthropic-ai/claude-code
This method work well in my Mac. Thanks!
When you are ready try this:
curl -fsSL claude.ai/install.sh | bash
I noticed that Claude Code gave a warning that the auto update failed, and provided the command to try from the CLI, which failed in the same way as the OP:
> npm update -g @anthropic-ai/claude-code
npm error code ENOTEMPTY
npm error syscall rename
npm error path /Users/mike/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code
npm error dest /Users/mike/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/.claude-code-L07bEh9A
npm error errno -66
npm error ENOTEMPTY: directory not empty, rename '/Users/mike/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/mike/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/.claude-code-L07bEh9A'
> which claude
/Users/mike/.nvm/versions/node/v22.14.0/bin/claude
> claude doctor
Claude CLI Diagnostic
Currently running: npm-global (1.0.61)
Path: /Users/mike/.nvm/versions/node/v22.14.0/bin/node
Invoked: /Users/mike/.nvm/versions/node/v22.14.0/bin/claude
Config install method: unknown
Auto-updates enabled: true
Update permissions: Yes
Press Enter to continue…
So used the new install method:
> rm -rf /Users/mike/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code
> curl -fsSL claude.ai/install.sh | bash
Setting up Claude Code...
✔ Claude Code successfully installed!
Version: 1.0.62
Location: ~/.local/bin/claude
Next: Run claude --help to get started
✅ Installation complete!
> which claude
/Users/mike/.local/bin/claude
> claude doctor
Claude CLI Diagnostic
Currently running: native (1.0.62)
Path: /Users/mike/.local/bin/claude
Invoked: /$bunfs/root/claude
Config install method: native
Auto-updates enabled: true
Press Enter to continue…
> uname -mv
Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:43 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T8132 arm64
Worked like a charm on a Mac. No issues with VSCode plugin either.
Is auto-update happening on invocation of Claude Code? I also see the update option:
> claude update
Current version: 1.0.62
Checking for updates...
Claude Code is up to date (1.0.62)
Thanks @sid374 and @wolffiex 👏🏼
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.