Slower on Purpose: An AI Coding Workflow That Writes Maintainable Code

We traded speed and tokens for code a team can live with: plans that get challenged, small points, narrow reviewers, and rules the agent can't ignore. With a prompt to set it up yourself.

Slower on purpose: an AI coding workflow drawn as a pipeline of gates, from plan to review to a push gate

Coding agents are fast. Give one a feature and you'll have working code before your coffee is cold.

Then you read it. Spaghetti code that does the job and nothing else. No long-term architecture, just whatever was the shortest path from the prompt to a passing build. Horrible names: data, result2, HandleStuff. Logic dropped into whichever file was open. Code that works today and that nobody, including the next agent, can safely change in six months.

That was our experience with agents left to themselves. And many of the problems broke rules we had already written down, because a rule in a document is a suggestion an agent is free to skip.

So we built a workflow that is slower on purpose. It spends more tokens and more wall-clock time on every feature, and in return the code is readable, well named, and fits an architecture we can keep living in. This post describes it in general terms, so you can build your own, and ends with a prompt to set it up.

Rules an agent can ignore will be ignored. Put each rule where it can't be.

The flow: plan, plan review, human approval, then for each point a sketch, sketch review, code and tests, review lanes in the background, and a push gate before every push
The whole flow. Every arrow is a gate the agent can't skip.

The flow at a glance

  1. Plan. A planner agent writes a short design document.
  2. Plan review. Three reviewers challenge it in parallel, once.
  3. Approval. A human approves the plan. No code is written before that.
  4. Build in points. For each small point: a one-screen sketch, a review of the sketch, then the code and its tests.
  5. Review lanes. Narrow reviewers check each point in the background while the next one starts.
  6. Push gate. Before anything is pushed, every check runs and every finding must be fixed or explained.

Hooks enforce each step. The agent can't write code without an approved plan, can't skip the gate, and can't edit the files that enforce any of this.


1. Plan like a senior engineer

The planner writes what a senior engineer writes before handing work to a junior one: the problem, the requirements, the edge cases, the approach, the architecture and the key decisions. About a thousand words and one diagram.

Three rules make the plans good:

  • No files, classes or fields. The plan is about the design, not the code. Naming comes later, with the code in front of you.
  • Every mechanism earns its place. Each one carries a one-line reason. A queue, a cache or a new table without a reason is cut.
  • Plan the whole request. No phases, no "we'll do that later", no time estimates. A plan that only covers the easy half isn't a plan.

The plan ends with the points to build, in order, and the open questions, each with options and a recommendation.


2. Challenge the plan before any code exists

A plan is cheapest to fix before there's code. Three reviewers read it in parallel:

  • The skeptic. Is this the right thing to build at all? How does it behave at a hundred times the load? Walk the next two or three requirements: does the design survive them? Is anything here that we don't need yet? A plan that flawlessly builds the wrong thing is still wrong.
  • The edge-case reviewer. What do real users do over time: twice, out of order, half-way, years later?
  • The requirements interviewer. Asks only the questions whose answer changes the design, and decides everything else itself.

Each gives at most five findings, and the planner folds them in once. A cap forces reviewers to rank, and a single round stops plan review from turning into an endless loop.


3. A human approves, and the approval is bound to the plan

Only the human's own message approves a plan. When they do, a hook records a hash of the plan alongside the approval. If the plan changes afterwards, the approval no longer matches and it has to be approved again.

Until there is a matching approval, another hook refuses every code edit. This is the single most important gate in the system: the agent cannot drift from "plan" to "just start coding".

A human approves the plan; the approval stores the plan's hash; any later change to the plan breaks the match and code edits are refused again
Approval is tied to the exact plan that was read.

4. Build in small points, sketch first

The build runs in a fresh session that reads only the approved plan, so nothing from the planning conversation leaks into the code.

For each point:

  1. Sketch. A fresh coder agent writes a one-screen sketch: the operations it will add, who calls them, the files, the edge cases, the tests. Then it stops.
  2. Review the sketch. Narrow reviewers check names, grouping, boundaries and tests on the sketch, where a fix costs a sentence.
  3. Build. The coder writes the code and its tests, using the project's generators for every new file.
  4. Commit and continue. The point is committed, the review lanes start in the background, and the next point begins.

Two rules for the coder matter more than they look. A generator that refuses is telling you the shape is wrong: fix the shape, don't hand-write around it. And never claim a build or test passed without running it.


5. Narrow reviewers, not one big one

