目次
はじめに
Claude Codeを利用中にwarnが表示されたため、claude doctorコマンドを実行したところ、npmの権限に関するエラーが発生しました。
同じ問題に遭遇している方のために、その解決手順を記録します。
エラーの詳細
利用していたディレクトリでnpmの権限が適切に設定されていないことが原因でした。
npm permission issues detected Claude Code can't update itself because it doesn't have sufficient global npm permissions. You have two options: Option 1: Use local installation (recommended) Install Claude Code to your home directory using the slash command: /migrate-installer This method doesn't require global npm permissions. Option 2: Fix npm permissions Visit our troubleshooting guide (https://docs.anthropic.com/s/claude-code-auto-updater) to learn how to fix npm permission issues. Press Enter to continue… Current npm prefix: /usr/local
解決手順
ステップ1: migrate-installerの実行エラーメッセージに従って/migrate-installerを実行します。
実行後、以下のような警告が表示されますが、これは正常な動作です。
claude ╭───────────────────────────────────────────────────╮ │ ✻ Welcome to Claude Code! │ │ │ │ /help for help, /status for your current setup │ │ │ │ cwd: /Users/username/project-name/ │ ╰───────────────────────────────────────────────────╯ What's new: • Streamable HTTP MCP servers are now supported • Remote MCP servers (SSE and HTTP) now support OAuth • MCP resources can now be @-mentioned • Slash commands: moved "project" and "user" prefixes to descriptions • Slash commands: improved reliability for command discovery ! Could not remove global installation The local installation is installed, but we couldn't remove the global npm package automatically. You can remove it manually later with: npm uninstall -g --force @anthropic-ai/claude-code Press Enter to continue or Esc to exit
以下のコマンドを順番に実行します。
# 古いグローバルインストールを削除 sudo npm uninstall -g --force @anthropic-ai/claude-code PATHを設定(zshを使用している場合) echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.zshrc source ~/.zshrc bashを使用している場合は以下を実行 echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc source ~/.bashrc
claude doctor
正常に動作している場合、以下のような出力が表示されます。
✓ Local installation: OK You are running Claude Code from your local installation (~/.claude/local). This installation method does not depend on global npm permissions. If auto-updates aren't working, you can force update with: cd ~/.claude/local && npm update @anthropic-ai/claude-code Press Enter to continue…
補足:他の解決方法
もしローカルインストールではなく、npm権限を修正したい場合は、以下の方法もあります。
# グローバルパッケージ用のディレクトリを作成 mkdir -p ~/.npm-global npmの設定を変更 npm config set prefix ~/.npm-global PATHを設定 echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc source ~/.zshrc Claude Codeを再インストール npm install -g @anthropic-ai/claude-code
最後に
npm系の権限エラーは厄介な問題ですが、適切な手順で解決できます。
最近は長らくCursor派でしたが、Claude Codeも併用するようになりました。
「Claude Code最強!」という声もありますが、個人的には複数のツールを使い分けることで、より効率的な開発が可能だと感じています。
私の最近の開発スタイルは、Claude Codeでバックエンドを作成し、フロントエンドのUIはGeminiに任せて、その間にテストやタスクの整理、設計書の作成を私自身が行うという流れです。
以上、どなたかのお役に立てばHappyです。