Spec-Based Development with AI Agents: A Step-by-Step Tutorial

Do you want to start building apps for the web, your phone or your desktop with AI harnesses, and wonder where to begin? This guide takes you, one step at a time, from a blank folder to software that AI agents have built, a different AI has reviewed, and you have proven to work.

By Faysal Aziz

Edited and approved by Faysal Aziz

Published

Faysal Aziz on the right against green Matrix-style digital rain, with the title SpecDev using a Harness and the line Spec-based development with AI harnesses, in depth.

Most of us have done it. You ask an AI coding tool to "build the app", it works for ten minutes, and you get something that looks right and is not. Then you spend the afternoon finding out where.

That is not because the AI is bad. It is because nobody told it exactly what "right" means, nobody fenced it in, and nobody checked. A cleverer prompt does not fix that. Structure does.

This tutorial walks you through the structure I use, one step at a time. I have built a real product this way, in public, and I will point at it as we go: open-office-harness. Everything you need to copy, the blank templates and ten detailed chapters, is in a companion repo: SpecDev using a Harness. Read this first. Use the repo when you sit down to do it.

What you will have at the end

  • One small piece of software, built by AI agents from a written spec.
  • Proof that it works: a list of checks that each say PASS or FAIL.
  • A review by a different AI, with every finding decided by you.
  • A tag in git you can always return to.
  • Records good enough that a brand-new AI session can carry on tomorrow.
Flow diagram of the spec-based development loop: the owner decides, a planner AI writes the spec, a different AI reviews it, builder AIs each build one Part, a reviewer checks each Part, and the owner runs the checks and accepts.
The whole loop. This tutorial takes you around it once.

What you need

  • Git and a terminal. Linux or macOS is easiest.
  • An AI coding tool that runs in a terminal. Any one will do. A "harness" is simply the program that wraps an AI model so it can read files, run commands and follow rules.
  • tmux, a free program that shows several terminals side by side.
  • A small thing you want built. Keep the first one tiny.

You also need four roles. The owner is you: you decide, test and accept. The planner is an AI session that writes the spec and keeps the records, and writes no product code. A builder is an AI session that builds exactly one share of the work. The reviewer is a different AI session that checks the work and reports problems only. One person with one AI tool can play all of this by opening separate sessions.

Step 1: Write the rules once

Before any spec, write one file that says how everything is built, in every stage, by every agent. I keep it at docs/specs/00-GLOBAL-RULES.md. Your AI tool reads a start file with a fixed name (often AGENTS.md); make that a short pointer to the rules file.

The most valuable part is a list that begins "A builder never:". Write each line so it can be seen in a command or in a list of changed files:

  • never runs privileged commands such as sudo;
  • never changes a file its share of the work does not list;
  • never puts a password, token or key in the repo, a log or a report;
  • never deletes data;
  • never adds a feature the spec did not ask for.

Then give it a way forward, or it will stall or cheat: when a builder needs something only the owner may do, it writes the exact commands into a script and stops.

An agent told "be careful with the server" has nothing to act on. An agent told "never run sudo" has a rule it can check before every command.

Copy the template: 00-GLOBAL-RULES.md. The full explanation is in chapter 2.

Step 2: Write down what you decided

Now the spec for your first stage. A stage is one piece of the product that can be built, tested and accepted on its own. The spec starts with a section most people skip: the owner's words and decisions. One dated line for each thing you decided.

  • 02 Mar 10:14: Reminders go out on day 7 and day 21 after the due date, never more than two.
  • 02 Mar 10:20: "No new email provider." Use the mail relay we already pay for.

This is the most important habit in the whole method. A planner AI suggests many things in conversation. Only what you agreed to goes here. It stops the AI's ideas from quietly becoming your decisions, and when someone questions a choice later, the answer is a dated line, not a memory.

Step 3: Write "Done when" before the design

Write a few lines of purpose: what exists after this stage that did not exist before. Then, straight away, write Done when: a numbered list of checks. Each one is something you can run, with a result that is plainly pass or fail.

  • Weak: "The API is secure." Strong: "A request without a token returns 401."
  • Weak: "Emails are not duplicated." Strong: "Run the job twice the same day; the count of sent emails does not change."
  • Weak: "It survives a restart." Strong: "After a reboot, the check script passes again without anyone touching the server."

Put the checks into one script that prints one PASS or FAIL line per check and ends with DONE. On the real build, the first stage ended with 27 such lines. By the fifth, the scripts printed 199 PASS and 0 FAIL on the live system, and anyone with the repo can run them again.

If you cannot write the checks, you do not yet know what you are building.

Then fill in the rest: the decisions already made (exact versions, looked up today, with the reason for each), what is out of scope, the files no builder may touch, and an honest list headed Unverified. The blank spec is here: stage-spec.md. Every section is explained, with a real spec beside it, in chapter 3.

