build-claude-code

作者 OPBR已验证

从0到1构建 Claude code (学习版)

133
Stars
16
Forks
TypeScript
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/OPBR/build-claude-code

快速入门

使用 build-claude-code 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

Build Claude Code

中文 | English

从0到1构建 Claude Code 风格的 AI Coding Agent

简介

这是一个渐进式学习项目,用 TypeScript 从零开始构建一个完整的 AI 编程代理。我们将逐步实现 Claude Code 的所有核心机制:

本项目灵感来自 learn-claude-code(68.5k ⭐),原项目 Agent 核心由 Python 实现,本项目使用 TypeScript 重写 Agent 逻辑本身,目前已完成 s01–s14,持续更新中。适合希望在 Node.js / TypeScript 生态中深入理解 Harness 工程的开发者。

  • 核心循环
  • 工具系统
  • 任务规划
  • 上下文压缩
  • 多代理协作
  • 工作树隔离

核心理念:智能来自模型训练,Harness(套件)只是让智能得以表达的载体。我们构建的是载体,不是智能本身。

学习路线

阶段Session主题核心概念
1s01Agent Loop一个循环 + Bash = Agent
1s02Tool Use添加工具 = 添加一个 handler
2s03TodoWrite没有计划的代理会迷失方向
2s04Subagent大任务拆分,子任务获得干净的上下文
2s05Skills按需加载知识,不要 upfront
3s06Context Compact三层压缩策略实现无限会话
3s07Permission System工具执行前的安全检查管道
3s08Hook System不改主循环也能在固定时机插入行为
4s09Memory System跨会话保存有价值的信息
4s10System Prompt动态组装系统提示词
4s11Error Recovery错误分类 + 恢复路径
5s12Task System文件持久化任务板 + 依赖图
5s13Background Tasks后台执行 + 通知队列
5s14Cron Scheduler定时任务调度
6s15Agent TeamsJSONL 邮箱通信的多代理
6s16Team Protocols关闭/审批协议
6s17Autonomous Agents代理自动发现任务
6s18Worktree Isolation目录级隔离执行
7s19MCP Plugin模型上下文协议插件
8s_fullFull Agent所有机制整合

快速开始

环境要求

  • Node.js >= 20
  • pnpm >= 10

安装

pnpm install

配置

复制 .env.example.env,填入你的 API 配置:

ANTHROPIC_API_KEY=your-api-key-here
MODEL_ID=claude-sonnet-4-20250514

运行

# 运行 s01 - 基础 Agent Loop
pnpm s01

# 运行其他 session
pnpm s02
pnpm s03
# ...

# 运行完整代理
pnpm full

核心模式

整个项目的核心就是一个简单的循环:

async function agentLoop(messages: Message[]): Promise<void> {
  while (true) {
    const response = await client.messages.create({
      model: MODEL,
      system: SYSTEM,
      messages: messages,
      tools: TOOLS,
    })

    messages.push({ role: 'assistant', content: response.content })

    if (response.stop_reason !== 'tool_use') {
      return // 模型决定停止
    }

    const results = await executeTools(response.content)
    messages.push({ role: 'user', content: results })
    // 循环继续...
  }
}

模型决定何时调用工具、何时停止。代码只执行模型的请求。

项目结构

build-claude-code/
├── src/
│   ├── index.ts              # 入口文件
│   ├── core/                 # 核心模块 (s01-s02)
│   │   ├── agent-loop.ts     # 核心循环
│   │   ├── tools.ts          # 工具系统
│   │   └── types.ts          # 类型定义
│   ├── planning/             # 计划模块 (s03-s05)
│   ├── persistence/          # 持久化模块 (s06-s14)
│   │   ├── compact.ts        # s06: 上下文压缩
│   │   ├── permission.ts     # s07: 权限系统
│   │   ├── hook.ts           # s08: Hook 系统
│   │   ├── memory.ts         # s09: 记忆系统
│   │   ├── prompt.ts         # s10: 系统提示词
│   │   ├── recovery.ts       # s11: 错误恢复
│   │   ├── task-manager.ts   # s12: 任务系统
│   │   ├── background.ts     # s13: 后台任务
│   │   └── cron.ts           # s14: 定时调度
│   ├── team/                 # 团队模块 (s15-s18)
│   ├── plugin/               # 插件模块 (s19)
│   ├── full/                 # 综合实现
│   └── sessions/             # 各 session 入口
├── learn/
│   ├── 00-project-setup.md   # 项目初始化笔记
│   ├── 01-agent-loop.md      # s01 学习笔记
│   ├── ...                   # 每个 session 的学习笔记
│   └── output/               # 公众号文章输出
├── skills/                   # 技能文件目录
├── package.json
├── tsconfig.json
├── eslint.config.mjs
├── .prettierrc
└── .env.example

技术栈

工具版本说明
TypeScript6.0主要语言
tsdown0.21现代化构建工具
tsx4.21开发时直接运行 TS
pnpm10包管理
@anthropic-ai/sdk0.90Anthropic 官方 SDK
ESLint10代码检查
Prettier3.8代码格式化

开发命令

pnpm dev          # 开发模式
pnpm build        # 构建
pnpm typecheck    # 类型检查
pnpm lint         # ESLint 检查
pnpm lint:fix     # ESLint 自动修复
pnpm format       # Prettier 格式化
pnpm format:check # Prettier 检查

公众号

关注公众号 前端的AI野心,获取更多 AI Agent 开发教程:

学习资源

代码风格

  • 无分号
  • 单引号
  • 尾逗号

License

MIT

常见问题

What is build-claude-code?

build-claude-code is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by OPBR. 从0到1构建 Claude code (学习版). It has 133 GitHub stars.

Is build-claude-code safe to use?

Yes. build-claude-code passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install build-claude-code?

Clone the repository with "git clone https://github.com/OPBR/build-claude-code" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is build-claude-code written in?

build-claude-code is primarily written in TypeScript. It is open-source under OPBR on GitHub, so you can review or fork the full source.

Are there alternatives to build-claude-code?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh build-claude-code against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI 智能体
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情