decode
decode logo decode Free open-source course

Building a Coding Agent From Scratch

Learn harness engineering by building Claude Code from scratch.

From a bare-bones agent loop to a swarm of cloud agents.

Open-source harness engineering course
by Decoding AI in collaboration with Modal, Opik (by Comet), and Kitaru (by ZenML).

decode — course trailer
Open-source course $0 to run 8 articles 6 videos Code from scratch Apache-2.0 license
Quickstart01

Try The Finished Agent First.

5 minutes / $0
quickstart.sh
$ git clone https://github.com/decodingai-magazine/building-a-coding-agent-from-scratch-course.git
$ cd building-a-coding-agent-from-scratch-course
$ make install
$ cp .env.example .env # set LLM API key
$ uv run decode

Then type /demo- and pick a demo. See what they do below. Full setup guide.

decode — /demo-
The demo skills listed inside the decode TUI after typing /demo-
Type /demo- and the six demos are one keystroke away.
About this course02

The Agent Is ~20 Lines. The Course Is Everything Else, Known as the Harness.

In LangChain's Terminal-Bench experiment, changing only the harness (with the same model) moved a coding agent from ~30th place into the top 5: the harness, not the model, is what makes a coding agent good.

That's the entire tool-calling agent. Everything else in this repo (the tools, skills, permission layer, sandbox, steering queue, memory, compaction, session recording & replay, remote execution, subagent fan-out, and evals) is the harness.

That's what you're here to build.

the entire agent
agent = Agent(
build_model(settings.llm_provider), # gemini | openrouter | modal
deps_type=AgentDeps, # cwd, event sink, permission gate
output_type=[str, DeferredToolRequests], # final answer, or tools paused for approval
)
register_tools(agent) # read, edit, bash, grep, ...
 
async with agent.iter(prompt, message_history=history) as run:
async for node in run: # model request → tool calls → repeat
stream_events(node)

We spent months under the hood of Claude Code (via its leaked source), OpenCode, Pi, and Aider, then distilled what we learned into 8 articles and 6 videos where you'll build decode, your own coding agent, from scratch. One headless core hooked to two modes: an interactive TUI and Modal serverless functions running N copies in parallel, fired by CLI, webhook, or cron.

Warning: Building a coding harness from scratch can make you dangerously good at building any other AI product, whether in finance, medicine, or e-commerce.

a fresh session
A fresh decode session: Opik tracing on, a Modal-served Qwen model, skill autocomplete, steering keys in the footer
A fresh session powered by Qwen3.6-35B hosted on Modal
the architecture
Diagram of a coding agent harness: two interfaces (Interactive TUI with steering queue and priority gate; Remote Modal runtime running N headless harnesses via CLI, webhook, or cron) drive one Headless Harness made of a Context Window with compaction, an LLM-to-Tools Agent Loop, and six modules (LLM Providers, Memory, Skills, Sandbox, Permissions, LSP Server). An Evals and Observability layer (benchmarks, regressions, replays via Opik and Kitaru) sits underneath.
The harness architecture of the coding agent you will build during this course.
Explore the 8 lessons: articles + videos
Course outline03

Eight Lessons. Six Videos.

From designing the harness to deploying a swarm of remote agents.

Read all the articles on SubstackWatch all the videos on YouTube
Why the lessons04

The Code Tells You What. The Lessons Tell You Why.

For the full experience, go through the articles and videos that cover what the code can't. The why behind every decision.

01

What the essential components of a coding agent are, and what is optional.

article 1 · video 1
02

Why we have a headless harness and two interface modes: TUI + Remote.

article 1 · video 1
03

Why we plugged in 9 tools, no more, no less.

article 2 · video 1
04

What guardrails are actually useful.

article 3 · video 2
05

Why compaction fires at ~80% of the window instead of at the limit.

article 4 · video 3
06

Why subagents are context engineering: scoped windows instead of one bloated context.

article 5
07

Why your agents should keep working after you close your laptop lid.

article 6 · video 4
08

Why you need both benchmarks and regression tests.

article 7 · video 5
09

Why we record every run, and what a replay buys you that a re-run doesn't.

article 8 · video 6
See it work05

Six Demos. One Keystroke Away.

