Published on , Aurélien Vandaële

How to do spec driven development with Claude Code: spec, data probe, then plan

Before an agent writes a line of code, I write three things in files: a spec that says why, what we aim for and what we refuse; a probe of the real data when the feature reads external data; a plan split into tasks, each with its files and a “done when” line. My agent chain refuses to start when the probe is missing.

The problem: the agent fills the gaps on its own

A vague request does not stop an agent. It chooses for you, confidently, and its choices only show up at review time. The longer the feature, the more these small choices add up.

In my case, the most expensive part was not the code. On a run of my chain that built a conversion funnel for my apps, the four costliest defects came from the reality of the data:

  • Apple reports that overlapped and restated their own figures after the fact;
  • two sources that did not cover the same period;
  • a store “conversion” that was not the right ratio;
  • a trial threshold computed on cohorts that were still too young.

No reviewer could see them in the diff: the code did exactly what the plan asked. The plan was the thing built on a wrong idea of the data.

The spec: the why, and what we refuse

My spec is a docs/design.md file, written before any plan. It fits in a few short sections:

  • Why: the measured fact that justifies the work.
  • Goals: what must be true at the end.
  • Non-goals: what we do not do this time, so the agent does not widen the scope.
  • Anti-goals: what would be a failure even if everything works.
  • Shape: the files, the contracts, the decisions already made.

Anti-goals are the most useful section. For my agent chain plugin, I wrote three lines there: hooks that fire in a repo that has not adopted the plugin, a repo that has to copy scripts to benefit from it, an AI mention in a commit. An agent does not guess this kind of rule. You have to write it down.

The spec also serves later: my reviewer agent judges each diff against the brief or the spec, and the final review of the run refers to it too.

The probe: look at the real data before the plan

As soon as a feature reads an API, reports, analytics or a database, I first run /pipeline:probe, a skill from my plugin. Its instructions:

  • List every source read and every number displayed.
  • Fetch one real sample per source, with the project's own client. Read-only: never write to production, never spend money, never read .env files.
  • Write down, per source, its real fields and types, its granularity and window, its delay, its duplicates, its nulls and its definition of each metric.
  • Compute every displayed number by hand, end to end, and check that the numerator and denominator of each ratio share the same window, unit and population.

The result goes into a ## Probe section of the spec: the sample paths, the surprises, the definitions chosen and the expected values computed by hand. The tests then reuse them as their reference. My estimate, written in the skill: each of the four funnel defects would have cost a quarter of an hour at this stage, instead of three review rounds later.

The chain itself enforces the rule: if the plan depends on external data and the spec has no ## Probe section, /pipeline:build stops and asks for the probe.

The plan: tasks an agent can finish alone

The plan is a second file that points to the spec. Its shape is the same from one project to the next:

  • Goal and architecture in a few lines.
  • Global constraints, copied into the brief of every task.
  • Deviations from the spec decided while planning, written down instead of slipped into the code.
  • The tasks, each with the files it touches and a “done when” line.
  • The questions still open, at the end of the plan. That one is a rule from my global CLAUDE.md.

Before the first task, the orchestrator reads the plan once and looks for conflicts: two tasks that contradict each other, a required test that would pass before the code exists. Everything goes out as one batched question. Then each task gets its own brief in a file, and the chain writes the tests before the code.

For a small change, I do not write all of this. Claude Code's plan mode is enough: it reads the files and proposes a plan without editing anything until you approve. You turn it on mid-session with Shift+Tab, pressed until the status bar shows plan mode, or at launch:

claude --permission-mode plan

Files become useful when the work outlasts a session and passes between several agents: they all read the same text, and that text stays on disk even after a compaction.

What went wrong: a probe too close to my own data

On my expense-sharing app, one task was blocked after the two allowed fix rounds. The subject: recovering how an imported expense in a foreign currency was split, from amounts already converted and rounded.

The postmortem found two causes. The probe had only exercised my own export, which held a single currency, at a rate of about 0.5. No reference values existed for lower rates. And each fix brief described the algorithm for the case at hand, instead of the property to guarantee: for any rate, any number of members and any amount, the split adds up to the total and converts back to the stored amount.

Two rules came out of it. When a feature converts currencies, the probe samples at least one rate below 0.5 and one above 1, even if my data holds a single currency. And any rounding or conversion code gets a property test over several rates from the moment the tests are written. A probe shows what your data contains, not what it could contain. The spec has to cover the rest.

How to start

  • Write docs/design.md with the five sections above. Start with the anti-goals.
  • If the feature reads external data, fetch one real sample per source and compute every displayed number by hand. Paste the result into the spec.
  • Write the plan: tasks with their files, one “done when” line each, and the open questions at the end.
  • Have the plan executed task by task, in a fresh session, giving each agent its task brief rather than the whole conversation.

In my case, the two tooled steps come down to two commands from my plugin:

/pipeline:probe          # before a plan that reads external data
/pipeline:build plan.md  # runs the plan, task by task

When a task still gets blocked, the postmortem often says the spec was incomplete, and the spec is what gets fixed first. I describe that loop in the article on postmortems and retros.

Article written with the help of AI, from my daily practice and my projects.

The whole notebook