freemcplab
Explore
Guides
Learn
基于 ↗
Learn · 12 课源码精读
Learn Claude Code
不是教程,是拆机。从 agent loop 一行循环开始,层层剥到 worktree 隔离。12 课 × 3 个可交互组件,每节都能独立读。
12
课
36
个交互组件
基于
shareAI-lab/learn-claude-code
S01
Agent Loop
没有循环,就没有 agent
Agent loop
stop_reason
messages 历史
tool_result 回传
→
S02
Tool Use
循环没变,只是工具变多了
Tool dispatch map
JSON schema
safe_path 防逃逸
tool 扩展
→
S03
Todo Write
让 agent 管自己的进度
TodoManager
in_progress 单例限制
nag reminder 注入
结构化状态
→
S04
Subagent
把大问题切给一个新开的 agent
Subagent 派发
上下文隔离
CHILD_TOOLS 裁剪
摘要式返回
→
S05
Skill Loading
按需加载的领域知识
两层 skill 架构
YAML frontmatter
load_skill tool
token 经济
→
S06
Context Compact
上下文满了,学会砍
Micro compact
Auto compact
手动 compact tool
transcript 持久化
→
S07
Task System
状态写到磁盘,活过压缩
Task CRUD
blockedBy 依赖图
JSON 文件持久化
拓扑求可执行
→
S08
Background Tasks
让活自己跑,agent 不阻塞
线程化 bg task
通知队列
LLM 调用前 drain
回灌结果
→
S09
Agent Teams
多个 agent 通过文件邮箱通信
持久 teammate
JSONL 邮箱
5 种消息类型
团队 config.json
→
S10
Team Protocols
两个 agent 之间的握手协议
shutdown 协议
plan_approval 协议
request_id 关联
FSM: pending→approved/rejected
→
S11
Autonomous Agents
自己找活干的 agent
WORK / IDLE 两阶段
任务板轮询
auto_claim
identity 重注入
→
S12
Worktree Isolation
不同 agent 不要抢同一棵树
git worktree add
任务 / worktree 绑定
keep vs remove
目录级隔离
→