Compare commits

...

2 Commits
v2 ... v1.0.2

Author SHA1 Message Date
claude-code-best
9a57642d3a feat: 完成最新的可构建版本 2026-04-01 10:42:53 +08:00
claude-code-best
604110272f docs: 尝试修复 docs 的位置 2026-04-01 10:09:00 +08:00
9 changed files with 160 additions and 107 deletions

View File

@@ -2,22 +2,22 @@
Anthropic 官方 [Claude Code](https://docs.anthropic.com/en/docs/claude-code) CLI 工具的源码反编译/逆向还原项目。目标是将 Claude Code 大部分功能及工程化能力复现。虽然很难绷, 但是它叫做 CCB(踩踩背)...
> V1 会完成跑通及基本的类型检查通过;
> V1 会完成跑通及基本的类型检查通过;
>
> V2 会完整实现工程化配套设施;
> V2 会完整实现工程化配套设施;
>
> V3 会实现多层级解耦, 很多比如 UI 包, Agent 包都可以独立优化;
> V3 会实现多层级解耦, 很多比如 UI 包, Agent 包都可以独立优化;
>
> V4 会完成大量的测试文件, 以提高稳定性
>
> 我不知道这个项目还会存在多久, fork 不好使, git clone 或者下载 .zip 包才稳健;
>
>
> 这个项目更新很快, 后台有 Opus 持续优化, 所以你可以提 issues, 但是 PR 暂时不会接受;
>
> 存活记录:
> 开源后 12 小时: 愚人节, star 破 1k, 并且牢 A 没有发邮件搞这个项目
>
> 如果你想要私人咨询服务, 那么可以发送邮件到 claude-code-best@proton.me, 备注咨询与联系方式即可; 由于后续工作非常多, 可能会忽略邮件, 半天没回复, 可以多发;
> 如果你想要私人咨询服务, 那么可以发送邮件到 <claude-code-best@proton.me>, 备注咨询与联系方式即可; 由于后续工作非常多, 可能会忽略邮件, 半天没回复, 可以多发;
## 快速开始
@@ -26,8 +26,7 @@ Anthropic 官方 [Claude Code](https://docs.anthropic.com/en/docs/claude-code) C
一定要最新版本的 bun 啊, 不然一堆奇奇怪怪的 BUG!!! bun upgrade!!!
- [Bun](https://bun.sh/) >= 1.3.11
- Node.js >= 18部分依赖需要
- 有效的 Anthropic API Key或 Bedrock / Vertex 凭据)
- 常规的配置 CC 的方式, 各大提供商都有自己的配置方式
### 安装
@@ -41,17 +40,11 @@ bun install
# 开发模式, 看到版本号 888 说明就是对了
bun run dev
# 直接运行
bun run src/entrypoints/cli.tsx
# 管道模式(-p
echo "say hello" | bun run src/entrypoints/cli.tsx -p
# 构建
bun run build
```
构建产物输出到 `dist/cli.js`~25.75 MB5326 模块)。
构建产物输出到 `dist/cli.js`, 构建出的版本 bun 和 node 都可以启动, 你 publish 到私有源可以直接启动
## 能力清单
@@ -302,7 +295,6 @@ bun run build
`ABLATION_BASELINE` `AGENT_MEMORY_SNAPSHOT` `BG_SESSIONS` `BRIDGE_MODE` `BUDDY` `CCR_MIRROR` `CCR_REMOTE_SETUP` `CHICAGO_MCP` `COORDINATOR_MODE` `DAEMON` `DIRECT_CONNECT` `EXPERIMENTAL_SKILL_SEARCH` `FORK_SUBAGENT` `HARD_FAIL` `HISTORY_SNIP` `KAIROS` `KAIROS_BRIEF` `KAIROS_CHANNELS` `KAIROS_GITHUB_WEBHOOKS` `LODESTONE` `MCP_SKILLS` `PROACTIVE` `SSH_REMOTE` `TORCH` `TRANSCRIPT_CLASSIFIER` `UDS_INBOX` `ULTRAPLAN` `UPLOAD_USER_SETTINGS` `VOICE_MODE` `WEB_BROWSER_TOOL` `WORKFLOW_SCRIPTS`
## 项目结构
```

47
build.ts Normal file
View File

@@ -0,0 +1,47 @@
import { readdir, readFile, writeFile } from "fs/promises";
import { join } from "path";
const outdir = "dist";
// Step 1: Clean output directory
const { rmSync } = await import("fs");
rmSync(outdir, { recursive: true, force: true });
// Step 2: Bundle with splitting
const result = await Bun.build({
entrypoints: ["src/entrypoints/cli.tsx"],
outdir,
target: "bun",
splitting: true,
});
if (!result.success) {
console.error("Build failed:");
for (const log of result.logs) {
console.error(log);
}
process.exit(1);
}
// Step 3: Post-process — replace Bun-only `import.meta.require` with Node.js compatible version
const files = await readdir(outdir);
const IMPORT_META_REQUIRE = "var __require = import.meta.require;";
const COMPAT_REQUIRE = `var __require = typeof import.meta.require === "function" ? import.meta.require : (await import("module")).createRequire(import.meta.url);`;
let patched = 0;
for (const file of files) {
if (!file.endsWith(".js")) continue;
const filePath = join(outdir, file);
const content = await readFile(filePath, "utf-8");
if (content.includes(IMPORT_META_REQUIRE)) {
await writeFile(
filePath,
content.replace(IMPORT_META_REQUIRE, COMPAT_REQUIRE),
);
patched++;
}
}
console.log(
`Bundled ${result.outputs.length} files to ${outdir}/ (patched ${patched} for Node.js compat)`,
);

4
docs/favicon.svg Normal file
View File

@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">
<circle cx="16" cy="16" r="14" fill="#D97706"/>
<path d="M12 10l10 6-10 6V10z" fill="#FFFFFF"/>
</svg>

After

Width:  |  Height:  |  Size: 180 B

5
docs/logo/dark.svg Normal file
View File

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 28" fill="none">
<circle cx="14" cy="14" r="11" stroke="#F59E0B" stroke-width="2" fill="none"/>
<path d="M11 10l6 4-6 4V10z" fill="#F59E0B"/>
<text x="30" y="19.5" font-family="system-ui, -apple-system, sans-serif" font-size="15" font-weight="700" letter-spacing="1" fill="#F1F5F9">CCB</text>
</svg>

After

Width:  |  Height:  |  Size: 362 B

5
docs/logo/light.svg Normal file
View File

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 28" fill="none">
<circle cx="14" cy="14" r="11" stroke="#D97706" stroke-width="2" fill="none"/>
<path d="M11 10l6 4-6 4V10z" fill="#D97706"/>
<text x="30" y="19.5" font-family="system-ui, -apple-system, sans-serif" font-size="15" font-weight="700" letter-spacing="1" fill="#0F172A">CCB</text>
</svg>

After

Width:  |  Height:  |  Size: 362 B

View File

@@ -1,84 +0,0 @@
{
"$schema": "https://mintlify.com/schema.json",
"name": "Claude Code Architecture",
"logo": {
"dark": "/logo/dark.svg",
"light": "/logo/light.svg"
},
"favicon": "/favicon.svg",
"colors": {
"primary": "#D97706",
"light": "#F59E0B",
"dark": "#B45309",
"background": {
"dark": "#0F172A",
"light": "#FFFFFF"
}
},
"navigation": [
{
"group": "开始",
"pages": [
"introduction/what-is-claude-code",
"introduction/why-this-whitepaper",
"introduction/architecture-overview"
]
},
{
"group": "对话是如何运转的",
"pages": [
"conversation/the-loop",
"conversation/streaming",
"conversation/multi-turn"
]
},
{
"group": "工具AI 的双手",
"pages": [
"tools/what-are-tools",
"tools/file-operations",
"tools/shell-execution",
"tools/search-and-navigation",
"tools/task-management"
]
},
{
"group": "安全与权限",
"pages": [
"safety/why-safety-matters",
"safety/permission-model",
"safety/sandbox",
"safety/plan-mode"
]
},
{
"group": "上下文工程",
"pages": [
"context/system-prompt",
"context/project-memory",
"context/compaction",
"context/token-budget"
]
},
{
"group": "多 Agent 协作",
"pages": [
"agent/sub-agents",
"agent/worktree-isolation",
"agent/coordinator-and-swarm"
]
},
{
"group": "可扩展性",
"pages": [
"extensibility/mcp-protocol",
"extensibility/hooks",
"extensibility/skills",
"extensibility/custom-agents"
]
}
],
"footerSocials": {
"github": "https://github.com/anthropics/claude-code"
}
}

84
mint.json Normal file
View File

@@ -0,0 +1,84 @@
{
"$schema": "https://mintlify.com/schema.json",
"name": "Claude Code Architecture",
"logo": {
"dark": "/docs/logo/dark.svg",
"light": "/docs/logo/light.svg"
},
"favicon": "/docs/favicon.svg",
"colors": {
"primary": "#D97706",
"light": "#F59E0B",
"dark": "#B45309",
"background": {
"dark": "#0F172A",
"light": "#FFFFFF"
}
},
"navigation": [
{
"group": "开始",
"pages": [
"docs/introduction/what-is-claude-code",
"docs/introduction/why-this-whitepaper",
"docs/introduction/architecture-overview"
]
},
{
"group": "对话是如何运转的",
"pages": [
"docs/conversation/the-loop",
"docs/conversation/streaming",
"docs/conversation/multi-turn"
]
},
{
"group": "工具AI 的双手",
"pages": [
"docs/tools/what-are-tools",
"docs/tools/file-operations",
"docs/tools/shell-execution",
"docs/tools/search-and-navigation",
"docs/tools/task-management"
]
},
{
"group": "安全与权限",
"pages": [
"docs/safety/why-safety-matters",
"docs/safety/permission-model",
"docs/safety/sandbox",
"docs/safety/plan-mode"
]
},
{
"group": "上下文工程",
"pages": [
"docs/context/system-prompt",
"docs/context/project-memory",
"docs/context/compaction",
"docs/context/token-budget"
]
},
{
"group": "多 Agent 协作",
"pages": [
"docs/agent/sub-agents",
"docs/agent/worktree-isolation",
"docs/agent/coordinator-and-swarm"
]
},
{
"group": "可扩展性",
"pages": [
"docs/extensibility/mcp-protocol",
"docs/extensibility/hooks",
"docs/extensibility/skills",
"docs/extensibility/custom-agents"
]
}
],
"footerSocials": {
"github": "https://github.com/anthropics/claude-code"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "claude-js",
"version": "1.0.1",
"version": "1.0.2",
"description": "Reverse-engineered Anthropic Claude Code CLI — interactive AI coding assistant in the terminal",
"type": "module",
"author": "claude-code-best <claude-code-best@proton.me>",
@@ -35,7 +35,7 @@
"dist"
],
"scripts": {
"build": "bun build src/entrypoints/cli.tsx --outdir dist --target bun",
"build": "bun run build.ts",
"dev": "bun run src/entrypoints/cli.tsx",
"prepublishOnly": "bun run build",
"lint": "biome lint src/",
@@ -44,7 +44,8 @@
"prepare": "git config core.hooksPath .githooks",
"test": "bun test",
"check:unused": "knip-bun",
"health": "bun run scripts/health-check.ts"
"health": "bun run scripts/health-check.ts",
"docs:dev": "npx mintlify dev"
},
"dependencies": {},
"devDependencies": {

View File

@@ -1,5 +1,3 @@
import { dlopen, FFIType, suffix } from "bun:ffi";
const FLAG_SHIFT = 0x20000;
const FLAG_CONTROL = 0x40000;
const FLAG_OPTION = 0x80000;
@@ -23,12 +21,13 @@ function loadFFI(): void {
}
try {
const lib = dlopen(
const ffi = require("bun:ffi") as typeof import("bun:ffi");
const lib = ffi.dlopen(
`/System/Library/Frameworks/Carbon.framework/Carbon`,
{
CGEventSourceFlagsState: {
args: [FFIType.i32],
returns: FFIType.u64,
args: [ffi.FFIType.i32],
returns: ffi.FFIType.u64,
},
}
);