跳转至

练习答案

本节:把 Claude Code 核心模块手写一遍——每个练习都是 100-500 行完整实现 + 100% 单元测试 目的:从"看代码""能写代码"

练习列表

文档 主题 行数 难度
handwrite-store 手写 Store(状态管理核心) ~60 ⭐⭐
handwrite-query-engine 手写 QueryEngine ~300 ⭐⭐⭐⭐
handwrite-claude-api 手写 claude.ts 核心 ~250 ⭐⭐⭐⭐
handwrite-bash-security 手写 bashSecurity 规则 ~150 ⭐⭐⭐
handwrite-async-generator 手写 async generator 模式 ~80 ⭐⭐⭐
handwrite-yoga-layout 手写 Yoga flexbox ~100 ⭐⭐
build-async-stream 手写异步流处理 ~80 ⭐⭐
mock-permission-prompt 模拟权限提示 ~60 ⭐⭐
mock-agent-loop 5 行 agent loop ~30
lru-cache LRU Cache ~50 ⭐⭐
build-a-tool 建 GitCommitTool ~150 ⭐⭐⭐
build-an-mcp-server 建 MCP server 完整 ~300 ⭐⭐⭐

推荐学习路径

起点 顺序
TypeScript 新手 handwrite-store → handwrite-async-generator → mock-agent-loop
前端工程师 handwrite-store → lru-cache → mock-permission-prompt
后端工程师 handwrite-query-engine → handwrite-claude-api → build-async-stream
Bash 专家 handwrite-bash-security
图形 / UI handwrite-yoga-layout
MCP 集成 build-an-mcp-server → build-mcp-server