[BUG] Claude command intermittently becomes unavailable ("command not found") with ENOTEMPTY errors preventing reinstallation on Ubuntu 24.04
Resolved 💬 20 comments Opened Jun 6, 2025 by nkeilar Closed Jan 5, 2026
💡 Likely answer: A maintainer (wolffiex, collaborator)
responded on this thread — see the highlighted reply below.
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.
20 Comments
This error also occurs in macOS Sequoia
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:
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:
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 latestUpdate: I tried with the latest flag as you suggested:
But now I'm seeing an even stranger issue:
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 --versionI got 1.0.41 (Claude Code). Then I ranclaude, and immediately/quit. Now if I runclaude --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:
Claude Code kept recreating these files on every launch, resulting in persistent "Multiple installations found" warnings.
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?
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-codenpm install -g @anthropic-ai/claude-codeThis method work well in my Mac. Thanks!
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:
So used the new install method:
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
updateoption: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.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
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.