Learn Claude Code

Learn Claude Code

Build a nano Claude Code-like agent from 0 to 1, one mechanism at a time

The Core Pattern

Every AI coding agent shares the same loop: call the model, execute tools, feed results back. Production systems add policy, permissions, and lifecycle layers on top.

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

20 progressive sessions, from a simple loop to a complete multi-agent harness

s01102 LOC

The Agent Loop

The smallest useful agent is a loop that calls the model, runs tools, and feeds results back.

s02135 LOC

Tool Use

The loop stays stable while capabilities register into a dispatch table.

s03180 LOC

Permission

Dangerous actions need a harness decision point before the shell runs.

s04232 LOC

Hooks

Cross-cutting behavior belongs around the loop, not tangled inside it.

s05236 LOC

TodoWrite

Explicit plans keep long-running work visible and correctable.

s06304 LOC

Subagent

Subagents give each subtask a clean message history while preserving the main thread.

s07335 LOC

Skill Loading

Inject specialized knowledge only when the task actually needs it.

s08414 LOC

Context Compact

Compression keeps the conversation usable when the context window gets crowded.

s09528 LOC

Memory

Some facts should survive summarization and future sessions.

s10166 LOC

System Prompt

The system prompt is a generated product of policy, tools, skills, and context.

s11287 LOC

Error Recovery

A robust harness classifies failures and decides what kind of retry is worthwhile.

s12297 LOC

Task System

A task graph turns vague goals into ordered, observable work.

s13379 LOC

Background Tasks

The agent can keep reasoning while slow work completes elsewhere.

s14645 LOC

Cron Scheduler

Recurring work should be created by the harness, not remembered by the model.

s15745 LOC

Agent Teams

Persistent teammates let work continue in parallel without stuffing every thought into one context.

s16709 LOC

Team Protocols

Multi-agent systems need explicit message contracts, not vibes.

s17648 LOC

Autonomous Agents

Teammates become useful when they can discover and claim work themselves.

s18802 LOC

Worktree Isolation

Parallel agents need isolated filesystems as much as isolated conversations.

s19835 LOC

MCP Tools

External services can become agent tools through a standard discovery and call protocol.

s201708 LOC

Comprehensive Agent

The final harness is still one loop, now surrounded by the systems that make it production-shaped.

Architectural Layers

Five orthogonal concerns that compose into a complete agent