◉CLAUDE LABJP
●THREADS — Message threads arrived in beta on the Messages API (11/2): the server keeps the conversation and you send only new messages●CONSOLE — Console IP allowlist is in beta (11/5): requests from addresses not on the list are refused●SONNET 4.5 — Retires on the Claude API on 11/30, 25 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST — Opus 4.8 fast mode is deprecated and will be removed on 11/30. Migrate to Opus 5.5●NEW — I Put a Ten-Line Promise File at the To…●THREADS — Message threads arrived in beta on the Messages API (11/2): the server keeps the conversation and you send only new messages●CONSOLE — Console IP allowlist is in beta (11/5): requests from addresses not on the list are refused●SONNET 4.5 — Retires on the Claude API on 11/30, 25 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST — Opus 4.8 fast mode is deprecated and will be removed on 11/30. Migrate to Opus 5.5●NEW — I Put a Ten-Line Promise File at the To…
Articles/Claude Code
⟐ Claude Code/2026-04-17Advanced

From Spec to Production: Spec-Driven Development with Claude Code

Driving tests, implementation, and docs from a YAML spec with Claude Code, plus measured bcrypt 72-byte results where a valid spec still yields broken code.

Claude Code282Spec-Driven DevelopmentTDD4Test AutomationCI/CD19SpecificationsQuality EngineeringWorkflow8

✦ Premium Article

Three months into a project, you open a function you wrote and think: "Wait, what was this supposed to do?" If you've experienced that moment, you're not alone.

The divergence between specs and code is one of software development's oldest problems. Test-Driven Development (TDD) offers one solution — "the test is the spec" — but the psychological overhead of writing tests first often slows teams down, especially in solo or small-team projects.

Over the past six months, I've been experimenting with a workflow built around Claude Code that sidesteps this problem entirely: write a structured specification, and let Claude Code generate the tests, implementation, and documentation from it. I call this Spec-Driven Development.

This article shares that workflow in full, including the code examples and the pitfalls I hit along the way.

Why Specs and Code Always Drift Apart

The typical development flow looks something like this:

  1. Gather requirements (Slack messages, Confluence pages, meetings)
  2. Write the implementation
  3. Open a PR once it "works"
  4. Add tests if there's time
  5. Document it later (which never comes)

The root problem is that specs live outside the code. They exist in chat logs and wiki pages, and keeping them synchronized with the implementation depends entirely on developer discipline.

TDD reframes this: "the test is the spec." But TDD requires you to write the test before you can write the implementation, which means you need to design the test first — another time-consuming task.

Claude Code changes the equation. When you write a structured specification, Claude Code can generate the test from it. You skip the test design step entirely.

The Spec-Driven Development Overview

The core idea is a clear division of labor:

Humans write:

  • Feature specifications (input → output contracts)
  • Business rules (edge cases, error handling policies)
  • Quality requirements (performance, security constraints)

Claude Code generates:

  • Test code based on the spec
  • Implementation that passes the tests
  • API documentation from the implementation
  • Review comments on diffs

The key is writing specs in a format Claude can read accurately. Structured YAML works better than natural language descriptions — Claude interprets it with higher fidelity.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Once you write a YAML spec, Claude Code auto-generates tests, implementation, and documentation — freeing you from manual test writing while maintaining code quality
✦Automating the 'write tests first' TDD principle with AI lets you eliminate bugs from the start. You can run the Red→Green cycle without writing a single line of code manually
✦A fully automated GitHub Actions pipeline—from spec to CI/CD—can be integrated into your project today, ensuring spec changes automatically propagate to tests, implementation, and docs
✦Catch the blind spot where a valid spec yields broken code: measured results across two bcrypt versions showing when a different password authenticates, and how to close the collision at the spec level
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Claude Code2026-04-26
Test-Driven Development with Claude Code — A TDD Workflow for the Agent Era
Adding the constraint of 'write tests first' to Claude Code stops the agent's drift and dramatically changes the quality of generated code. Here's the TDD workflow I arrived at after six months of trial and error.
⟐ Claude Code2026-07-29
The MCP Server Connects Fine and Still Hands Back Zero Tools — Catching Silent Capability Drift with a Tool Manifest Diff
A missing credential does not break the MCP handshake. initialize succeeds, tools/list succeeds, and the array comes back empty. Here is the measured behaviour, and a preflight that locks the expected tool surface and fails closed before the agent ever starts.
⟐ Claude Code2026-05-24
Five Filters I Use Before Wiring a Claude Code Skill Into My Daily Workflow
Public Claude Code Skills keep multiplying. As an indie developer running a few tech blogs through Claude Code, I share the filters that decide which Skills stay in my daily workflow — and which ones I quietly remove after a few days.