1. 先判断是否需要重装
认证失败、模型无权限和服务端 503 通常不是安装问题。先运行 claude --version,若命令可用,按 Claude Code 常见问题 排查。
2. 备份并核对安装来源
PowerShell
Get-Command claude -All
npm list -g @anthropic-ai/claude-code --depth=0Shell
command -v claude
npm list -g @anthropic-ai/claude-code --depth=0Shell
command -v claude
npm list -g @anthropic-ai/claude-code --depth=0备份实际 CLAUDE_CONFIG_DIR(未设置时为 .claude)及用户目录下相关配置。不要删除整个目录以解决 PATH 冲突。
3. npm 安装的版本
仅当确认原安装来自 npm 时执行:
Shell
npm uninstall -g @anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code
claude --versionWindows 的 npm.ps1 被执行策略阻止时,可使用 npm.cmd。
4. 原生安装器或其他安装来源
按 Claude Code 官方安装说明 使用对应安装方式的卸载、更新或修复步骤。不要用 npm 卸载原生版本,也不要混装多种来源。
5. 恢复与验证
- 重新打开终端,确认 claude 命令指向预期安装。
- 检查原 settings.json、插件和 MCP 是否保留;只合并必要的网关字段。
- 启动 claude,检查 /status,发送简单请求并核对本站日志。