User Stories - Codebase Analysis & Story Breakdown
Analyze a codebase and break down a goal into small, atomic, implementable user stories. Do NOT implement anything — only analyze and plan.
Input
If $ARGUMENTS is empty, ask: "What goal would you like to break down into user stories? You can optionally add --format=gherkin for BDD-style output."
Otherwise, extract the goal and optional format flag (--format=json default, or --format=gherkin). If the format is invalid: "Invalid format. Use --format=json (default) or --format=gherkin for BDD-style output."
Workflow
- Explore the codebase with Glob/Grep/Read: architecture, patterns, frameworks, similar existing features
- Decompose the goal into 3–10 atomic user stories, each completable in one coding session (2–4 hours max)
- Sequence stories by technical and logical dependency — earlier stories enable later ones
- Estimate complexity per story: XS (<1h, single file), S (1–2h), M (2–4h), L (4–8h), XL (break it down further)
- Generate filename from the goal (see naming rules)
- Write the plan to
.context/[slug]-plan.md using JSON or Gherkin format
- Verify all stories have clear acceptance criteria and reasonable scope
Error Recovery
- Goal too vague: ask the user to clarify scope before proceeding
- Goal too broad (>10 stories): suggest splitting into separate plans
- No relevant codebase patterns found: note in Context Summary and plan from first principles
- Story too large (XL+): decompose into sub-stories before continuing
- Fewer than 3 stories: verify granularity is sufficient for the goal
Output File Naming
Generate a kebab-case slug from the goal:
- Remove articles (a, an, the, um, uma, o, a, os, as)
- Keep 3–5 keywords (nouns, verbs, key technologies)
- Lowercase, hyphens for spaces, append
-plan.md
- Save to
.context/ directory (create if needed)
| Goal |
File |
| "implement JWT authentication in the backend" |
.context/jwt-authentication-backend-plan.md |
| "create payment API with stripe" |
.context/payment-api-stripe-plan.md |
| "add image upload support" |
.context/image-upload-support-plan.md |
JSON Format (Default)
Create the plan file with this structure:
# Development Plan: [Goal Summary]
**Generated**: [ISO Date]
**Goal**: $ARGUMENTS
## Context Summary
[Current codebase state, relevant technologies, key architectural decisions]
## User Stories
```json
[
{
"id": "US-001",
"title": "Story title in user voice",
"description": "As a [user type], I want [goal] so that [benefit]. Implementation details...",
"acceptanceCriteria": [
"Specific, verifiable criterion 1",
"Specific, verifiable criterion 2",
"Specific, verifiable criterion 3"
],
"priority": 1,
"complexity": "S",
"dependencies": [],
"filesToTouch": ["path/to/file1.ts", "path/to/file2.ts"],
"notes": "Any technical notes or gotchas"
}
]
Implementation Notes
- [Key insight about architecture]
- [Potential risks or blockers]
- [Suggested testing approach]
Definition of Done
See [example-output.md](example-output.md) for a complete JSON example.
## Gherkin Format
When `--format=gherkin` is specified, output Feature/Scenario blocks instead of JSON. Each user story becomes a Feature with Scenarios for each acceptance criterion. Include metadata comments (`# Complexity`, `# Dependencies`, `# Files`) above each Feature block. All Gherkin output must be in English regardless of input language.
See [example-gherkin-output.md](example-gherkin-output.md) for the complete template and a six-feature example.
1---2name: user-stories3description: Analyzes a codebase and breaks down a goal into implementable user stories with clear acceptance criteria. Use when planning a new feature, estimating work, or creating a development roadmap. Outputs structured stories to .context/[goal-slug]-plan.md ordered by dependency. Filename is generated from the goal (kebab-case, 3-5 words). Do NOT implement anything - only analyze and plan.4---56# User Stories - Codebase Analysis & Story Breakdown78Analyze a codebase and break down a goal into small, atomic, implementable user stories. **Do NOT implement anything — only analyze and plan.**910## Input1112If `$ARGUMENTS` is empty, ask: "What goal would you like to break down into user stories? You can optionally add `--format=gherkin` for BDD-style output."1314Otherwise, extract the goal and optional format flag (`--format=json` default, or `--format=gherkin`). If the format is invalid: "Invalid format. Use `--format=json` (default) or `--format=gherkin` for BDD-style output."1516## Workflow17181. **Explore** the codebase with Glob/Grep/Read: architecture, patterns, frameworks, similar existing features192. **Decompose** the goal into 3–10 atomic user stories, each completable in one coding session (2–4 hours max)203. **Sequence** stories by technical and logical dependency — earlier stories enable later ones214. **Estimate** complexity per story: XS (<1h, single file), S (1–2h), M (2–4h), L (4–8h), XL (break it down further)225. **Generate filename** from the goal (see [naming rules](#output-file-naming))236. **Write** the plan to `.context/[slug]-plan.md` using JSON or Gherkin format247. **Verify** all stories have clear acceptance criteria and reasonable scope2526### Error Recovery2728- **Goal too vague**: ask the user to clarify scope before proceeding29- **Goal too broad** (>10 stories): suggest splitting into separate plans30- **No relevant codebase patterns found**: note in Context Summary and plan from first principles31- **Story too large** (XL+): decompose into sub-stories before continuing32- **Fewer than 3 stories**: verify granularity is sufficient for the goal3334## Output File Naming3536Generate a kebab-case slug from the goal:37- Remove articles (a, an, the, um, uma, o, a, os, as)38- Keep 3–5 keywords (nouns, verbs, key technologies)39- Lowercase, hyphens for spaces, append `-plan.md`40- Save to `.context/` directory (create if needed)4142| Goal | File |43|------|------|44| "implement JWT authentication in the backend" | `.context/jwt-authentication-backend-plan.md` |45| "create payment API with stripe" | `.context/payment-api-stripe-plan.md` |46| "add image upload support" | `.context/image-upload-support-plan.md` |4748## JSON Format (Default)4950Create the plan file with this structure:5152```markdown53# Development Plan: [Goal Summary]5455**Generated**: [ISO Date] 56**Goal**: $ARGUMENTS5758## Context Summary5960[Current codebase state, relevant technologies, key architectural decisions]6162## User Stories6364```json65[66 {67 "id": "US-001",68 "title": "Story title in user voice",69 "description": "As a [user type], I want [goal] so that [benefit]. Implementation details...",70 "acceptanceCriteria": [71 "Specific, verifiable criterion 1",72 "Specific, verifiable criterion 2",73 "Specific, verifiable criterion 3"74 ],75 "priority": 1,76 "complexity": "S",77 "dependencies": [],78 "filesToTouch": ["path/to/file1.ts", "path/to/file2.ts"],79 "notes": "Any technical notes or gotchas"80 }81]82```8384## Implementation Notes8586- [Key insight about architecture]87- [Potential risks or blockers]88- [Suggested testing approach]8990## Definition of Done9192- [ ] All acceptance criteria met93- [ ] Tests written and passing94- [ ] Code reviewed95- [ ] Documentation updated (if needed)96```9798See [example-output.md](example-output.md) for a complete JSON example.99100## Gherkin Format101102When `--format=gherkin` is specified, output Feature/Scenario blocks instead of JSON. Each user story becomes a Feature with Scenarios for each acceptance criterion. Include metadata comments (`# Complexity`, `# Dependencies`, `# Files`) above each Feature block. All Gherkin output must be in English regardless of input language.103104See [example-gherkin-output.md](example-gherkin-output.md) for the complete template and a six-feature example.