Auto-update fails repeatedly with ENOTEMPTY error on macOS with nvm

Open 💬 4 comments Opened Nov 20, 2025 by david-gethers-cityblock

Environment

  • OS: macOS (Darwin 24.6.0)
  • Node Version: v22.10.0
  • npm Version: 10.9.0
  • Node Manager: nvm
  • Claude Code Version: 2.0.46 → 2.0.47 (failing to update)
  • Installation Path: ~/.nvm/versions/node/v22.10.0/lib/node_modules/@anthropic-ai/claude-code

Description

Claude Code's auto-update mechanism repeatedly fails with an ENOTEMPTY error when attempting to update from version 2.0.46 to 2.0.47. Each failed update leaves behind a stale temporary directory (.claude-code-euxhxob3), which prevents all subsequent auto-update attempts from succeeding.

This results in the constant error message: **"auto-update failed try claude doctor"*

Error Message

npm error code ENOTEMPTY
npm error syscall rename
npm error path /Users/[username]/.nvm/versions/node/v22.10.0/lib/node_modules/@anthropic-ai/claude-code
npm error dest /Users/[username]/.nvm/versions/node/v22.10.0/lib/node_modules/@anthropic-ai/.claude-code-euxhxob3
npm error errno -66
npm error ENOTEMPTY: directory not empty, rename '.../@anthropic-ai/claude-code' -> '.../@anthropic-ai/.claude-code-euxhxob3'

Reproduction Steps

  1. Install Claude Code via npm on macOS with nvm
  2. Launch Claude Code (which triggers auto-update check)
  3. When a new version is available, the auto-updater attempts to update in the background
  4. The update fails, leaving a .claude-code-* temp directory
  5. All subsequent auto-update attempts fail with ENOTEMPTY error
  6. User sees "auto-update failed * try claude doctor" message constantly

Root Cause Analysis

  1. npm's atomic update strategy tries to rename the existing installation to a temp directory
  2. The temp directory name appears to be static/deterministic (.claude-code-euxhxob3)
  3. When the first update fails, the temp directory persists
  4. Subsequent attempts try to use the same temp directory name, resulting in ENOTEMPTY
  5. Contributing factors:
  • macOS extended attributes (com.apple.provenance) on the installation
  • Large installation size (90MB)
  • Possible file handles from running Claude Code process
  • npm's atomic rename operation failing mid-transaction

Workaround

# Remove stale temp directory
rm -rf ~/.nvm/versions/node/*/lib/node_modules/@anthropic-ai/.claude-code-*

# Update manually
npm update -g @anthropic-ai/claude-code

# Or disable auto-updates
export DISABLE_AUTOUPDATER=1

Suggested Fixes

  1. Use unique temp directory names (timestamp-based) instead of static names
  2. Clean up stale temp directories before attempting update
  3. Add error handling to retry with a different temp directory name if ENOTEMPTY occurs
  4. Gracefully degrade by notifying user and suggesting manual update instead of repeatedly failing silently
  5. Check for running processes before attempting update

Impact

  • User constantly sees "auto-update failed" error messages
  • Auto-update mechanism becomes permanently broken until manual intervention
  • Likely affects nvm users on macOS (and possibly other Node version managers)

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