Spec Driven Workflow

Use when the user asks to write specs before code, define acceptance criteria, plan features before implementation, generate tests from specifications

What Is Spec Driven Workflow?

Spec Driven Workflow is a development methodology that mandates the creation of detailed specifications before any code is written. Unlike traditional approaches where specifications might be loosely documented or written in parallel with code, spec-driven workflow treats the specification as a binding contract. It explicitly defines what the system must, should, and will not do. Every code artifact, from implementation to tests, is directly traceable to requirements and acceptance criteria outlined in the specification. This approach brings structure and predictability to the development process, minimizing ambiguity and ensuring that all stakeholders share a common understanding of the desired outcome.

Why Use Spec Driven Workflow?

Adopting a spec-driven workflow offers several compelling advantages:

  1. Eliminates Rework: The majority of software defects—estimated at 60-80%—originate from misunderstood or incomplete requirements. By clarifying expectations before any coding begins, teams can resolve ambiguities early, drastically reducing costly rework later in the cycle.
  2. Forces Clarity: Articulating requirements in plain language exposes gaps in understanding. If a feature cannot be clearly specified, it is not ready for implementation. This discipline prevents teams from moving forward based on assumptions.
  3. Enables Parallelism: Once a specification is approved, different teams—frontend, backend, QA, documentation—can proceed in parallel, referencing the same authoritative contract.
  4. Creates Accountability: The specification becomes the definition of done. There is no room for subjective interpretation; features are either compliant with the acceptance criteria or not.
  5. Feeds Test-Driven Development (TDD): Acceptance criteria written in Given/When/Then format can be directly translated into automated tests, creating a seamless bridge between requirements and validation.

How to Get Started

Implementing a spec-driven workflow involves a sequence of deliberate steps:

  1. Draft the Specification: Before writing any code, capture the desired behavior, boundaries, and non-goals of the system. Use clear and unambiguous language.

  2. Define Acceptance Criteria: For each feature or requirement, specify how success will be measured, usually in the form of Given/When/Then scenarios.

  3. Review and Approve the Spec: Stakeholders—including product owners, developers, and QA—must review and sign off on the specification before implementation begins.

  4. Develop Tests from the Spec: Translate acceptance criteria directly into automated tests. For example, using a framework like Cucumber:

    Feature: User Login
    
      Scenario: Successful login with valid credentials
        Given a registered user exists
        When the user logs in with correct credentials
        Then the user should be redirected to the dashboard
  5. Code to the Specification: Begin implementation, ensuring all code corresponds to elements defined in the spec.

  6. Validate Against Acceptance Criteria: Continuously verify that the code meets the acceptance criteria through automated and manual testing.

Key Features

  • Specification-First Approach: No code is written until the specification is complete and approved.
  • Traceability: Every code and test artifact is linked to a specific requirement or acceptance criterion.
  • Contractual Clarity: The specification is treated as a contract, not merely documentation.
  • Parallel Development: Teams can work simultaneously, referencing the shared specification.
  • Automated Test Generation: Acceptance criteria are structured to support direct conversion into executable tests.

Practical Example

Suppose you are implementing a feature for password reset. The spec might include:

  • Must: Allow users to request a password reset via email.
  • Should: Ensure the password reset token expires after 30 minutes.
  • Will Not: Allow password reset via SMS.

Corresponding acceptance criteria:

Scenario: Password reset email is sent
  Given a user has forgotten their password
  When the user requests a password reset
  Then a password reset email is sent to the user

Scenario: Token expires after 30 minutes
  Given a user has received a password reset token
  When 30 minutes have elapsed
  Then the token is no longer valid

Implementation and tests proceed only after these specs are approved.

Best Practices

  • Involve Stakeholders Early: Ensure that product managers, developers, and QA collaborate on writing and reviewing specs.
  • Avoid Ambiguity: Use precise language and detailed acceptance criteria to eliminate misinterpretation.
  • Keep Specs Up to Date: If requirements change, update the specification first, then revise implementation and tests.
  • Automate Where Possible: Use tools that support spec-based test generation and validation.
  • Enforce the Rule: Do not allow code to be written for features not in the specification.

Important Notes

  • Spec-driven workflow is not just about documentation; it is about accountability and quality assurance.
  • This methodology may require a cultural shift, especially in organizations accustomed to rapid prototyping or informal requirements.
  • The upfront investment in specification pays dividends in reduced defects, improved predictability, and easier maintenance.
  • Specs should be living documents, evolving as requirements change, but always serving as the single source of truth for implementation and testing.
  • Adhering strictly to writing specs before code is essential; relaxing this rule undermines the workflow’s effectiveness.

For implementation details and examples, see the Claude Code Spec Driven Workflow skill on GitHub.