Step 4: Have a different AI review the spec

Open a new AI session, not the one that helped you write the spec. Tell it to read the rules and the spec, change nothing, and report findings only: where, what is wrong, what it conflicts with. No praise.

Fix the spec, record what changed in a table at the end of the spec, and review once more. On the real build, the first review of one spec found 30 things, and the second review found 8 more, all before a single line of code. A mistake found in the spec costs a sentence. The same mistake found in the code costs a rebuild.

Step 5: Split the work into Parts

One builder is fast. Two at the same time are faster, but only if they never trip over each other. Split the stage into Parts. Each Part gets a branch, a builder and a literal list headed "Files (only these)". The one rule:

No Part changes a file another Part lists.

A good first cut is the code on one side and "getting it running" (build, deploy and check scripts) on the other. Whatever both Parts must spell the same way, such as a port or a variable name, goes into one table of fixed names. Then give each builder its own folder with git worktrees:

  • git tag -a stage-1-base -m "Stage 1 base"
  • git worktree add ~/projects/worktrees/stage-1-part-a -b stage-1-part-a stage-1-base
  • git worktree add ~/projects/worktrees/stage-1-part-b -b stage-1-part-b stage-1-base
Flow diagram: three Parts start from one base commit on their own branches, each is reviewed, and they are then merged with no conflicts and checked again.
Every Part starts from the same commit, on its own branch.

More on where to cut, and what to do when two Parts need the same file, in chapter 4.

Step 6: Run the builders side by side

Open one tmux window with a titled tile per job: two builders, one reviewer, and one shell that is only yours. Anything that needs a password is typed in your shell and nowhere else. The repo has a script that builds this layout in one command: tmux-work.sh.

Start each builder inside its own folder with the same first instruction: read the rules, read the spec, build only your Part, change only the files it lists, and if anything is unclear, stop and ask. Then watch. If an agent asks a question, answer it, and if the answer changes what anyone builds, write it into the spec. If an agent edits a file that is not on its list, stop it at once. Stopping early is cheap.

Decide how much each agent may do without asking you before it starts, and never let one agent answer another agent's permission prompt. That key is yours. See chapter 5.

Step 7: Report, review, decide, fix

Every builder ends with a report under the same seven headings. Three of them matter most: what it could not do, where it deviated from the spec, and its open questions. They give the builder honest places to say what did not go to plan. Treat the report as a claim to check, never as evidence.

Then a new reviewer session checks each Part against the spec and the rules, with a numbered checklist, and reports findings only: file, line, what is wrong, what the spec says.

Do not pass the findings straight to the builder. You decide each one first: fix it, change the spec, accept it with a reason, or reject it. Then the builder fixes, and a fresh session reviews the fixes too, because fixes are new code written in a hurry.

The report format, the checklist and the fix request are all templates in the repo, explained in chapter 6.

Step 8: Test it yourself, then accept and tag

Merge the Parts into one stage branch. If the file lists did not overlap, there are no conflicts; a conflict means a Part crossed its fence. Run every check again on a clean copy.

Then it is your turn. Deploy it, run the "Done when" script, restart, and run it again. Reviews find what can be read. Only running finds the rest: on the real build, the first live run of one stage found four problems that the spec reviews and the code reviews had all missed.

When every line says PASS, say the word: accepted. Merge to main and tag it. Every stage leaves two tags, where the builders started and what you accepted, so you can always go back to exactly that point.

Step 9: Write it down, every time

An AI agent remembers nothing between sessions. So the project keeps a memory in plain files, written in the same turn things happen:

  • a status file in the repo: what is built, what was checked (with numbers and dates), and what is still open;
  • a session log: what happened, in order, with times;
  • a decisions file: what you agreed, and why;
  • a journal of mistakes and the rule each one produced;
  • a handover at the end of each session, so the next one starts cold and loses nothing.

A status file with nothing listed as open is not finished. It is unwritten. The log templates and the handover prompt are in the repo; chapter 7 and chapter 8 show how I use them.

What this bought me

On the real build, this method took a product from an empty server to a copy running on managed cloud Kubernetes: six accepted stages in six days, with two to four AI builders working in parallel. It was not free of problems, and I have written those down too. Chapter 10 walks through every stage, including what went wrong and what changed because of it.

What it will not do for you

It will not replace your judgement. The method makes an agent's work checkable. Deciding what is worth building, and whether an architecture is sound, is still your job. If you cannot tell whether a spec is right, the agents cannot save you. That is the point of the whole thing: the human stays in the loop, able to see, reroute and approve at every moment.

Your turn

Pick something you could build in an afternoon. One small tool, one stored thing, one check script. Take it once around the loop.

When you have done two stages this way, you will not want to go back to "build me the app".

Sources