Spec-Kit Baseline
Generate structured feature specifications by analyzing existing source code. Reverse-engineers requirements, user stories, and success criteria from implementation.
When to Use
- Documenting existing features that lack specifications
- Understanding legacy code before refactoring
- Creating specs for inherited or acquired codebases
- Generating documentation from implemented functionality
- Preparing brownfield code for the Spec Kit workflow
Execution Workflow
The user's input after the skill invocation specifies the code to analyze. The workflow:
Parse target input: Identify files, directories, or patterns to analyze
- Accept file paths, glob patterns, or directory paths
- If empty: ERROR "No code target provided - specify files, directories, or patterns"
Discover and read source files:
- Expand glob patterns to file list
- Read file contents for analysis
- Identify primary language(s) and frameworks
- Map file relationships and dependencies
Analyze code structure:
- Identify entry points and public interfaces
- Extract function/method signatures and behaviors
- Find data models and entities
- Detect API endpoints and routes
- Identify user-facing functionality
Generate short name (2-4 words) from analyzed code:
- Use action-noun format (e.g., "user-auth", "payment-processing")
- Base on primary functionality discovered
- Preserve technical terms where meaningful
Check for existing branches/specs and run setup script:
- Find highest feature number for this short-name
- Run
.specify/scripts/bash/create-new-feature.sh --json with calculated number and short-name
- Get BRANCH_NAME and SPEC_FILE paths from JSON output
Load spec template from .specify/templates/spec-template.md
Generate specification content:
- User Stories: Infer from user-facing code paths and interactions
- Acceptance Scenarios: Derive from test cases, validation logic, error handling
- Functional Requirements: Extract from business logic and constraints
- Key Entities: Identify from data models and schemas
- Success Criteria: Infer from existing metrics, logging, or performance code
- Assumptions: Document inferences made during analysis
Abstract implementation details:
- Convert technical patterns to user-focused requirements
- Remove framework-specific terminology
- Focus on WHAT the code does, not HOW it does it
- Express behaviors in technology-agnostic terms
Create spec quality checklist at FEATURE_DIR/checklists/requirements.md
Report completion with:
- Branch name and spec file path
- Summary of analyzed files
- Key features discovered
- Areas needing clarification or review
Key Points
- Focus on extracting WHAT and WHY from HOW
- Abstract away implementation details in the generated spec
- Document assumptions made during code analysis
- Flag areas where code behavior is unclear
- Preserve discovered business rules and constraints
- Use [NEEDS CLARIFICATION] for ambiguous code sections (max 3)
- Generated specs should be validated by someone who knows the feature
Example Transformations
Code Pattern → Spec Requirement:
if (user.role === 'admin') → "System MUST restrict action to administrator users"
password.length >= 8 → "Passwords MUST be at least 8 characters"
cache.set(key, value, 3600) → "System MUST cache results for improved performance"
try { ... } catch (e) { notify(e) } → "System MUST notify users when errors occur"
Code Pattern → User Story:
- Login endpoint with OAuth → "As a user, I can sign in using my social account"
- Shopping cart logic → "As a customer, I can add items to my cart for later purchase"
- Report generation → "As an analyst, I can generate reports on system activity"
Next Steps
After generating spec.md:
- Clarify with domain experts using
speckit-clarify
- Plan modernization/refactoring with
speckit-plan
- Compare generated spec with actual requirements to identify gaps
See Also
speckit-specify - Create specs from descriptions (forward direction)
speckit-clarify - Resolve specification ambiguities
speckit-plan - Create technical implementation strategy
1---2name: speckit-baseline-23description: Generate feature specifications by analyzing existing source code.4---5
6# Spec-Kit Baseline
7
8Generate structured feature specifications by analyzing existing source code. Reverse-engineers requirements, user stories, and success criteria from implementation.
9
10## When to Use
11
12- Documenting existing features that lack specifications
13- Understanding legacy code before refactoring
14- Creating specs for inherited or acquired codebases
15- Generating documentation from implemented functionality
16- Preparing brownfield code for the Spec Kit workflow
17
18## Execution Workflow
19
20The user's input after the skill invocation specifies the code to analyze. The workflow:
21
221. **Parse target input**: Identify files, directories, or patterns to analyze
23 - Accept file paths, glob patterns, or directory paths
24 - If empty: ERROR "No code target provided - specify files, directories, or patterns"
25
262. **Discover and read source files**:
27 - Expand glob patterns to file list
28 - Read file contents for analysis
29 - Identify primary language(s) and frameworks
30 - Map file relationships and dependencies
31
323. **Analyze code structure**:
33 - Identify entry points and public interfaces
34 - Extract function/method signatures and behaviors
35 - Find data models and entities
36 - Detect API endpoints and routes
37 - Identify user-facing functionality
38
394. **Generate short name** (2-4 words) from analyzed code:
40 - Use action-noun format (e.g., "user-auth", "payment-processing")
41 - Base on primary functionality discovered
42 - Preserve technical terms where meaningful
43
445. **Check for existing branches/specs** and run setup script:
45 - Find highest feature number for this short-name
46 - Run `.specify/scripts/bash/create-new-feature.sh --json` with calculated number and short-name
47 - Get BRANCH_NAME and SPEC_FILE paths from JSON output
48
496. **Load spec template** from `.specify/templates/spec-template.md`
50
517. **Generate specification content**:
52 - **User Stories**: Infer from user-facing code paths and interactions
53 - **Acceptance Scenarios**: Derive from test cases, validation logic, error handling
54 - **Functional Requirements**: Extract from business logic and constraints
55 - **Key Entities**: Identify from data models and schemas
56 - **Success Criteria**: Infer from existing metrics, logging, or performance code
57 - **Assumptions**: Document inferences made during analysis
58
598. **Abstract implementation details**:
60 - Convert technical patterns to user-focused requirements
61 - Remove framework-specific terminology
62 - Focus on WHAT the code does, not HOW it does it
63 - Express behaviors in technology-agnostic terms
64
659. **Create spec quality checklist** at `FEATURE_DIR/checklists/requirements.md`
66
6710. **Report completion** with:
68 - Branch name and spec file path
69 - Summary of analyzed files
70 - Key features discovered
71 - Areas needing clarification or review
72
73## Key Points
74
75- Focus on extracting WHAT and WHY from HOW
76- Abstract away implementation details in the generated spec
77- Document assumptions made during code analysis
78- Flag areas where code behavior is unclear
79- Preserve discovered business rules and constraints
80- Use [NEEDS CLARIFICATION] for ambiguous code sections (max 3)
81- Generated specs should be validated by someone who knows the feature
82
83## Example Transformations
84
85**Code Pattern → Spec Requirement**:
86
87- `if (user.role === 'admin')` → "System MUST restrict action to administrator users"
88- `password.length >= 8` → "Passwords MUST be at least 8 characters"
89- `cache.set(key, value, 3600)` → "System MUST cache results for improved performance"
90- `try { ... } catch (e) { notify(e) }` → "System MUST notify users when errors occur"
91
92**Code Pattern → User Story**:
93
94- Login endpoint with OAuth → "As a user, I can sign in using my social account"
95- Shopping cart logic → "As a customer, I can add items to my cart for later purchase"
96- Report generation → "As an analyst, I can generate reports on system activity"
97
98## Next Steps
99
100After generating spec.md:
101
102- **Clarify** with domain experts using `speckit-clarify`
103- **Plan** modernization/refactoring with `speckit-plan`
104- **Compare** generated spec with actual requirements to identify gaps
105
106## See Also
107
108- `speckit-specify` - Create specs from descriptions (forward direction)
109- `speckit-clarify` - Resolve specification ambiguities
110- `speckit-plan` - Create technical implementation strategy