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
目錄級隔離
→