`claude update` fails with generic error when stale temp directory exists from previous failed update
AI Assistant:
Preflight Checklist
- [x] I have searched existing issues and this is not a duplicate
- [x] I am filing a single bug per report
- [x] I am using the latest version of Claude Code
What's Wrong?
When claude update or auto-update fails (e.g., due to disk space exhaustion), it leaves stale temp directories in the npm package location. Subsequent update attempts fail with a generic error message:
Error: Failed to install update
Or consider using native installation with: claude install
The actual underlying error (ENOTEMPTY from npm) is not shown to the user, and there's no guidance on how to resolve the issue.
What Should Happen?
- The actual error should be displayed (e.g., "ENOTEMPTY: stale temp directory from previous failed update")
- Recovery guidance should be provided (e.g., "Remove stale directory and retry:
rm -rf ~/.config/npm-global/lib/node_modules/@anthropic-ai/.claude-code-*") - Ideally, Claude should detect and clean up stale temp directories before attempting an update
Steps to Reproduce
- Install Claude Code via npm:
npm install -g @anthropic-ai/claude-code - Fill disk to 0% free space (or simulate disk exhaustion)
- Let auto-update attempt to run (or run
claude update) - The update will fail and leave a stale temp directory like
.claude-code-hubQN3oG - Free disk space
- Try
claude updateagain - Observe: Generic "Failed to install update" error with no actionable information
Is this a regression?
This never functioned - the error handling has always been generic for npm update failures.
Claude Code Version
2.1.11 (Claude Code)
(Bug was observed on 2.1.9, fixed by manual intervention, now running 2.1.11)
Platform
Anthropic API (Claude Max subscription)
Operating System
Arch Linux (Kernel 6.17.3-arch2-1) on ThinkPad T490
Terminal/Shell
- Bash 5.x
- tmux 3.x
Error Messages/Logs
From claude update:
Current version: 2.1.9
Checking for updates to latest version...
New version available: 2.1.11 (current: 2.1.9)
Installing update...
Using global installation update method...
Error: Failed to install update
Or consider using native installation with: claude install
Actual npm error (from npm update -g @anthropic-ai/claude-code):
npm error code ENOTEMPTY
npm error syscall rename
npm error path /home/user/.config/npm-global/lib/node_modules/@anthropic-ai/claude-code
npm error dest /home/user/.config/npm-global/lib/node_modules/@anthropic-ai/.claude-code-hubQN3oG
npm error errno -39
npm error ENOTEMPTY: directory not empty, rename '.../@anthropic-ai/claude-code' -> '.../.claude-code-hubQN3oG'
Directory state showing stale temp directory:
~/.config/npm-global/lib/node_modules/@anthropic-ai/
├── claude-code/ # Current install
├── .claude-code-hubQN3oG/ # STALE temp dir from failed update
└── sandbox-runtime/
Additional Information
Root cause chain:
- Home directory ran out of space (0% free)
- Auto-update attempted and failed mid-operation
- npm tried to rename old package directory before installing new version
- Rename failed, leaving stale
.claude-code-*directory - All subsequent updates fail because destination directory already exists
Workaround (manual fix):
rm -rf ~/.config/npm-global/lib/node_modules/@anthropic-ai/.claude-code-*
npm cache clean --force
npm install -g @anthropic-ai/claude-code@latest --force
hash -r # Clear bash hash table
Suggested improvements:
- Surface the actual npm error to users instead of generic message
- Detect stale
.claude-code-*directories and offer to clean them up - Add retry logic after initial failure when conditions (disk space) improve
- Document this failure mode in troubleshooting docs
npm configuration in ~/.bashrc (Linux, user-writable prefix, no sudo required):
# In ~/.bashrc
export npm_config_prefix="$HOME/.config/npm-global"
export PATH="$HOME/.config/npm-global/bin:$PATH"This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