Claude Code Spec Workflow: Hướng Dẫn Thực Hành Spec-Driven Development

Claude Code Spec Workflow: Hướng Dẫn Thực Hành Spec-Driven Development

Giới Thiệu

Trong thế giới phát triển phần mềm hiện đại, việc kết hợp AI vào quy trình coding đang trở thành xu hướng không thể tránh khỏi. Tuy nhiên, phương pháp “vibe coding” – viết code dựa trên cảm hứng và prompt ngẫu nhiên – thường dẫn đến kết quả không nhất quán và thiếu cấu trúc. Claude Code Spec Workflow ra đời như một giải pháp để biến việc phát triển phần mềm với AI trở nên có hệ thống và chuyên nghiệp hơn.

1. Spec-Driven Development Là Gì?

Định Nghĩa

Spec-Driven Development (SDD) là một phương pháp phát triển phần mềm mà trong đó specification (đặc tả) trở thành trung tâm của toàn bộ quy trình engineering – từ planning và design đến implementation, testing và documentation. SDD nhấn mạnh việc viết specifications rõ ràng và có cấu trúc trước khi bắt đầu implementation.

Nguyên Lý Cốt Lõi

Thay vì “vibe coding” – phương pháp mô tả mục tiêu và nhận về một khối code có vẻ đúng nhưng thường không hoạt động chính xác, SDD đối xử với coding agents như những pair programmers nghiêm túc. Chúng xuất sắc trong pattern recognition nhưng vẫn cần hướng dẫn rõ ràng và không mơ hồ.

Quy Trình 4 Giai Đoạn

SDD hoạt động qua 4 giai đoạn với các checkpoint rõ ràng:

1. Specify (Đặc Tả): Tạo ra contract về cách code nên hoạt động, trở thành source of truth cho tools và AI agents.

2. Plan (Lập Kế Hoạch): AI agent phân tích spec và tạo ra kế hoạch chi tiết về architecture, constraints và cách tiếp cận.

3. Tasks (Nhiệm Vụ): Chia nhỏ spec và plan thành các công việc cụ thể, có thể review được, mỗi task giải quyết một phần cụ thể của puzzle.

4. Implement (Triển Khai): AI agent thực hiện từng task một cách có hệ thống, với developer review những thay đổi tập trung thay vì những code dump hàng nghìn dòng.

Ưu Điểm Của SDD

  • Giảm đoán mò: Spec rõ ràng giúp giảm thiểu sự bất ngờ và đảm bảo chất lượng code
  • Dễ thay đổi hướng: Chỉ cần update spec, regenerate plan và để AI agent xử lý phần còn lại
  • Phù hợp với dự án phức tạp: Đặc biệt hữu ích cho greenfield projects và feature work trong hệ thống hiện có

2. Claude Code Spec Workflow – Tổng Quan

Giới Thiệu Tool

Claude Code Spec Workflow là một toolkit tự động hóa được phát triển bởi Pimzino, cung cấp quy trình spec-driven development có cấu trúc cho Claude Code. Tool này transform các ý tưởng feature thành implementation hoàn chỉnh thông qua quy trình: Requirements → Design → Tasks → Implementation.

Các Tính Năng Chính

🎯 Quy Trình Phát Triển Có Cấu Trúc

  • Requirements Generation: Tạo user stories và acceptance criteria sử dụng định dạng EARS (WHEN/IF/THEN statements)
  • Design Creation: Tạo technical architecture và design với Mermaid diagrams để visualization
  • Task Breakdown: Chia design thành các atomic coding tasks tập trung vào test-driven development
  • Systematic Implementation: Thực hiện tasks một cách có hệ thống với validation dựa trên requirements

🛠 7 Slash Commands Chính

  • /spec-create <name> <description> – Tạo specification mới cho feature
  • /spec-requirements – Generate requirements document
  • /spec-design – Tạo design document
  • /spec-tasks – Generate implementation tasks
  • /spec-execute <task-number> – Execute specific tasks
  • /spec-status – Check status của specification hiện tại
  • /spec-list – List tất cả specifications

🏗 Cấu Trúc Project Tự Động

Sau khi setup, tool tự động tạo:

  • 📁 .claude/ directory: Chứa commands, templates, specs, và config files
  • 📝 7 slash commands: Để thực hiện complete workflow
  • 📋 Document templates: Đảm bảo formatting nhất quán
  • ⚙️ Configuration files: Cho workflow automation
  • 📖 CLAUDE.md: Với comprehensive workflow instructions

