Learn Claude Code

Learn Claude Code

Build an AI coding agent from scratch, one concept at a time

The Core Pattern

Every AI coding agent shares the same loop: call the model, execute tools, feed results back. Everything else is details.

agent_loop.py
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)

Message Growth

Watch the messages array grow as the agent loop executes

messages[]len=0
[]

Learning Path

12 progressive versions, from 13 lines to 1321 lines

Architectural Layers

Five orthogonal concerns that compose into a complete agent

Tools & Execution

2 versions

Planning & Coordination

4 versions

Memory Management

1 versions

Concurrency

1 versions