0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Codeのアップデートに失敗する場合の対処法

Last updated at Posted at 2025-11-13

結論

💡
Claude Codeのupdate時に残ったゴミファイル(node_modules/@anthropic-ai/.claude-code-*)を消せばOK
aliasを設定しておくと楽にupdateできるかもという例

.zshrc
alias claude-update='NODE_VERSION=$(node -v | sed "s/v//") && rm -rf "$HOME/.anyenv/envs/nodenv/versions/$NODE_VERSION/lib/node_modules/@anthropic-ai/.claude-code-"* && npm update -g @anthropic-ai/claude-code'

この記事の対象者

  • anyenvやnodenvを使っている
    • nodenv以外でも発生するらしい
  • claude codeのupdateが毎度うまくいかない人むけ

背景

npm update -g @anthropic-ai/claude-code がエラーになる。

→ npm update -g @anthropic-ai/claude-code
**npm** error code ENOTEMPTY
**npm** error syscall rename
**npm** error path /Users/username/.anyenv/envs/nodenv/versions/24.1.0/lib/node_modules/@anthropic-ai/claude-code
**npm** error dest /Users/username/.anyenv/envs/nodenv/versions/24.1.0/lib/node_modules/@anthropic-ai/.claude-code-ov5JJO7q
**npm** error errno -66
**npm** error ENOTEMPTY: directory not empty, rename '/Users/username/.anyenv/envs/nodenv/versions/24.1.0/lib/node_modules/@anthropic-ai/claude-code' -> '/Users/username/.anyenv/envs/nodenv/versions/24.1.0/lib/node_modules/@anthropic-ai/.claude-code-ov5JJO7q'
**npm** error A complete log of this run can be found in: /Users/username/.npm/_logs/2025-11-13T04_46_02_787Z-debug-0.log

やったこと

.zshrcに aliasを設定した。
もちろん削除しての再インストールなので成功するがもっといい方法はないかなと。

alias claude-reinstall='NODE_VERSION=$(node -v | sed "s/v//") && CLAUDE_DIR="$HOME/.anyenv/envs/nodenv/versions/$NODE_VERSION/lib/node_modules/@anthropic-ai/claude-code" && echo "[Claude] Removing $CLAUDE_DIR..." && rm -rf "$CLAUDE_DIR" && echo "[Claude] Installing @anthropic-ai/claude-code globally..." && npm install -g @anthropic-ai/claude-code && echo "[Claude] 再インストール完了しました"’

Claude Code自身が導いた答え

前回のアップデート失敗時に残った一時ファイルが原因でした。npmのリネーム処理が途中で中断されたため、.claude-code-ov5JJO7qというゴミファイルが残り、次回のアップデート時に「ディレクトリが空でない」エラーを引き起こしていたんですね。

rm -rf $HOME/.anyenv/envs/nodenv/versions/24.1.0/lib/node_modules/@anthropic-ai/.claude-code-*

これをするだけでupdateできる。なのでalias変更する

alias claude-update='NODE_VERSION=$(node -v | sed "s/v//") && rm -rf "$HOME/.anyenv/envs/nodenv/versions/$NODE_VERSION/lib/node_modules/@anthropic-ai/.claude-code-"* && npm update -g @anthropic-ai/claude-code'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?