claude执行提示"Error: claude native binary not installed"

问题

mac@GaGa ~ % claude -v
Error: claude native binary not installed.

Either postinstall did not run (--ignore-scripts, some pnpm configs)
or the platform-native optional dependency was not downloaded
(--omit=optional).

## 提示很明确如何修复
Run the postinstall manually (adjust path for local vs global install):
  node node_modules/@anthropic-ai/claude-code/install.cjs

Or reinstall without --ignore-scripts / --omit=optional.

这是 @anthropic-ai/claude-code 的本地 native binary 没有正确安装。
常见原因:

  • npm install 时用了 --ignore-scripts
  • pnpm 禁止 postinstall
  • 使用了 --omit=optional
  • Apple Silicon / x64 架构不匹配
  • 全局安装残缺

1. 先确认安装方式

查看

1
2
3
4
5
6
7
8
npm list -g --depth=0 | grep claude

mac@GaGa ~ % npm list -g --depth=0 | grep claude
mac@GaGa ~ % pnpm list -g --depth=0 | grep claude
├── @anthropic-ai/claude-code@2.1.153

mac@GaGa ~ % which claude
/Users/mac/Library/pnpm/claude

2. 最直接修复(推荐)

执行官方 postinstall:

1
node $(npm root -g)/@anthropic-ai/claude-code/install.cjs

如果是 pnpm:

1
node $(pnpm root -g)/@anthropic-ai/claude-code/install.cjs

执行完成后:

1
claude -v

3. 如果还不行彻底重装

3.1npm 全局安装

1
npm uninstall -g @anthropic-ai/claude-code

重新安装:

1
npm install -g @anthropic-ai/claude-code

注意不要带:

1
2
--ignore-scripts
--omit=optional

4. pnpm 用户常见问题

很多人 .npmrc 里配置了:

1
ignore-scripts=true

检查:

1
cat ~/.npmrc

如果有:

1
ignore-scripts=true

改成:

1
ignore-scripts=false

然后:

1
pnpm add -g @anthropic-ai/claude-code

5. Apple Silicon(M1/M2/M3) 架构问题

检查架构:

1
uname -m

正常:

  • arm64 → Apple Silicon
  • x86_64 → Intel/Rosetta

再检查 Node:

1
node -p process.arch

两者最好一致。

错误场景:

系统 Node
arm64 x64

会导致 native binary 下载失败。


6. 验证 native binary 是否存在

查看:

1
2
3
ls -lah $(npm root -g)/@anthropic-ai/claude-code

ls -lah $(pnpm root -g)/@anthropic-ai/claude-code

应该能看到类似: @anthropic-ai/claude-code