One reviewer holding three hundred rules misses things. A reviewer with a short checklist misses less. So review is split into lanes, each one concern:

  • names
  • grouping (does this belong together?)
  • boundaries between modules and services
  • placement (is it in the right layer?)
  • tests
  • security
  • concurrency and money, when the code touches them
  • dead code and docs, once at the end

Which lanes run is decided by the files the point touched. Each lane follows the same protocol: read the whole files, not just the diff; stay in your lane; cite the rule; give the file and line; name the real user flow that breaks; say what is wrong, never how to fix it. Each lane also has a list of things that are not findings: a crash with no real user flow behind it, or "a future caller might…".

Then a separate verifier tries to prove each finding wrong. Findings that survive go back to the same coder, with its context, and are fixed first in the next point. Nothing is pushed until every finding is either fixed or listed with a reason.

One overloaded reviewer with a long rule list misses issues; several narrow lanes, each with a short checklist, catch them, and a verifier filters false positives
Short checklists, one concern each, and a verifier that tries to disprove every finding.

6. Put every rule where the agent can't ignore it

This is the heart of it. Every rule in the project has exactly one home, and the home decides how it's enforced:

  • A check. If a tool can decide it, a tool decides it. Analyzers turn conventions into build errors: at most four parameters, braces everywhere, no reading the clock directly, full-word names, booleans named as questions, one type per file, no layer reaching into one it shouldn't. A structure script checks what the compiler can't: folder sizes, banned names, one repository per domain, no references between services, no sleeps or retries in tests.
  • A generator. Use cases, tests and entities are created by a generator, so they all have the same shape. Hand-made ones are refused.
  • A card. A short rule file that loads only when the agent opens a matching file. A rule about database migrations loads when the agent touches a migration, not on every task.
  • The workflow. Rules about the process itself live in the hooks and the gate.

The always-loaded instructions file holds only what applies to every task, so it stays short. The full guides are for reviewers and people; the coder never reads them.

Two more details made a large difference. The agent copies the code next to it, so legacy folders carry a one-line note: legacy, don't copy. And allowlists only shrink: an exception list for a rule can lose lines but never gain them, so old exceptions die out instead of spreading.

Every rule has one home: a check (build error or structure script), a generator, a card loaded only for matching files, or the workflow's hooks and gate
One home per rule. The home decides how it's enforced.

7. Tests that prove behaviour

Agents love tests that prove nothing: "the mock was called", "it didn't throw". The rules are blunt:

  • A point is done when every behaviour that can break has a functional test through the operation's real entry point.
  • Unit tests only for a pure calculation or parser with its own branching.
  • No "mock was called" tests. One test per behaviour.
  • Never accept a flaky test, and never add retries. Use a fake clock, not real time.
  • Tests that cost money, like real model calls, run only for the part that changed, with a stated budget.

A separate test-writer agent writes tests only. If making a test pass needs a change to the application code, it stops and says so.


8. The push gate

Before every push, one gate runs everything in order and stops at the first failure: structure, knowledge-base links and rule IDs, docs that cite real code names, every prompt having a live test, the build and the tests, and finally every finding fixed or listed with a reason. A pass writes a small report tied to the exact code tree, and CI rejects any change whose report is missing or stale.

The hooks also block the obvious escapes: skipping git hooks, pointing git at another hooks folder, or editing the gate itself. Changing the enforcement files needs the human's explicit, time-limited permission. None of this stops a determined human, and it isn't meant to. It stops an agent from taking a shortcut by accident.


9. A system that learns

Every finding that survives verification gets a cause:

  • missing card: no rule covered it
  • unclear card: a rule existed but was misread
  • bad example: nearby code taught the wrong thing
  • no check: a tool could have caught it

A weekly review runs every lane over a whole service. And the rule that keeps the system improving: a kind of mistake found twice becomes a check. Over time, more rules move from prompts into tools, and the prompts get shorter.


The cost, and keeping it sane

This is slower and more expensive than letting an agent run. More model calls, more waiting, more tokens. We accept that, because maintainable code is the whole point. But we spend the effort where a miss is expensive:

  • Big models where judgement matters: planning, plan review and coding. Smaller, cheaper models for narrow lanes and the verifier, where the checklist does the thinking.
  • Small points skip the sketch review, and purely mechanical commits skip the lanes.
  • The build runs in a fresh session, and a coder whose context grows too large is replaced with a fresh one.
  • Any command output over a hundred lines goes to a file, and a small model reads it and reports only what matters.

The speed you lose up front, you get back every time someone, or something, has to change that code later.


A checklist for your own workflow

