Learn Claude Code
从 0 到 1 构建 nano Claude Code-like agent,每次只加一个机制
核心模式
所有 AI 编程 Agent 共享同一个循环:调用模型、执行工具、回传结果。生产级系统会在其上叠加策略、权限和生命周期层。
while True:
response = client.messages.create(messages=messages, tools=tools)
if response.stop_reason != "tool_use":
break
for tool_call in response.content:
result = execute_tool(tool_call.name, tool_call.input)
messages.append(result)消息增长
观察 Agent 循环执行时消息数组的增长
学习路径
12 个渐进式课程,从简单循环到隔离化自治执行
The Agent Loop
The minimal agent kernel is a while loop + one tool
Tools
Adding tools means adding handlers, not rewriting the loop
TodoWrite
Visible plans improve task completion and accountability
Subagents
Process isolation gives context isolation for free
Skills
Skills inject via tool_result, not system prompt
Compact
Forgetting old context enables infinite-length sessions
Tasks
File-based state survives context compression
Background Tasks
Non-blocking daemon threads + notification queue
Agent Teams
Persistent teammates with async mailbox inboxes
Team Protocols
Same request-response pattern, two applications
Autonomous Agents
Polling + timeout makes teammates self-organizing
Worktree + Task Isolation
Task board coordinates ownership, worktrees isolate execution, and events make lifecycle auditable
架构层次
五个正交关注点组合成完整的 Agent