The finished agent ships with demo skills under .decode/skills/. Open the TUI, type /demo-, pick one, and watch the harness you're about to build do real work.

The demo skills listed inside the decode TUI after typing /demo-
Implement the Skills StandardType /demo- and the six demos are one keystroke away.
A playable Snake game built by decode
Capable of Creating Games/demo-1-terminal-arcade — one prompt, a playable Snake game
Live GitHub repo data rendered as a web dashboard
Fetching Data & Creating Dashboards/demo-3-repo-pulse — live GitHub API data rendered as a dashboard
An interactive knowledge graph scraped from web articles
Extracting Ontologies & Rendering Graphs/demo-6-article-kg — web articles scraped into an interactive knowledge graph

And the infra that powers the agents.

An agent run recorded step by step as a Kitaru Session
Record & Replay for AI AgentsEvery run recorded step by step in Kitaru — replay it on a Kitaru Worker with the model swapped, then compare the two runs
Live Modal sandboxes executing the agent's tools
Remote SandboxingThe agent's bash runs in disposable Modal sandboxes
A self-served open model endpoint on Modal
Powered by Open-Source ModelsYour own Qwen3.6-35B served on an H200 via a Modal endpoint
Sessions traced in Opik with secrets scrubbed
Adding AI Evals & ObservabilityEvery session traced in Opik
Outcomes06

You'll Walk Away Knowing How To

Design a coding agent harness from scratch (article 1 · video 1)
Implement the coding agent loop as a headless harness (article 2 · video 1)
Attach the headless harness to multiple interfaces: a terminal UI, a CLI, or even a remote runtime (article 6 · video 4)
Execute the agent's tools within local Docker or remote Modal sandboxes (article 3 · video 2)
Host open-source models as SGLang servers on Modal (article 2 · video 1)
Implement guardrails by adding a permission layer (article 1 · video 1)
Build essential context engineering techniques: memory, compaction, skills (article 4 · video 3)
Hook up an LSP server for faster feedback loops (article 4 · video 3)
Implement a configurable agents catalog: build, plan, code reviewer, and exploration agents (article 5)
Deploy the headless harness on Modal, triggering remote agents via the CLI, a webhook, or a cron job (article 6 · video 4)
Spawn parallel subagents via fan-out strategies (article 5)
Add observability (article 2 · video 1)
Design an eval harness for benchmarking the agent and checking for regressions (article 7 · video 5)
Organically grow your regression suite from failed agent traces (article 8 · video 6)
Reproduce agent failures and check for regressions when changing your prompts or models by replaying traces with Kitaru (article 8 · video 6)
decode in plan mode breaking the Snake demo into a task list with the todo tool
Plan mode, live: the agent breaks the Snake demo into a task list with the todo tool — [x] done, [~] in progress.

Tech Stack

The code is written in Python, with the following frameworks and libraries:

Agent framework
LLM providers
Modal (open weights you serve yourself via SGLang), OpenRouter (open weights as a service), or Gemini (proprietary)
Session recording & replays
Observability & evals
Sandboxing
Local Docker & remote Modal sandboxes
Deploying
Modal as headless agents (fired by hand, by cron, or by webhook)

Otherwise, we build all the functionality from scratch to teach you the foundations that last, not frameworks that abstract away the hard parts.

Who should join07

Engineers Who Learn by Building.

You finish with a working coding agent that teaches you harness engineering patterns to steal for your own agentic applications.

Best for
ML/AI engineers who want to level up their craft
Software engineers and data scientists who want to transition into building agentic systems from scratch
Skills
Python (Intermediate), LLMs & agents (Beginner)
Hardware
Any modern machine will do. No GPU required, as we run all the LLMs in the cloud.
Level
Intermediate (but with a little sweat and patience, anyone can do it)
Time
~4–8 hours for the whole course — 4 if you read and watch, 6–8 if you run everything.
Cost structure08

Running It Costs $0.

Running the code costs $0 if you stick to free tiers. Only reading? Everything's free!

ServiceCost
Gemini API (default provider — easy setup, but limited API requests)free tier (Google AI Studio)
Modal (recommended provider, remote sandbox, remote agents)$30 free credits — enough to run the course
OpenRouter (alternative provider)$0 on :free models (optional $10 credit raises the daily cap)
Opik (tracing + evals)free tier
Kitaru (recording + replays)free — the OSS server runs on your laptop (make kitaru-local)
Project structure09