✨ Tính Năng Nâng Cao

  • Triple optimization commands: get-steering-context, get-spec-context, và get-template-context
  • Smart document handling: Bug documents sử dụng direct reading, templates sử dụng bulk loading
  • Session-based caching: Intelligent file change detection và cache invalidation
  • Real-time web dashboard: Monitor specs, tasks, và progress với live updates
  • Bug workflow system: Complete bug reporting và resolution tracking

3. Hướng Dẫn Cài Đặt và Sử Dụng

Yêu Cầu Hệ Thống

  • Node.js: 16.0.0 hoặc cao hơn
  • Claude Code: Đã cài đặt và configure
  • Bất kỳ project directory nào

Cài Đặt Claude Code (Prerequisite)

bash
# Install Claude Code
npm install -g @anthropic-ai/claude-code

# Verify installation
claude doctor

# Navigate to your project
cd your-awesome-project

# Start Claude Code (first time login required)
claude

Cài Đặt Claude Code Spec Workflow

Phương Pháp 1: Cài Đặt Nhanh (Khuyến Nghị)

bash
# Cài đặt trong current directory
npx @pimzino/claude-code-spec-workflow

# Cài đặt trong directory cụ thể  
npx @pimzino/claude-code-spec-workflow --project /path/to/project

# Force overwrite existing files
npx @pimzino/claude-code-spec-workflow --force

# Skip confirmation prompts
npx @pimzino/claude-code-spec-workflow --yes

# Test setup
npx @pimzino/claude-code-spec-workflow test

Phương Pháp 2: Global Installation

bash
# Install globally
npm install -g @pimzino/claude-code-spec-workflow

# Use anywhere
claude-spec-setup

Phương Pháp 3: Development Dependency

bash
# Install as dev dependency
npm install --save-dev @pimzino/claude-code-spec-workflow

# Run via package.json script
npx claude-spec-setup

Cấu Trúc Được Tạo Ra

your-project/
├── .claude/
│   ├── commands/
│   │   ├── spec-create.md
│   │   ├── spec-requirements.md  
│   │   ├── spec-design.md
│   │   ├── spec-tasks.md
│   │   ├── spec-execute.md
│   │   ├── spec-status.md
│   │   └── spec-list.md
│   ├── templates/
│   │   ├── requirements-template.md
│   │   ├── design-template.md
│   │   └── tasks-template.md
│   ├── specs/
│   │   └── (your specs will be created here)
│   └── spec-config.json
└── CLAUDE.md (created/updated)

4. Hướng Dẫn Sử Dụng Chi Tiết

Workflow Cơ Bản

Bước 1: Khởi Tạo Claude Code

bash
cd my-awesome-project
claude

Bước 2: Tạo Specification Mới

bash
# Trong Claude Code terminal
/spec-create user-dashboard "User profile management system"

Bước 3: Generate Requirements

bash
/spec-requirements

Output: User stories với EARS format (WHEN/IF/THEN statements) đảm bảo comprehensive requirement coverage.

Bước 4: Tạo Design Document

bash
/spec-design

Output: Technical architecture với Mermaid diagrams, plans components, interfaces, và data models.

Bước 5: Generate Implementation Tasks

bash
/spec-tasks

Output: Atomic coding tasks với focus vào test-driven development, references specific requirements.

Bước 6: Execute Tasks

bash
/spec-execute 1

Executes tasks systematically với validation against requirements, ensures quality và consistency.

Bước 7: Monitor Progress

bash
# Check current status
/spec-status

# List all specifications  
/spec-list

Web Dashboard (Tính Năng Nâng Cao)

bash
# Basic dashboard
npx -p @pimzino/claude-code-spec-workflow claude-spec-dashboard

# Dashboard with tunnel (share externally) 
npx -p @pimzino/claude-code-spec-workflow claude-spec-dashboard --tunnel

# Full tunnel configuration
npx -p @pimzino/claude-code-spec-workflow claude-spec-dashboard \
  --tunnel \
  --tunnel-password mySecret123 \
  --tunnel-provider cloudflare \
  --port 3000 \
  --open

5. Ví Dụ Thực Hành: Phát Triển Game Asteroids

Mô Tả Dự Án

Một developer đã sử dụng claude-code-spec-workflow để tạo một game 2D đơn giản where player controls spaceship để tránh falling asteroids. Score được tính dựa trên survival time.

Quy Trình Thực Hiện

bash
# 1. Tạo specification
/spec-create asteroids-game "A simple 2D action game where the player controls a spaceship to avoid falling asteroids. The score is based on survival time."

# 2. Generate 3 types of specs
- Requirements document (요구사항 정의서)
- Design document (설계서)  
- Task list (타스크 리스트)

# 3. Implementation using SDD methodology

Kết Quả

