[Bug] Auto-update fails with npm ENOTEMPTY rename error
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 13 comments · opened Sep 10, 2025 · closed Feb 11, 2026
Bug Description
I keep getting auto-update errors. When I quit and attempt to do the update myself, it fails because of some kind of corruption of the global npm package install. I then have to manually delete the entire package and do a fresh install.
This is the message I get in the Claude Code terminal at the bottom in red text:
✗ Auto-update failed · Try claude doctor or npm i -g
@anthropic-ai/claude-code
This is the error I get when I exit and attempt to update manually:
❯ npm i -g @anthropic-ai/claude-code
npm error code ENOTEMPTY
npm error syscall rename
npm error path /Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code
npm error dest /Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/.claude-code-0ePLndiR
npm error errno -66
npm error ENOTEMPTY: directory not empty, rename '/Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/.claude-code-0ePLndiR'
npm error A complete log of this run can be found in: /Users/willd/.npm/_logs/2025-09-10T00_42_19_467Z-debug-0.log
It only works again if it rm -rf the claude-code package directory and then run a fresh install.
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 1.0.109
- Feedback ID: d27b86f3-3c19-4ec8-8f2f-25c081fd7abe
Errors
[{"error":"Error: Request was aborted.\n at i61._createMessage (file:///Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:971:7955)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","timestamp":"2025-09-10T00:03:30.151Z"},{"error":"SyntaxError: Unexpected token 'I', \"I apologiz\"... is not valid JSON\n at JSON.parse (<anonymous>)\n at file:///Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:733:9932\n at Q (file:///Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:713:13288)\n at at2 (file:///Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1095:1982)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","timestamp":"2025-09-10T00:19:44.828Z"},{"error":"Error: Failed to install new version of claude: npm error code ENOTEMPTY\nnpm error syscall rename\nnpm error path /Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code\nnpm error dest /Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/.claude-code-0ePLndiR\nnpm error errno -66\nnpm error ENOTEMPTY: directory not empty, rename '/Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/.claude-code-0ePLndiR'\nnpm error A complete log of this run can be found in: /Users/<username_redacted>/.npm/_logs/2025-09-10T00_28_21_539Z-debug-0.log\n at IG1 (file:///Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1612:393)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async Object.current (file:///Users/<username_redacted>/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3563:12159)","timestamp":"2025-09-10T00:28:22.061Z"}]
13 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
The bot is generating broken links.
It is using
anthropic-aias the organization, but it should beanthropicsRoot Cause Analysis & Permanent Fix
I've experienced this exact same issue and conducted a thorough investigation. Here's the root cause and permanent solution:
Root Cause
The ENOTEMPTY error occurs because auto-updates attempt to run while Claude Code is actively running, causing file locks that prevent npm from renaming the installation directory.
Technical sequence:
/node_modules/@anthropic-ai/claude-code→/.claude-code-[randomstring]ENOTEMPTYEvidence
From npm debug logs, the failure happens at the rename step:
Permanent Solution
The issue requires process-aware updates. I've implemented this fix:
1. Disable problematic auto-updates:
2. Create safe update script:
3. Weekly maintenance instead of daily failures:
Use controlled updates that properly handle process termination.
Environment Details
Recommended Fix for Maintainers
Auto-updates should:
This is a common issue with self-updating applications and needs special handling to avoid file lock conflicts.
After implementing the above solution, the daily auto-update failures completely stopped.
For me I had to
rm -rf ~/.npm/_npx, as I was using it with Vibe Kanban, which invokesnpxdirectlyThat's now how file locking on Unix works. Deleting (or equivalently atomically replacing) files or directories with open file descriptors is not an issue, and is in fact how updates are often handled.
Checking for running processes of the application to be updated is still a good idea, but is only required if it doesn't open all resource files it needs at startup time. If it's not done, there might be issues with currently running instances, but never with the update process itself.
ENOTEMPTY happens when trying to delete a non-empty directory or when trying to replace a non-empty directory with another.
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.
Still relevant
Same for me:
Still having this issue. Deleting temp files and terminating all running claude instances worked.
I dont know if its been fixed in latest version(since the bug is still up). As Teo added,Fix is to add process-aware updates that:
Additional Data Point: Complete Package Corruption with Multiple Concurrent Instances
cc @bcherny - this is a significant issue affecting users running multiple Claude Code instances.
Environment
npm install -g @anthropic-ai/claude-codeWhat Happened
The
@anthropic-ai/claude-codenpm package was completely corrupted - not just a failed update, but the entire package contents were wiped. Onlynode_modules/andvendor/subdirectories remained;cli.js,package.json, and all other files were deleted.Root Cause Analysis
Multiple concurrent Claude instances were running (6+ instances, some from days/weeks ago that were never closed). The npm debug logs show TWO simultaneous
npm install --global @anthropic-ai/claude-codecommands at the exact same timestamp:This happened twice within 30 minutes (at 20:04 and again at 20:34), with concurrent installs each time.
The Race Condition
npm install -g @anthropic-ai/claude-codesimultaneouslyReproduction Steps
Workaround Applied
Disabled auto-updates to prevent race condition:
Suggested Fix
This is the same underlying issue as #14100 (concurrent instance race condition) but with a more severe outcome (complete package corruption vs version downgrade).
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.