claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Claude command intermittently becomes unavailable ("command not found") with ENOTEMPTY errors preventing reinstallation on Ubuntu 24.04

Open nkeilar opened this issue 6 months ago • 5 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude CLI version: Unable to check - claude --version returns "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

  1. Install Claude Code: npm install -g @anthropic-ai/claude-code
  2. Use Claude Code normally (it works initially)
  3. Either: Claude crashes, auto-updates, or is exited normally
  4. Attempt to run claude again
  5. Receive "bash: claude: command not found" error
  6. Try to reinstall: npm install -g @anthropic-ai/claude-code
  7. 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/claude or wait for it to randomly fix itself
  • Shell command cache may be involved (requires hash -r to clear)

This appears to be a systematic issue with the package's installation/update mechanism leaving directories in an inconsistent state.

nkeilar avatar Jun 06 '25 00:06 nkeilar

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'

antmoro avatar Jun 06 '25 12:06 antmoro

Got this randomly too on my dedicated server, same reproduction steps as OP

Asentrixx avatar Jun 09 '25 12:06 Asentrixx

Same issue

zeocax avatar Jun 19 '25 04:06 zeocax

same in ubuntu 20.04 of wsl2

nowhereman1999 avatar Jun 24 '25 13:06 nowhereman1999

This just happened to me on OSX

perryn avatar Jul 01 '25 00:07 perryn

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!

wolffiex avatar Jul 02 '25 04:07 wolffiex

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?

liby avatar Jul 02 '25 15:07 liby

thanks for testing it! We are being a little cautious promoting native versions. we'll try to keep parity going forward though.

wolffiex avatar Jul 02 '25 16:07 wolffiex

if you are extra brave, you can try curl -fsSL claude.ai/install.sh | bash -s latest

wolffiex avatar Jul 03 '25 00:07 wolffiex

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?

liby avatar Jul 03 '25 01:07 liby

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.

sid374 avatar Jul 03 '25 01:07 sid374

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).

brentlemons avatar Jul 09 '25 00:07 brentlemons

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

liby avatar Jul 09 '25 02:07 liby

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

wolffiex avatar Jul 09 '25 17:07 wolffiex

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

joseporiolcarne avatar Jul 13 '25 21:07 joseporiolcarne

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

This method work well in my Mac. Thanks!

Williamleejx avatar Jul 17 '25 15:07 Williamleejx

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 👏🏼

MGreenZ avatar Jul 29 '25 10:07 MGreenZ

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.

github-actions[bot] avatar Dec 03 '25 10:12 github-actions[bot]