How to Fix Claude Code Failed to Auto-Update on macOS Sonoma (ENOTEMPTY npm Error)
Resolve npm ENOTEMPTY rename errors during global updates by clearing old installs and cache

📚 Get Practical Development Guides
Join developers getting comprehensive guides, code examples, optimization tips, and time-saving prompts to accelerate their development workflow.
I recently ran into an annoying issue while trying to upgrade the Claude Code CLI on macOS Sonoma. Instead of updating, npm threw this error:
npm error code ENOTEMPTY
npm error syscall rename
npm error path /Users/username/.npm-global/lib/node_modules/@anthropic-ai/claude-code
npm error dest /Users/username/.npm-global/lib/node_modules/@anthropic-ai/.claude-code-XXXXXX
npm error errno -66
npm error ENOTEMPTY: directory not empty, rename ...
If Claude Code says it failed to auto-update on macOS Sonoma, this is likely the exact error you’re seeing.
Why this happens
The problem isn’t Claude itself but npm on macOS. During a global install or upgrade, npm tries to rename the existing claude-code
folder to a temporary one. If any leftover files (or even hidden macOS files like .DS_Store
) remain, npm can’t finish the rename, and the install fails.
Step-by-step fix
-
Remove the existing Claude Code folder
rm -rf /Users/$(whoami)/.npm-global/lib/node_modules/@anthropic-ai/claude-code
-
Clear the npm cache
npm cache clean --force
-
Reinstall Claude Code globally
npm i -g @anthropic-ai/claude-code
That’s it — the install should now complete cleanly.
Alternative: Skip the global install
If you’d rather not deal with global installs (and their conflicts), you can just run Claude Code with npx
:
npx @anthropic-ai/claude-code
This always pulls the latest version and avoids the global node_modules
mess.
Conclusion
If you see the Claude Code failed to auto-update error on macOS Sonoma with ENOTEMPTY
, the fix is straightforward: delete the old install, clear the cache, and reinstall. The issue comes from npm’s handling of leftover directories on macOS, not from Claude itself.
Let me know in the comments if you’ve hit other upgrade quirks, and subscribe for more practical dev fixes.
Thanks, Matija