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

·Matija Žiberna·
How to Fix Claude Code Failed to Auto-Update on macOS Sonoma (ENOTEMPTY npm Error)

📚 Get Practical Development Guides

Join developers getting comprehensive guides, code examples, optimization tips, and time-saving prompts to accelerate their development workflow.

No spam. Unsubscribe anytime.

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

  1. Remove the existing Claude Code folder

    rm -rf /Users/$(whoami)/.npm-global/lib/node_modules/@anthropic-ai/claude-code
    
  2. Clear the npm cache

    npm cache clean --force
    
  3. 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

10

Comments

Leave a Comment

Your email will not be published

10-2000 characters

• Comments are automatically approved and will appear immediately

• Your name and email will be saved for future comments

• Be respectful and constructive in your feedback

• No spam, self-promotion, or off-topic content

Matija Žiberna
Matija Žiberna
Full-stack developer, co-founder

I'm Matija Žiberna, a self-taught full-stack developer and co-founder passionate about building products, writing clean code, and figuring out how to turn ideas into businesses. I write about web development with Next.js, lessons from entrepreneurship, and the journey of learning by doing. My goal is to provide value through code—whether it's through tools, content, or real-world software.

You might be interested in