用 strings + grep 验证 Claude Code 跑的是 Rust 版 Bun · 干货攻略
- 链接: https://x.com/simonw/status/2078692298301587758
- 分类: x-tips
- 来源: X @simonw
- 作者: Jay
- 更新: 2026-09-05
这是什么
一条朴素的二进制考古技巧:用 strings 和 grep 从 Claude Code 的可执行文件中挖出它内置 Bun 运行时的版本号,从而确认 Claude Code 已经切换到 Rust 重写的 Bun(v1.4.0)而非旧的 Zig 版。
核心两行命令:
# 方法一:直接搜字符串
strings ~/.local/bin/claude | grep -m1 'Bun v1'
# 方法二:用 BUN_OPTIONS=--preload 注入脚本读版本
cat > /tmp/bun-version.ts <<'EOF'
console.log("embedded bun:", Bun.version);
process.exit(0);
EOF
BUN_OPTIONS="--preload=/tmp/bun-version.ts" claude --version
方法一输出类似 Bun v1.4.0 (macOS arm64),方法二直接打印 1.4.0。
为什么值得关注
2026 年 5 月,Bun 完成了从 Zig 到 Rust 的 rewrite——这是 JavaScript 运行时领域一次罕见的大规模重写。Jarred Sumner 在官方博客中透露,Claude Code v2.1.181(2026 年 6 月 17 日发布)已开始使用 Rust 版 Bun,Linux 冷启动提速约 10%。
simonw 的这条技巧妙在零依赖、零工具链:任何人都可以用系统自带的 strings 做到。它本质上是一种"二进制考古"——不依赖源码、不需要反编译器,仅靠可读字符串直接定位关键信息。
核验过程
| 来源 | 关键说法 | 核验结论 |
|---|---|---|
| bun.com/blog/bun-in-rust(官方博客,Jarred Sumner) | "Claude Code v2.1.181 and later use the Rust port of Bun. Startup got 10% faster on Linux" | ✅ 确认 |
| bun.com/blog/bun-v1.4(官方博客) | "Bun is now written in Rust - Bun v1.4.0 is the first version written in Rust" | ✅ 确认 |
| bun.com/docs/runtime/environment-variables(官方文档) | BUN_OPTIONS prepends command-line arguments; --preload runs scripts at startup |
✅ 确认 |
| simonwillison.net/2026/Jul/19(simonw 博客) | 两条验证命令均有效;输出 Bun v1.4.0 |
✅ 复现有效 |
| cosmicjs.com/blog/bun-rust-rewrite(第三方独立验证) | Rust rewrite 仍主要面向 Linux x64 glibc;macOS/Windows 支持尚在后续 | ⚠️ 补充说明:10% 提速仅在 Linux 上验证过,macOS 和 Windows 的收益未经官方确认 |
关于 10% 提速的说明:该数字来自 Jarred Sumner 官方博客,未在 macOS/Windows 上验证。原帖 claim 为"Startup got 10% faster on Linux but otherwise, barely anyone noticed"。
上手步骤
前置条件
Claude Code 已安装。确认路径:
which claude
# 或 macOS/Linux 常见路径:
ls ~/.local/bin/claude
步骤一:快速验证(推荐)
strings ~/.local/bin/claude | grep -m1 'Bun v1'
预期输出示例:
Bun v1.4.0 (macOS arm64)
或
Bun v1.4.0 (linux x64)
注意:
strings是 GNU coreutils 自带工具,macOS 内置的strings功能相同,无需额外安装。
步骤二:交互式版本获取(更精确)
# 写一个临时脚本
cat > /tmp/bun-version.ts <<'EOF'
console.log("embedded bun:", Bun.version);
process.exit(0);
EOF
# 用 BUN_OPTIONS 注入
BUN_OPTIONS="--preload=/tmp/bun-version.ts" claude --version
输出为纯数字版本号 1.4.0,可以直接在脚本中捕获。
步骤三:理解版本含义
| 版本 | 含义 |
|---|---|
Bun v1.3.x |
Zig 版,2026 年 5 月前的稳定版 |
Bun v1.4.0 |
Rust 版第一个正式版(2026 年 7 月后随 canary 渠道进入 Claude Code) |
canary 标签 |
尚未 tag 正式 release,但已在 Claude Code 中稳定运行数月 |
进阶:查看 Claude Code 内置的所有运行时
strings ~/.local/bin/claude | grep -E '(Node|JavaScriptCore|Python|git|Poppler|LibreOffice)' | head -20
这可以揭示 Claude Code 桌面版捆绑的其他工具链(完整的 Python/Node.js/Poppler/git/LibreOffice 全家桶藏在 ~/.cache/codex-runtimes/codex-primary-runtime/)。
坑与适用边界
- 平台差异:上述 10% 提速仅在 Linux 上测量。macOS ARM64 设备上未经验证,Windows 同样未测。
- 路径因安装方式而异:通过
npm install -g @anthropic-ai/claude-code安装时二进制可能在node_modules/.bin/下而非~/.local/bin/。用which claude先确认。 - macOS 安全拦截:macOS 上如果 Claude Code 来自 /tmp 或未签名路径,Gatekeeper 可能拦截。签名验证:
codesign -dvv ~/.local/bin/claude。 - strings 输出有噪声:搜索
Bun v可能匹配到注释字符串里的旧版本号。加-m1取第一个结果最可靠。 - Rust rewrite 范围:当前 Rust 版主要覆盖 Linux x64 glibc。macOS(Apple Silicon)和 Windows 的 Rust 支持仍在后续路线图上。
BUN_OPTIONS的正确写法:环境变量赋值等号两边不能有空格,BUN_OPTIONS="--preload=/tmp/bun-version.ts"而非BUN_OPTIONS = "--preload=..."。
一句话结论
用 strings ~/.local/bin/claude | grep -m1 'Bun v1' 两秒内就能确认 Claude Code 跑的是 Rust 版 Bun v1.4.0——零依赖、零安装、纯系统工具,是挖闭源二进制版本信息的范本级技巧。