Skip to content

Spec-Driven Development

The biggest mistake with AI coding assistants? Jumping straight into implementation. Spec-driven development flips this: plan thoroughly, then execute precisely.

When you say “add a login feature” and let Claude figure it out:

  1. Claude makes assumptions (wrong ones)
  2. You correct them mid-implementation
  3. Context fills with back-and-forth
  4. Code gets rewritten multiple times
  5. Final result is inconsistent
Plan → Specify → Approve → Implement

Spend 30% of your time planning. Save 70% on implementation and debugging.

  1. Start with intent, not implementation

    > I need to add user authentication to this API
  2. Let Claude interview you

    > Before implementing, interview me about the requirements
    > using questions to clarify all decisions
  3. Answer the questions

    Claude asks about JWT vs sessions, refresh tokens, password policies, etc.

  4. Review the generated spec

    Claude produces a detailed specification. Review and refine.

  5. Approve and implement

    > This spec looks good. Implement it.

A spec should answer these questions:

  • What does it do?
  • What are the inputs and outputs?
  • What are the edge cases?
  • What errors can occur?
  • What patterns/architecture?
  • What libraries/frameworks?
  • How does it integrate with existing code?
  • What are the performance requirements?
  • How do we know it’s done?
  • What tests prove it works?
  • What does success look like?
# User Authentication Spec
## Overview
Add JWT-based authentication to the REST API.
## Functional Requirements
### Registration (POST /api/auth/register)
- Input: email, password, name
- Validation:
- Email: valid format, unique
- Password: min 8 chars, 1 uppercase, 1 number
- Name: 2-100 characters
- Output: user object (no password)
- Errors: 400 (validation), 409 (duplicate email)
### Login (POST /api/auth/login)
- Input: email, password
- Output: { access_token, refresh_token, expires_in }
- Errors: 401 (invalid credentials)
- Rate limit: 5 attempts per minute per IP
### Refresh (POST /api/auth/refresh)
- Input: refresh_token
- Output: { access_token, expires_in }
- Errors: 401 (invalid/expired token)
### Logout (POST /api/auth/logout)
- Input: refresh_token
- Action: Invalidate refresh token
- Output: 204 No Content
## Technical Decisions
### JWT Configuration
- Access token: 15 minutes expiry
- Refresh token: 7 days expiry
- Algorithm: HS256
- Secret: from environment variable JWT_SECRET
### Password Storage
- Bcrypt with cost factor 12
- Never log or return passwords
### Token Storage
- Refresh tokens stored in Redis
- Key: `refresh:{user_id}:{token_hash}`
- TTL: 7 days
## Files to Create/Modify
- app/routes/auth.py (new)
- app/services/auth_service.py (new)
- app/models/user.py (modify: add password_hash)
- tests/test_auth.py (new)
## Acceptance Criteria
- [ ] Can register new user
- [ ] Can login with valid credentials
- [ ] Cannot login with invalid credentials
- [ ] Access token grants access to protected routes
- [ ] Refresh token generates new access token
- [ ] Expired access token returns 401
- [ ] Rate limiting prevents brute force
- [ ] All endpoints have tests
> I want to add payment processing with Stripe
> Interview me to create a detailed spec before implementing

Claude will use the AskUserQuestion tool to gather requirements.

> Here's a rough idea:
> - Add Stripe payments
> - Support subscriptions and one-time purchases
> - Handle webhooks for payment events
>
> Expand this into a detailed specification
> Create a spec for adding email notifications using this template:
>
> ## Overview
> ## Functional Requirements
> ## Technical Decisions
> ## Files to Change
> ## Acceptance Criteria

Once you have a spec, start fresh:

Terminal window
# Save the spec
> save this spec to docs/specs/auth-spec.md
# Clear context
> /clear
# Or start new session
exit
claude
# Implement from spec
> implement the specification in docs/specs/auth-spec.md

If you want more structure, explore these frameworks:

A lightweight CLI toolkit with four phases:

  1. Specify - Define what and why
  2. Plan - Technical design
  3. Tasks - Break into actions
  4. Implement - Execute with AI
Terminal window
npx github-spec-kit init

A comprehensive multi-agent framework with specialized roles:

  • Analyst Agent (requirements)
  • PM Agent (planning)
  • Architect Agent (design)
  • Developer Agent (implementation)
Terminal window
npx bmad-method install

A spec-driven system designed for Claude Code:

Terminal window
# Uses Claude Code commands for orchestration
  • New features with multiple components
  • Architectural changes
  • Anything touching auth, payments, or data
  • Work that will be reviewed by others
  • Features you’ll need to maintain
  • Simple bug fixes
  • One-line changes
  • Exploratory coding
  • Throwaway prototypes
### Example Request
POST /api/orders
{
"items": [{"product_id": "123", "quantity": 2}],
"shipping_address": {...}
}
### Example Response
{
"order_id": "ord_abc123",
"status": "pending",
"total": 4999
}
### Errors
| Status | Code | When |
|--------|------|------|
| 400 | INVALID_INPUT | Missing required fields |
| 404 | PRODUCT_NOT_FOUND | Product doesn't exist |
| 409 | INSUFFICIENT_STOCK | Not enough inventory |
### Performance
- Response time: < 200ms p95
- Support: 100 concurrent requests
### Security
- All endpoints require authentication
- Rate limit: 60 requests/minute