- Bun >= 1.3.11
- Node.js >= 18.0.0
bun installbun run build编译成功后会在根目录生成 cli.js(约 22MB)。
# 设置 API Key
export ANTHROPIC_API_KEY=your_api_key_here
# 启动交互界面
bun cli.js
# 或直接传入 prompt(非交互模式)
bun cli.js -p "你好"bun cli.js --version # 查看版本
bun cli.js --help # 查看帮助
bun cli.js --model <model> # 指定模型本项目为 @anthropic-ai/claude-code v2.1.88 源码,使用 Bun 作为构建工具,基于 TypeScript + React (Ink) 构建的终端 AI 编程助手。
| 技术 | 用途 |
|---|---|
| Bun | 构建工具 + 运行时 |
| TypeScript | 主要开发语言 |
| React + Ink | 终端 UI 渲染 |
| Zod v4 | 数据校验 |
| @anthropic-ai/sdk | Anthropic API 客户端 |
| @modelcontextprotocol/sdk | MCP 协议支持 |
bun build src/entrypoints/cli.tsx --outfile cli.js --target bun \
--define 'MACRO.VERSION="2.1.88"' \
--define 'MACRO.BUILD_TIME="2025-01-01T00:00:00Z"' \
--define 'MACRO.FEEDBACK_CHANNEL="https://github.com/anthropics/claude-code/issues"' \
--define 'MACRO.ISSUES_EXPLAINER="https://github.com/anthropics/claude-code/issues"' \
--define 'MACRO.NATIVE_PACKAGE_URL="https://npmjs.com"' \
--define 'MACRO.PACKAGE_URL="https://npmjs.com"' \
--define 'MACRO.VERSION_CHANGELOG=""'MACRO.* 是 Bun 编译时宏,在源码中作为常量使用,必须在构建时注入。
项目在 bunfig.toml 中配置了路径别名:
[build]
alias = { "src" = "./src", "react/compiler-runtime" = "react-compiler-runtime" }源码中 src/xxx 的绝对路径引用通过此别名解析到 ./src/xxx。
以下 4 个 Anthropic 内部私有包在 npm 上不公开,已在 node_modules/ 中创建功能存根:
| 包名 | 对应功能 | 影响 |
|---|---|---|
@ant/claude-for-chrome-mcp |
Claude in Chrome 浏览器控制 | Chrome 集成不可用 |
@ant/computer-use-mcp |
Computer Use 鼠标键盘控制 | Computer Use 不可用 |
@anthropic-ai/mcpb |
MCP 插件包(.dxt 格式)安装 | 插件市场不可用 |
@anthropic-ai/sandbox-runtime |
沙箱文件/网络权限隔离 | 沙箱模式不可用 |
核心对话、代码编辑、工具调用等主要功能不受影响。
export ANTHROPIC_API_KEY=sk-ant-xxxx
bun cli.jsbun cli.js
# 启动后在界面中选择登录,走 claude.ai 授权流程export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=xxx
export AWS_REGION=us-east-1
bun cli.js --model anthropic.claude-3-5-sonnet-20241022-v2:0Q: 运行后界面卡住? A: 正常现象,Ink (React 终端 UI) 启动需要 1-2 秒,等待即可。
Q: MACRO is not defined 报错?
A: 需要用 bun run build 重新编译,直接运行 .ts 源文件不行。
Q: API Error: headers?.get is not a function?
A: 升级 zod 到 v4:bun add zod@^4,然后重新 bun run build。
Q: organization has been disabled 报错?
A: API Key 所属组织被禁用。如果是环境变量设置的 Key,尝试 unset ANTHROPIC_API_KEY 后用 OAuth 登录。