One Module Per Concept.

One Python package; each module maps to one part of the architecture.

How it works

As an open-source course, it is entirely self-paced and based on this repository, plus the attached lessons that walk you through the code. No paywall. No platform.

Read the lessons on the Decoding AI Magazine, watch the videos on the Decoding AI Channel, run the code on your own machine, break it, fix it, and learn from the process.

tree -L 2
.
├── docs/
│   ├── adr/                  # Architecture Decision Records — the "why" of every choice
│   └── glossary.md           # one canonical name per concept
├── evals/                    # benchmark tasks + regression cases + the Opik harness
├── scripts/                  # operator scripts: Kitaru bootstrap + eval table generation
├── tests/{unit,integration}/ # mirrors src/ 1:1; milestone capstones prove each milestone
└── src/decode/
    ├── cli.py                # Click entrypoint → launches the TUI
    ├── tui/                  # input: prompt_toolkit · output: Rich
    ├── harness/              # message queue + priority gate around the loop
    ├── agent/                # the Pydantic-AI ReAct loop (LLM ⇄ tools)
    ├── agents/               # agents catalog: Build / Plan / Code-Reviewer + Explore subagent
    ├── tools/                # file I/O, bash, web, todo, skills dispatch, LSP, ask_user
    ├── permissions/          # allow/ask/deny · modes · settings.json
    ├── sandbox/              # bash + file tools seam: none (host) / docker / modal
    ├── services/lsp/         # hand-rolled stdio LSP client (ty)
    ├── runtime/              # plain headless decode run + the Recording Seam
    ├── remote/               # decode remote deploy|run|attempts|logs — the Modal Headless App (CLI, webhook, cron)
    ├── context/              # compaction + conversation log (JSONL)
    ├── memory/               # AGENTS.md / MEMORY.md loading + write-back
    ├── observability/        # Opik tracing
    └── config/, entities/    # settings singleton · shared models
Running the code10

One Guide Per Side Quest.

The guides live under running_the_code/. Follow them in order; each ends with a link to the next.

00_troubleshooting.mdEvery known failure, and its fix 01_install_and_usage.mdStart here: install, one key, first session 02_modal_endpoints.mdServing open models on Modal 03_sandboxing.mdDocker (local) / Modal (remote) sandboxing + the sandbox git token 04_deploy.mdThe headless harness on Modal — CLI, webhook, cron 05_evals.mdBenchmarks and regression cases on Opik 06_evals_replays.mdKitaru on your laptop: record, replay & the full evals loop

Open a GitHub issue for course questions, setup trouble, or concept clarifications. Found a bug and know the fix? Fork, fix, run make ci (no API key needed), and open a pull request. Future readers will thank you 🤗

This Course Is Free Thanks to Them.

Sponsored by Modal, Opik and Kitaru

Special thanks to Modal, Opik (by Comet), and Kitaru (by ZenML) for sponsoring this open-source course and keeping it free!

Opik and Kitaru are open source. Consider starring their repositories: Opik on GitHub · Kitaru on GitHub.

FAQ11

Asked and Answered.

Do I need a paid API key?

No. The default Gemini provider has a free tier, OpenRouter routes across :free models, and Modal gives $30 in credits — see Cost Structure.

Why Python and not TypeScript or Go?

Accessibility: our audience knows Python. The course focuses on the design decisions, which transfer to any language.

Why build from scratch instead of extending Pi, DeepAgents, or an existing harness?

Because adding custom logic to an existing harness is the easy part. Knowing what to add requires understanding the internals. Those fundamentals are what still make AI engineers valuable. Build a coding agent once and you're equipped to build a custom agent for any use case.

Course author
Paul Iusztin
Paul Iusztin
Senior AI Engineer, Educator & Founder of Decoding AI
Author of the best-selling LLM Engineer's Handbook.
Decoding AI
Decoding AI Magazine
Join 45k+ engineers subscribed to the Decoding AI Magazine to learn to build coding agents from scratch.

One More Thing.

If you found this course useful, consider starring the repository so others can find it too.

Star the repo Start Lesson 1
Star History Chart