claude-code
claude-code copied to clipboard
[BUG] ✗ Auto-update failed · Try claude doctor or npm i -g @anthropic-ai/claude-code
Environment
- Platform (select one):
- [√ Anthropic API
- Claude CLI version: 0.2.61 (Claude Code)
- Operating System: Mac OS 15.3
- Terminal: IntelJIdea 2023.1.1
Bug Description
Auto update does not work.
Specified instructions for update do not work.
Only solution has been to completely delete the claude code directory.
Steps to Reproduce
- Run Claude Code
- Observe that it can't update itself
- Try to update it with "npm i -g @anthropic-ai/claude-code"
- Observe it fail:
% npm i -g @anthropic-ai/claude-code
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /Users/walt/.nvm/versions/node/v18.18.0/lib/node_modules/@anthropic-ai/claude-code
npm ERR! dest /Users/walt/.nvm/versions/node/v18.18.0/lib/node_modules/@anthropic-ai/.claude-code-Mnsj2ANr
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/Users/walt/.nvm/versions/node/v18.18.0/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/walt/.nvm/versions/node/v18.18.0/lib/node_modules/@anthropic-ai/.claude-code-Mnsj2ANr'
npm ERR! A complete log of this run can be found in: /Users/walt/.npm/_logs/2025-05-07T21_04_49_796Z-debug-0.log
- Try the suggested "claude doctor" and observe as it think it succeeds:
% claude doctor
✓ npm permissions: OK
Your installation is healthy and ready for auto-updates.
You can also install Claude Code locally to avoid npm permission issues using the slash command:
/migrate-installer
Press Enter to continue…
Expected Behavior
The update to work
Actual Behavior
The update failed
Additional Context
I received the same error message today and now claude won't run at all. claude doctor results in the same error.
$ claude
node:internal/modules/cjs/loader:995
const err = new Error(message);
^
Error: Cannot find module './yoga.wasm'
Require stack:
- /Users/bradreynolds/.nvm/versions/node/v18.11.0/lib/node_modules/@anthropic-ai/claude-code/cli.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Function.resolve (node:internal/modules/cjs/helpers:109:19)
at file:///Users/bradreynolds/.nvm/versions/node/v18.11.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:665:22850
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/bradreynolds/.nvm/versions/node/v18.11.0/lib/node_modules/@anthropic-ai/claude-code/cli.js'
]
}
Node.js v18.11.0
$ npm i -g @anthropic-ai/claude-code
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /Users/bradreynolds/.nvm/versions/node/v18.11.0/lib/node_modules/@anthropic-ai/claude-code
npm ERR! dest /Users/bradreynolds/.nvm/versions/node/v18.11.0/lib/node_modules/@anthropic-ai/.claude-code-mGu8LTeU
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/Users/bradreynolds/.nvm/versions/node/v18.11.0/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/bradreynolds/.nvm/versions/node/v18.11.0/lib/node_modules/@anthropic-ai/.claude-code-mGu8LTeU'
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/bradreynolds/.npm/_logs/2025-06-17T02_36_00_116Z-debug-0.log
This looks more like a known npm error rather than a Claude Code issue. The ENOTEMPTY error occurs when npm fails to clean up temporary directories during package updates.
What's happening:
- npm creates a temporary directory (e.g.,
.claude-code-jtqndIsa) during the update process - If the rename operation fails or is interrupted, npm doesn't clean up this temp directory
- Subsequent installation attempts fail because npm tries to use the same temp directory name
Evidence:
- This exact issue is documented in npm/cli#4096 for TypeScript and other packages
- The error pattern is consistent:
ENOTEMPTY: directory not empty, rename ... - Still present in npm v10.9.2
Solution:
Remove the leftover temporary directory:
# Check for temp directories
ls -la /Users/<username>/.npm-global/lib/node_modules/@anthropic-ai/ | grep claude
# Remove any directories starting with a dot (e.g., .claude-code-jtqndIsa)
rm -rf /Users/<username>/.npm-global/lib/node_modules/@anthropic-ai/.claude-code-*
# Retry the installation
npm install -g @anthropic-ai/claude-code@latest
For Windows users:
Replace the paths with your npm global directory (check with npm config get prefix).
This workaround resolves the immediate issue, but the underlying npm bug remains unfixed.
@liby this answer worked for me, thank you!
I used /migrate-installer which seemed to work - I interrogated the problem with claude and ut said the error occurs because npm can't rename the existing claude-code directory during the update process. You can set up a local installation that avoids these npm global installation conflicts:
The "/migrate-installer" from claude code as it seems to be Anthropic's recommended solution for avoiding these npm-related update issues.
This is happening everyday and results in command not found: claude
Your auto-updates are breaking claude. Stop it.
can't even disable auto updates :(
I am having the same issue, and was contacting the Anthropic help - the chatbot, which it gave me the following suggestions
- i followed the instruction to use the native installer
- it installed a local version at my ~/.claude/local
- i had update the PATH parameter
however, when i was using the usual VS code plugin, the claude code command box is still showing the "auto-update failed, try claude doctor or npm i -g @anthropic-ai/claude-code
now my actual questions are
- claude doctor is now showing that i have multiple installations. is that going to be "harmful"
- what is the difference between the npm global version versus the local installation
- how do i remove the local installation, as i prefer to stick with NPM
anyone knows what is the difference between the local install under the ./local/share/claude versus the npm global installation?
hi! for me, i faced the same error but my claude works fine, just an annoying notification that i treat.
I sovled it by using sudo to repeat the installation command again as certain npm installation steps required root access, this is probably not the best way though.
The solution posted by @liby worked for me - but because I was using nvm, the dir that needed removing was elsewhere. Found it like this:
ls -la /Users/<username>/.nvm/versions/node/<version>/lib/node_modules/@anthropic-ai | grep claude
After removing the one with a dot prefix, auto-update finally works again!
for my case, i use the VS code with Claude Code plug in,
it used to be - when VS code prompted me there is an update for claude code, i will let it run on "auto-update" but now - i have to manually remove the folder - /Users/hwee/.nvm/versions/node/v23.11.0/bin/claude
then run the npm update instruction. it is particularly annoying when i need to perform manual step. anyone knows what is the permenent solution?
A generic copy-pastable version of @liby's solution that would also work for most other setups like @iwootten's is:
- List any claude-related dirs under your npm global prefix
ls -la "$(npm prefix -g)/lib/node_modules/@anthropic-ai" | grep claude
- Remove any leftover temp dirs like .claude-code-*
rm -rf "$(npm prefix -g)/lib/node_modules/@anthropic-ai/.claude-code-"*
- Reinstall fresh
npm install -g @anthropic-ai/claude-code@latest
@joelbeedle thanks a lot for the steps, i tried and it works!
For me problem was with a permission and it works this way:
Install without sudo by changing global prefix
If you don’t want to use sudo, configure npm to install globals into your home directory:
mkdir -p ~/.npm-global/bin
npm config set prefix ~/.npm-global
export PATH=$HOME/.npm-global/bin:$PATH
Tip: You can add that last export line into ~/.bashrc or ~/.zshrc.
Now reinstall again:
- Remove current installation
sudo npm remove -g @anthropic-ai/claude-code@joelbeedle steps: - List any claude-related dirs under your npm global prefix
ls -la "$(npm prefix -g)/lib/node_modules/@anthropic-ai" | grep claude - Remove any leftover temp dirs like .claude-code-*
rm -rf "$(npm prefix -g)/lib/node_modules/@anthropic-ai/.claude-code-"* - And finaly installing:
npm install -g @anthropic-ai/claude-code@latest
fix works, but next auto-update will fail again for me.