Developer đã thành công tạo ra một asteroids avoidance game hoàn chỉnh sử dụng:

  • LLM: Claude Sonnet 4
  • Frontend: HTML, CSS, JavaScript
  • Development Tools: Claude Code, claude-code-spec-workflow

Kỹ Thuật Sử Dụng

Trong video demonstration, developer đã sử dụng:

  • /spec-status để check workflow status
  • /spec-list để view tất cả specifications
  • /spec-create để tạo các specs với detailed content
  • Cuối cùng là gameplay video của completed game

6. Troubleshooting và Best Practices

Common Issues

❓ Command Not Found After NPX

bash
# Make sure you're using correct package name
npx @pimzino/claude-code-spec-workflow

❓ Setup Fails với Permission Errors

bash
# Try with different directory permissions
npx @pimzino/claude-code-spec-workflow --project ~/my-project

❓ Claude Code Not Detected

bash
# Install Claude Code first
npm install -g @anthropic-ai/claude-code

# Show verbose output
DEBUG=* npx @pimzino/claude-code-spec-workflow

# Check package version
npx @pimzino/claude-code-spec-workflow --version

Best Practices

1. Project Setup

bash
# Setup multiple projects efficiently
for dir in project1 project2 project3; do
  npx @pimzino/claude-code-spec-workflow --project $dir --yes
done

2. Testing Setup

bash
# Test setup trong temporary directory
npx @pimzino/claude-code-spec-workflow test

3. Workflow Efficiency

  • Auto-detects project type: Node.js, Python, Java, etc.
  • Beautiful CLI: Với progress indicators
  • Validation: Claude Code installation check
  • Safety: Preserves existing CLAUDE.md content

7. So Sánh Với Các Công Cụ Khác

Claude Code Spec Workflow vs GitHub Spec-Kit

  • GitHub Spec-Kit: Toolkit chính thức từ GitHub cho SDD với support cho multiple AI agents (GitHub Copilot, Claude Code, Gemini CLI)
  • Claude Code Spec Workflow: Chuyên biệt cho Claude Code với workflow tự động hóa và dashboard

Ưu Điểm Của Claude Code Spec Workflow

  • Dễ cài đặt: One-command setup
  • Tự động hóa cao: 7 slash commands có sẵn
  • Dashboard tích hợp: Real-time monitoring
  • TypeScript implementation: Comprehensive error handling

8. Tương Lai và Phát Triển

Xu Hướng SDD

Spec-driven development đang trở thành popular trong developer community như một cách để build software với structure hơn và ít “vibes” hơn. Nó đặc biệt phù hợp với greenfield projects và mid-to-large-sized features.

Limitations

  • UI-heavy work: Non-visual spec không hữu ích cho UI work
  • Small features: Tạo full-blown spec có thể overkill cho small features hoặc bug fixes
  • Overengineering risk: Có thể dẫn đến solutions phức tạp hơn cần thiết

Future of SDD

“Specs are the new code” – Sean Grove từ OpenAI team cho rằng 80-90% công việc của programmers là structured communication, và specs là cách tốt nhất để communicate về software functionality.

9. Kết Luận

Claude Code Spec Workflow đại diện cho bước tiến quan trọng trong việc kết hợp AI vào quy trình phát triển phần mềm một cách có hệ thống. Tool này không chỉ đơn thuần là automation mà còn là methodology giúp developers:

Lợi Ích Chính

  1. Cấu trúc hóa quy trình: Từ vibe coding thành systematic development
  2. Tăng chất lượng code: Thông qua spec-driven approach
  3. Cải thiện collaboration: Giữa developers và AI agents
  4. Giảm rủi ro dự án: Với clear specifications và validation

Khi Nào Nên Sử Dụng

  • Greenfield projects: Starting từ zero với clear vision
  • Feature development: Trong existing complex systems
  • Team collaboration: Cần consistent development approach
  • Quality-focused projects: Khi code quality là priority

Khuyến Nghị

Claude Code Spec Workflow là tool xuất sắc cho developers muốn áp dụng SDD methodology với Claude Code. Tuy nhiên, hãy nhớ rằng tool chỉ là means, methodology và mindset mới là điều quan trọng nhất.

Hãy bắt đầu với những dự án nhỏ, làm quen với workflow, và dần mở rộng sang những dự án phức tạp hơn. Spec-driven development không phải là silver bullet, nhưng chắc chắn là một powerful approach trong arsenal của modern developers.


Demo:

Sử dụng claude cli + claude-code-spec-workflow test tạo workflow cho chức năng  user-authentication

Kết quả :
Tạo ra code và spec cho chức năng  user-authentication

————————————————————————————————————————————————————————————————————————————–

Sử dụng claude cli + claude-code-spec-workflow test 1 game đơn giản bằng html

Kết quả :