Checklist card: plan before code, challenge the plan once, bind approval to the plan, build in small points with a sketch first, review in narrow lanes, give every rule one home, test behaviour not calls, turn repeated mistakes into checks
The rules, on one card.
  1. Plan before code, with a reason for every mechanism.
  2. Challenge the plan once, with capped findings.
  3. Bind the human's approval to the exact plan, and refuse code edits without it.
  4. Build in small points, sketch first.
  5. Review in narrow lanes, and verify every finding.
  6. Give every rule one home, and prefer a check over a prompt.
  7. Test behaviour through real entry points, never "the mock was called".
  8. Turn every mistake found twice into a check.

A prompt to set this up

Paste this into your coding agent (it's written for Claude Code, but the shape works in any agent with sub-agents and hooks) at the root of your repository. Adjust the language-specific parts to your stack.

Set up a quality-first AI development workflow in this repository. We accept slower, more
expensive runs in exchange for readable, well-named, maintainable code with a clear architecture.
Study the codebase first, then create the following. Ask me only questions whose answer changes
the design.

1. Knowledge base: .ai-knowledge/INDEX.md as the single source of truth, with a routing table
   ("you are about to … → read guide X → rule prefix"). One guide per topic (naming, layering,
   testing, data access, errors). Each guide opens with "Rules at a glance", every rule has a stable
   ID that is never reused, and the guides state rules and reasons, never history.
2. Rule homes: a rule-homes file giving every rule exactly one home: check (analyzer, lint or
   structure script), generator, card (a short rules file loaded only for matching paths), or
   workflow (hooks and gate). Prefer a check whenever a tool can decide the rule.
3. AGENTS.md / CLAUDE.md: under 400 words, only what applies to every task, pointing to INDEX.md.
   Mark legacy folders with a one-line "legacy, don't copy" AGENTS.md.
4. Agents:
   - planner: writes plan.md (≤1000 words, one diagram): problem, requirements, edge cases,
     approach, architecture, key decisions with one reason each, points in order, open questions
     with options and a recommendation. No file, class or field names. No phases, no estimates.
   - plan-reviewer (skeptic: right thing? 100x scale? next 2-3 requirements? anything not needed
     yet?), edge-case-reviewer (real users over time), requirements-interviewer (only
     design-changing questions). At most 5 findings each, one round, run in parallel.
   - coder: contract first, then a one-screen sketch, stop for review, then code and tests using
     generators only. Never claims a build or test passed without running it. Never commits.
   - review lanes, one concern each (names, grouping, boundaries, placement, tests, security,
     dead code, docs), each a short checklist of rule IDs with a "not findings" list. Output
     JSONL: rule ID, file:line, the user flow that breaks, what is wrong (never the fix).
   - finding-verifier: tries to disprove each finding; tags kept ones with a cause
     (missing card | unclear card | bad example | no check).
   - test-writer: writes tests only; stops if a test needs an application change.
   Use the strongest model for planner, plan review and coder; a cheaper model for lanes and verifier.
5. Commands: /plan (session folder, planner, parallel plan review, fold once), /build (fresh
   session, per point: sketch → sketch review → code → commit → lanes in background, findings fixed
   first in the next point), /quick for small changes (no plan, lanes and gate still run), /gate.
6. Hooks: record approval only from my own "approve" message, storing the plan's hash; refuse code
   edits without a matching approval or a quick/fix mode; refuse hand-made files a generator
   should create; refuse additions to allowlists (they only shrink); block --no-verify and changes
   to the git hooks path; refuse edits to the enforcement files unless I explicitly allow it; run a
   fast structure check after each edit and report only that file's failures.
7. Tests: functional tests through each operation's real entry point; unit tests only for pure
   calculations; no "mock was called" tests; no retries or sleeps; a fake clock.
8. Push gate (pre-push hook and CI): structure, knowledge-base links, analyzers, build and tests,
   and every finding fixed or listed with a reason. Write a pass report tied to the code tree; CI
   rejects changes with a missing or stale report.
9. Learning loop: a /weekly-review that runs all lanes over one area; any mistake found twice
   becomes a check.

When done, show me the flow as a diagram and list what is enforced by tools and what still
relies on the prompt.

Closing

Agents will happily write code that works today and rots tomorrow. They're not careless; they're doing exactly what the setup lets them do. Change the setup: challenge the plan, keep each step small, review one concern at a time, and put every rule somewhere the agent can't skip it. It's slower. The code is worth keeping.

Kasper Sogaard

Founder and CEO of MagicDoor, and founder of Agent Parley, LoreStage and Revoco. 20 years building software at Amazon, Microsoft, Hulu, Disney and Royal Caribbean.