[BUG] Auto-Update Fails and Corrupts Installation When Claude Sessions Are Running

Resolved 💬 2 comments Opened Dec 29, 2025 by broneotodak Closed Dec 29, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The Claude Code auto-updater attempts to update packages while active Claude sessions are running, causing ENOTEMPTY errors and leaving the installation in a broken state where the claude binary becomes
inaccessible. Users cannot start new Claude sessions until manual reinstall.

What Should Happen?

  • Auto-updater should detect running Claude sessions and defer update
  • OR auto-updater should gracefully handle locked files without corrupting installation
  • Running sessions should continue working AND new sessions should be startable

Error Messages/Logs

npm error code ENOTEMPTY
  npm error syscall rename
  npm error path /Users/broneotodak/.claude/local/node_modules/@anthropic-ai/claude-code
  npm error dest /Users/broneotodak/.claude/local/node_modules/.package-lock.json...
  npm error errno -66
  npm error ENOTEMPTY: directory not empty, rename '/Users/broneotodak/.claude/local/node_modules/@anthropic-ai/claude-code' -> ...
 Terminal error when trying to start new session:
  /Users/broneotodak/.claude/local/node_modules/.bin/claude: No such file or directory

Steps to Reproduce

  1. Install Claude Code via npm in ~/.claude/local/
  2. Start one or more Claude Code sessions (e.g., claude command in terminal)
  3. Keep sessions running for extended period (hours)
  4. Auto-updater triggers in background (likely via postinstall script or background check)
  5. Open a new terminal and run claude
  6. Observe error: "/Users/[user]/.claude/local/node_modules/.bin/claude: No such file or directory"
  7. Note: Running sessions continue to work (code already in memory)

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

2.0.43

Claude Code Version

2.0.76 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Root Cause Analysis:
The auto-update mechanism doesn't check for or handle:

  1. Running Claude processes that have files open/locked
  2. The atomicity requirement of npm package updates
  3. Graceful degradation when update fails

Suggested Fixes:

  1. Check for running processes before update (use pgrep or check for open file handles)
  2. Implement update queue - if sessions are running, queue update for when all sessions close
  3. Add rollback mechanism - if update fails mid-way, restore previous working state
  4. User notification - alert user that update is pending and requires session restart
  5. Lock file mechanism - use a lock file to prevent concurrent updates

Workaround:
rm -rf ~/.claude/local/node_modules/@anthropic-ai
cd ~/.claude/local && npm install @anthropic-ai/claude-code

Impact:

  • Severity: Medium-High
  • User Impact: Cannot start new Claude sessions until manual reinstall
  • Data Loss: None (running sessions survive, work is preserved)

Additional context:

  • User had 2 Claude sessions running when this occurred
  • Both running sessions continued to work normally (code in memory)
  • Only new session attempts failed
  • Issue discovered when user tried to open third terminal with claude command

View original on GitHub ↗

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