Learn Claude Code

Learn Claude Code

从 0 到 1 构建 nano Claude Code-like agent,每次只加一个机制

核心模式

所有 AI 编程 Agent 共享同一个循环:调用模型、执行工具、回传结果。生产级系统会在其上叠加策略、权限和生命周期层。

agentLoop.ts
while (true) {
    const response = client.messages.create({messages, tools: TOOLS})
    if (response.stop_reason !== "tool_use"){
        return
    }
    for (const toolCall of response.content) {
        const result = executeTool(toolCall.name, toolCall.input)
        messages.append(result)
    }
}

消息增长

观察 Agent 循环执行时消息数组的增长

messages[]len=0
[]

学习路径

12 个渐进式课程,从简单循环到隔离化自治执行

架构层次

五个正交关注点组合成完整的 Agent

Tools & Execution

2 个版本

Planning & Coordination

4 个版本

Memory Management

1 个版本

Concurrency

1 个版本