| name | plan-and-build |
| version | 2.0.0 |
| description | Use when a user wants to plan and implement a new feature or bug fix from scratch. Triggers on requests like "I want to build X", "add a feature for Y", "fix Z", or when the user invokes /plan-and-build. Guides through clarifying questions, breaks work into small features, sets up a tasks folder, implements each feature with TDD (test first), and produces a manual testing guide when complete.
|
| user-invokable | true |
| argument-hint | [feature or fix description] |
| license | MIT |
| allowed-tools | Read, Grep, Glob, Bash, Write, Edit, Agent |
Plan and Build
Overview
A structured workflow that turns a vague feature idea or bug report into working, tested code โ one small feature at a time. Combines targeted clarifying questions, TDD, and task tracking in a reusable folder structure.
Core principle: Ask first, build small, test first, document last.
Process Flow
digraph plan_and_build {
rankdir=TB;
"Explore codebase context" [shape=box];
"Detect test framework" [shape=box];
"Extract existing patterns" [shape=box];
"Ask clarifying questions\n(one at a time)" [shape=box];
"Propose approach\nand get approval" [shape=box];
"Create tasks/ folder\n(all-features, todo, done)" [shape=box];
"Setup Git branch\n(optional)" [shape=box];
"Pick next feature\nfrom all-features โ todo" [shape=box];
"Write failing test (RED)" [shape=box];
"Implement (GREEN)" [shape=box];
"Test failed?" [shape=diamond];
"Debug & recover\n(or mark blocked)" [shape=box];
"Move feature to done\n(with metadata)" [shape=box];
"More features?" [shape=diamond];
"Revisit blocked features?" [shape=diamond];
"Create guide/<name>.md\nimplementation guide" [shape=box];
"Explore codebase context" -> "Detect test framework";
"Detect test framework" -> "Extract existing patterns";
"Extract existing patterns" -> "Ask clarifying questions\n(one at a time)";
"Ask clarifying questions\n(one at a time)" -> "Propose approach\nand get approval";
"Propose approach\nand get approval" -> "Create tasks/ folder\n(all-features, todo, done)";
"Create tasks/ folder\n(all-features, todo, done)" -> "Setup Git branch\n(optional)";
"Setup Git branch\n(optional)" -> "Pick next feature\nfrom all-features โ todo";
"Pick next feature\nfrom all-features โ todo" -> "Write failing test (RED)";
"Write failing test (RED)" -> "Implement (GREEN)";
"Implement (GREEN)" -> "Test failed?";
"Test failed?" -> "Debug & recover\n(or mark blocked)" [label="yes"];
"Test failed?" -> "Move feature to done\n(with metadata)" [label="no"];
"Debug & recover\n(or mark blocked)" -> "Move feature to done\n(with metadata)" [label="recovered"];
"Debug & recover\n(or mark blocked)" -> "More features?" [label="blocked"];
"Move feature to done\n(with metadata)" -> "More features?";
"More features?" -> "Pick next feature\nfrom all-features โ todo" [label="yes"];
"More features?" -> "Revisit blocked features?" [label="no"];
"Revisit blocked features?" -> "Pick next feature\nfrom all-features โ todo" [label="yes"];
"Revisit blocked features?" -> "Create guide/<name>.md\nimplementation guide" [label="no"];
}
Phase 0 โ Detect Test Framework
Before exploring the feature space, figure out how this project tests. The TDD loop in Phase 4 depends on a working test command.
Detection checklist:
- Read
package.json โ check devDependencies and scripts.test for: vitest, jest, mocha, ava, playwright, cypress, bun test, deno test
- Look for config files:
vitest.config.*, jest.config.*, .mocharc*, pytest.ini, pyproject.toml ([tool.pytest]), phpunit.xml, Cargo.toml ([dev-dependencies]), go.mod
- Look for existing test files:
**/*.test.{ts,tsx,js,jsx}, **/*.spec.*, __tests__/, tests/, test/, *_test.go, test_*.py
- Note the runner command (e.g.
pnpm test, npm run test:unit, pytest -k, cargo test) and the single-file pattern (e.g. vitest run path/to/file.test.ts)
Decision rules:
- Framework found + tests exist โ record the runner command and continue
- Framework found, no tests yet โ record the runner, scaffold the first test in Phase 4
- No framework found โ ask the user: "I don't see a test framework. (A) Set up Vitest, (B) Set up Jest, (C) Skip TDD for this work, (D) I'll tell you the framework"
- Unfamiliar framework โ ask: "How do I run a single test file in this project?"
Record the answer in the tasks/all-features.md header (see Phase 3) so future sessions don't re-detect.
Phase 1 โ Explore and Extract Patterns
Read the codebase before asking the user anything:
- Check existing files, services, routes, components related to the request
- Check
CLAUDE.md for project conventions and patterns
- Check
tasks/ folder โ if features already exist, jump to Resuming Work below
Then identify 2โ3 existing features that resemble what's being built and extract their patterns:
| Pattern | What to look for |
|---|
| Naming | camelCase vs snake_case, file suffixes (.service.ts, _handler.py), test file naming |
| Directory layout | Where do similar features live? Co-located tests or separate __tests__/? |
| Error handling | Throw vs Result types vs error returns; centralized error middleware? |
| Logging | Which logger, what level conventions, what gets logged on error |
| API shape | REST resource style, RPC method names, response envelope ({ data, error } vs raw) |
| Validation | Zod, Pydantic, Joi, manual; where validation happens (boundary vs deep) |
If the codebase is legacy or inconsistent (different files use different patterns), surface the conflict and ask: "I see two patterns for X โ (A) the older approach in foo.ts, (B) the newer approach in bar.ts. Which should I follow?"
After extracting, ask clarifying questions one at a time. Prefer multiple choice (A/B/C). Stop when you have enough to propose an approach. Typical questions:
- What is the core workflow / user action?
- Who uses it and what access do they have?
- What data needs to be collected or shown?
- What happens after the action completes?
- Does it need to integrate with existing systems (payments, auth, etc.)?
Phase 2 โ Propose and Approve
Present 2โ3 approaches with trade-offs. Lead with your recommendation and why. Wait for explicit user approval before proceeding.
Phase 3 โ Task Folder Setup
Create these three files (or append to them if they already exist):
tasks/all-features.md
# [Feature Name] โ All Features
## Context
- **Test runner:** `<command from Phase 0>` (single-file: `<command> <path>`)
- **Patterns to follow:**
- Naming: <e.g. camelCase, files end in `.service.ts`>
- Errors: <e.g. throw `AppError`, caught by `errorMiddleware`>
- Logging: <e.g. `pino` at `info`/`error`>
- API shape: <e.g. REST, `{ data, error }` envelope>
- **Reference features:** `src/foo/`, `src/bar/`
## Features
- [ ] F01 โ short description
- [ ] F02 โ short description
...
tasks/todo.md
# TODO
## F01 โ [current feature]
Steps:
1. ...
## Blocked
_(features paused mid-implementation โ see Phase 4.5)_
tasks/done.md
# Done
_Completed features logged here with metadata._
Features must be small and independent โ each one should be implementable in a single focused session. A feature that touches UI, service, and route is too big; split it.
Phase 3.5 โ Git Branch (optional)
Ask once after the task folder is set up: "Want me to set up a feature branch and commit per feature, or do you handle git yourself?"
If the user opts in (or CLAUDE.md declares a convention like git-workflow: feature-branch-per-task):
- Branch:
feature/<kebab-case-feature-name> off the current default branch
- Per-feature commits: one commit when each feature moves to
done.md, message format F01: <short description>
- Final commit: the implementation guide gets its own commit, message
docs: add <feature> manual testing guide
If the user declines, or if CLAUDE.md says the user manages version control manually, skip this phase entirely โ do not run git commands.
This phase is opt-in. When in doubt, ask. Never force a branch on a user who hasn't asked for one.
Phase 4 โ TDD Implementation (repeat per feature)
REQUIRED SUB-SKILL: Follow superpowers:test-driven-development strictly.
For each feature:
- Update
tasks/todo.md with the current feature
- Write the failing test first โ run it with the Phase 0 runner command and confirm it fails for the right reason
- Write the minimal implementation to pass the test (follow patterns recorded in
all-features.md header)
- Run the test again โ confirm green
- Run the full test suite โ confirm nothing else broke
- Update
tasks/all-features.md (check the box)
- Append to
tasks/done.md with metadata (see format below)
- If Phase 3.5 was enabled, create the per-feature commit
- Update
tasks/todo.md to the next feature
- Repeat
Auto mode: Unless the user has said to ask for permission, proceed through all features without pausing. Only stop if a feature requires a decision the user hasn't answered yet.
done.md entry format
Append one block per completed feature:
## F01 โ [feature name] โ
- **Tests:** 4/4 passing
- **Files changed:** 3 (1 new, 2 modified)
- **Lines:** +120 / -8
- **Complexity:** Medium โ async DB write, external email call mocked
- **Notes:** <any non-obvious decision worth remembering>
Complexity rubric:
- Low โ pure logic, single file, no I/O, no async
- Medium โ async, one external dep, or touches 2โ3 files
- High โ multiple external deps, concurrency, transactions, or complex state machines
Phase 4.5 โ Error Recovery
When a test fails unexpectedly during implementation (redโgreen never goes green, or greenโred after a passing run):
REQUIRED SUB-SKILL: Follow superpowers:systematic-debugging for the diagnostic loop.
Quick recovery checklist (in order):
- Re-read the test expectation โ does it match what you actually intended to build? Often the test is wrong.
- Run the failing test in isolation โ
<single-file runner> <path> โ confirm it's not a side-effect from a sibling test
- Add a logging line at the assertion โ print the actual vs expected value
- Check the patterns recorded in
all-features.md โ did you drift from the project's error-handling or validation convention?
- Bisect the implementation โ comment out half, see which half breaks the test
The 15-minute rule: if you've been stuck on the same failing test for ~15 minutes with no narrowing of the cause, stop and mark the feature blocked. Don't grind.
To mark blocked:
- Move the feature's section in
todo.md from the active area to the Blocked section
- Add a short note: what was tried, the last error message, and the hypothesis you couldn't verify
- Pick the next feature from
all-features.md and continue
- After all unblocked features are done, return to blocked features with fresh context (often the next feature reveals the missing piece)
Example blocked entry:
## Blocked
### F03 โ webhook signature validation
- **Last error:** `Invalid signature` even with documented test vector
- **Tried:** swapped HMAC algorithms, checked encoding, verified secret
- **Hypothesis:** the upstream service may be using a non-standard canonical form โ need their docs
Phase 5 โ Implementation Guide
When all features in tasks/all-features.md are checked (and any blocked features have been resolved or explicitly deferred):
Create guide/<kebab-case-feature-name>.md with:
# [Feature Name] โ Manual Testing Guide
## Prerequisites
[What must exist before testing โ accounts, data, env vars]
## 1. [First test scenario]
Steps + expected result
## 2. [Second test scenario]
...
## Common Issues
| Issue | Likely cause | Fix |
The guide must be written for a human following it for the first time with no prior context.
If Phase 3.5 was enabled, commit the guide as the final commit on the branch.
Rules
- One question per message during Phase 1
- No production code before a failing test โ Iron Law
- Features stay small โ if a feature takes more than one file to explain, split it
- tasks/ folder is the source of truth โ always check it at the start of a session to resume work
- Auto mode by default โ don't ask for permission between features unless blocked
- 15-minute debug cap โ mark blocked and move on rather than grinding
Resuming Work
If tasks/all-features.md already exists, start here instead of Phase 0/1:
- Read the Context section of
tasks/all-features.md โ adopt the recorded test runner and patterns; don't re-detect
- Read
tasks/all-features.md โ find unchecked features
- Read
tasks/done.md โ understand what's already built (and the metadata of past features for sizing)
- Read
tasks/todo.md โ check if a feature is in progress, and check the Blocked section
- Continue from where work left off; consider blocked features first if you have new context
Common Mistakes
| Mistake | Fix |
|---|
| Features too large | Split until each fits in one focused session |
| Test written after implementation | Delete the code, start over |
| Skipping the guide at the end | The guide is part of the deliverable โ always write it |
| Stopping between features to ask permission | Work through all features unless blocked |
| Not reading codebase before questioning | Always explore first โ avoids redundant questions |
| Not detecting test framework before starting | Detect in Phase 0 โ discovering "no test runner" mid-implementation wastes the TDD cycle |
| Ignoring existing codebase patterns | Extract 2โ3 reference features in Phase 1 โ code that drifts from local convention is harder to review and maintain |
| Not documenting blocked features | Always write the Blocked entry with last error + hypothesis โ without it, the next session re-treads the same dead ends |
| Committing all features in one giant commit | One commit per feature (when Phase 3.5 is enabled) โ keeps review and rollback granular |
| Grinding past 15 minutes on a stuck test | Mark blocked, move on, return with fresh context |