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

Open 💬 18 comments Opened May 7, 2025 by walt93

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

<!-- Add any other context about the problem here, such as screenshots, logs, etc. -->

View original on GitHub ↗

18 Comments

bradleyjames · 1 year ago

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
liby · 1 year ago

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.

kkukshtel · 11 months ago

@liby this answer worked for me, thank you!

samjm000 · 11 months ago

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.

deanq · 11 months ago

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

eightnoteight · 11 months ago

can't even disable auto updates :(

<img width="1298" height="387" alt="Image" src="https://github.com/user-attachments/assets/f27b1e94-d3b9-45bb-b3de-ff2479d8e388" />

chaihwee79 · 10 months ago

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

<img width="549" height="513" alt="Image" src="https://github.com/user-attachments/assets/9b95b137-4eb1-49b0-9e24-90d5be608ca1" />

  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

<img width="556" height="216" alt="Image" src="https://github.com/user-attachments/assets/1bd7bd5a-a892-4b9f-a1ae-d55fcf1314c7" />

chaihwee79 · 10 months ago

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

kyl33r · 10 months ago

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.

iwootten · 10 months ago

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!

chaihwee79 · 10 months ago

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?

joelbeedle · 10 months ago

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
chaihwee79 · 10 months ago

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

Arsennikum · 10 months ago

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

schneidermayer · 7 months ago

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

github-actions[bot] · 6 months ago

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.

mids-neo · 2 months ago

Adding a data point: this fires deterministically under a non-root TUI user when the package was installed by root (or by a different system user).

Setup: claude-code v2.1.121 installed by claude-coord:claude-coord at /opt/claude-runtime/nvm/versions/node/v22.22.1/lib/node_modules/@anthropic-ai/claude-code/. Mode 0755. We launch multiple lane TUIs via a runuser-based wrapper that drops to per-lane users (uid 9001-9005).

On startup, the TUI auto-update runs npm install --global @anthropic-ai/claude-code. npm tries to atomically swap the existing version's directory:

verbose stack Error: EACCES: permission denied, rename
   '/opt/claude-runtime/nvm/versions/node/v22.22.1/lib/node_modules/@anthropic-ai/claude-code'
   -> '/opt/claude-runtime/nvm/versions/node/v22.22.1/lib/node_modules/@anthropic-ai/.claude-code-27St6cO9'
error code EACCES
error syscall rename

Lane user (uid 9003) cannot rename in a directory owned by claude-coord:claude-coord. The TUI proceeds with the existing installed version (so functionality isn't blocked), but emits the ✗ Auto-update failed banner on every launch. Lane sessions stay on whatever version was last claude-coord-installed, while root sessions auto-update past it. Long-running version drift between users on the same machine.

This is distinct from the OP's macOS ENOTEMPTY case, but shares the same root cause class: the auto-update path doesn't account for the running user not owning the package install directory.

Possible mitigations the maintainers might consider:

  • Detect the mismatch and skip auto-update silently (or with a different banner) instead of emitting "✗ Auto-update failed" suggesting npm i -g which will also fail
  • Provide a documented DISABLE_AUTOUPDATER=1 or --no-update-check flag so multi-user setups can opt out cleanly
  • Honor a per-user fallback install location ($XDG_CACHE_HOME/claude-code/ or similar) when the system install isn't user-writable

We've worked around this by accepting the version drift in our architecture; documenting the case in case it helps prioritize one of the above.

c4lm · 1 month ago

M1 Mac MacOS Tahoe 26.3 (25D125) node v22.18.0
Had a bunch of sessions open, did not notice ✗ Auto-update failed on one of them and started new shell, had to reinstall in the end.