Thanks to visit codestin.com
Credit goes to github.com

Skip to content

minruixu/claude-code

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code — 从源码运行

本仓库包含 Claude Code CLI 的反编译源码,经过修改后可以直接使用 Bun 运行。

前置要求

  • Bun >= 1.3(推荐 1.3.11+)
  • macOS(arm64 / Apple Silicon)
  • 已通过 Claude Code 官方完成 OAuth 登录~/.claude.json 中需有有效 token)

安装依赖

bun install

运行

# 启动交互式 REPL
bun start

# 传递额外参数(如 --resume)
bun run claude --resume <session-id>

# 带 debug 日志启动(日志输出到 stderr,可重定向到文件)
bun run debug 2>./tmp/debug.log

手动运行(完整命令)

如果不想用 package.json 中的 scripts,可以直接执行:

bun run \
  --define 'MACRO.VERSION="1.0.100"' \
  --define 'MACRO.VERSION_CHANGELOG=""' \
  --define 'MACRO.BUILD_TIME=""' \
  --define 'MACRO.FEEDBACK_CHANNEL=""' \
  --define 'MACRO.ISSUES_EXPLAINER="report via GitHub issues"' \
  --define 'MACRO.PACKAGE_URL=""' \
  --define 'MACRO.NATIVE_PACKAGE_URL=""' \
  src/entrypoints/cli.tsx

所有 MACRO.* 定义都是必须的。 官方构建时这些值会被内联替换;从源码运行时需要通过 --define 手动提供,否则会产生 ReferenceError: MACRO is not defined 并导致进程崩溃。

已知问题

问题 说明
Ripgrep 缺失 内置 ripgrep 二进制 (src/utils/vendor/ripgrep/) 未包含在源码中。文件搜索功能会回退或不可用,不影响核心对话。
git ls-files 警告 Bun 将 Node.js signal 选项重命名为 cancelSignal,产生警告但不影响功能。
MCP 服务器认证 claude.ai 代理的 MCP 服务器(Gmail、Notion、Google Calendar)需要单独进行 OAuth 授权,与主 CLI 登录无关。
headers.get is not a function 429 错误处理中 claudeAiLimits.tsheaders 对象类型不匹配,已记录但不影响运行。
长上下文 429 首次请求可能因 system prompt + 工具定义过长而被限流,重试后通常会成功。

相对官方版本的修改

源码基于官方构建产物反编译,做了以下修改以适配从源码直接运行:

  • Commander.js flag 修复-d2e, --debug-to-stderr 改为 --debug-to-stderr(Commander 13 不支持多字符短 flag)
  • TTY 检测增强isNonInteractive 逻辑改为同时检查 stdoutstderr 的 TTY 状态
  • stdin.resume() — Ink App 组件中添加 stdin.resume(),修复 Bun 下 stdin 可能保持暂停的问题
  • headers 防御性检查logging.tscolor-diff/index.ts 中添加空值/类型检查
  • 流式文本显示优化 — REPL 中 reduced-motion 模式下仍显示流式内容
  • Autocomplete + Enter 行为 — PromptInput 中修复建议弹窗阻止提交的问题
  • runHeadless 错误处理 — 为 -p 模式添加 .catch() 避免静默失败

项目结构

src/
├── entrypoints/cli.tsx   # 入口,处理 CLI 参数分发
├── main.tsx              # 主逻辑,Commander 定义、交互/非交互模式
├── screens/REPL.tsx      # 交互式 REPL 界面(~5000 行)
├── ink/                  # 定制版 Ink (React TUI 框架)
├── services/api/         # Anthropic API 客户端、重试、日志
├── components/           # React 组件(消息、输入、权限等)
├── tools/                # 内置工具(Bash、文件读写、搜索等)
└── utils/                # 通用工具函数

About

Claude Code Snapshot for Research. All original source code is the property of Anthropic.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%