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. The harness adds policy, permissions, memory, coordination, and lifecycle control around it.

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

17 progressive sessions, from a simple loop to deterministic orchestration and goal closure

s01106 LOC

The Agent Loop

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

s02145 LOC

Tool Use

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

s03181 LOC

Permission

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

s04203 LOC

Hooks

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

s05280 LOC

TodoWrite

Explicit plans keep long-running work visible and correctable.

s06287 LOC

Subagent

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

s07302 LOC

Skill Loading

Inject specialized knowledge only when the task actually needs it.

s08423 LOC

Context Compact

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

s09669 LOC

Memory

Some facts should survive summarization and future sessions.

s10421 LOC

Task System

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

s11401 LOC

Background Tasks

The agent can keep reasoning while slow work completes elsewhere.

s12639 LOC

Cron Scheduler

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

s131525 LOC

Agent Team Runtime

Persistent teammates can reliably discover and execute parallel work when the runtime owns messaging, atomic claims, and task-bound working directories.

s14441 LOC

MCP Tools

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

s152618 LOC

Integrated Harness

The integrated harness is still one loop, surrounded by the systems introduced across the course.

s16722 LOC

Workflow Runtime

When orchestration has a fixed shape, code can make it parallel, deterministic, and resumable.

s17790 LOC

Goal Loop

A durable goal keeps the loop working until an independent evaluator finds the completion condition satisfied in the conversation.

Architectural Layers

Five orthogonal concerns that compose into a complete agent