DEV Community

Cover image for I built a coding agent from scratch to see what's inside
Tobías Chavarría
Tobías Chavarría

Posted on AI-assisted

I built a coding agent from scratch to see what's inside

I use coding agents every day, and for a while I couldn't explain what they actually do between my prompt and the edit to my file. So I built one.

The answer turned out to be smaller than I expected. Claude Code, Cursor and Codex all run the same loop: send the conversation to a model, run the tools it asks for, send back the results, repeat until the model just answers. The model never touches your files. It only asks, and your machine does the work.

petite is that loop, written from scratch in 565 lines of Python. I built it in 14 commits, one concept each:

  • talking to a model, then giving it tools (Read, Write, Bash)
  • the agent loop
  • validating tool calls with Pydantic
  • skills, slash commands and arguments
  • the Skill tool, and subagents with their own conversation

Every stage is a tagged commit that runs on its own. The site gives you a task for each one, keeps the solution folded until you want it, and has a command that proves it works:

    just stage 4
    cd .stages/04
    just run "How many carrots does the rabbit eat per day, according to rabbit.py?"
Enter fullscreen mode Exit fullscreen mode

The diagrams put the model on top and your machine below, so you can see exactly what crosses the network.

If you've wondered how these tools work, the fastest way to find out is to build one. The whole tutorial costs a few cents of API credit.

petite — how coding agents work, built from scratch

Understand how coding agents like Claude Code work inside by building one: a complete agent in 565 lines of Python, one concept per commit: tool calling, the agent loop, skills, subagents.

favicon tobiaschc.github.io

Top comments (0)