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

[BUG] ✗ Auto-update failed · Try claude doctor or npm i -g @anthropic-ai/claude-code

Open walt93 opened this issue 7 months ago • 2 comments

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

  1. Run Claude Code
  2. Observe that it can't update itself
  3. Try to update it with "npm i -g @anthropic-ai/claude-code"
  4. 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

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

walt93 avatar May 07 '25 21:05 walt93

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

bradleyjames avatar Jun 17 '25 02:06 bradleyjames

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:

  1. npm creates a temporary directory (e.g., .claude-code-jtqndIsa) during the update process
  2. If the rename operation fails or is interrupted, npm doesn't clean up this temp directory
  3. 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 avatar Jun 26 '25 05:06 liby

@liby this answer worked for me, thank you!

kkukshtel avatar Aug 13 '25 03:08 kkukshtel

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.

samjm000 avatar Aug 13 '25 06:08 samjm000

This is happening everyday and results in command not found: claude Your auto-updates are breaking claude. Stop it.

deanq avatar Aug 13 '25 15:08 deanq

can't even disable auto updates :(

Image

eightnoteight avatar Aug 20 '25 03:08 eightnoteight

I am having the same issue, and was contacting the Anthropic help - the chatbot, which it gave me the following suggestions

Image
  1. i followed the instruction to use the native installer
  2. it installed a local version at my ~/.claude/local
  3. 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

  1. claude doctor is now showing that i have multiple installations. is that going to be "harmful"
  2. what is the difference between the npm global version versus the local installation
  3. how do i remove the local installation, as i prefer to stick with NPM
Image

chaihwee79 avatar Aug 28 '25 01:08 chaihwee79

anyone knows what is the difference between the local install under the ./local/share/claude versus the npm global installation?

chaihwee79 avatar Aug 30 '25 03:08 chaihwee79

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.

lee-jian-hui avatar Sep 09 '25 10:09 lee-jian-hui

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!

iwootten avatar Sep 10 '25 08:09 iwootten

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?

chaihwee79 avatar Sep 10 '25 09:09 chaihwee79

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 avatar Sep 10 '25 10:09 joelbeedle

@joelbeedle thanks a lot for the steps, i tried and it works!

chaihwee79 avatar Sep 12 '25 16:09 chaihwee79

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

Arsennikum avatar Sep 17 '25 11:09 Arsennikum

fix works, but next auto-update will fail again for me.

schneidermayer avatar Nov 27 '25 08:11 schneidermayer