Test-Driven Development
With the smallest possible iteration steps, use red-green TDD as follows:
- Ultrathink about the full scope of the task. Analyze what needs to be done,
ask the user any clarifying questions to fully understand it. Follow the
YAGNI (You Ain't Gonna Need It) principle and do NOT design functionality not
asked for, but feel free to note it and ask the user for feedback. Only then
design. Strive for simplicity. For any non-trivially sized plan, write it to
a scratch plan file.
- Run
./check.shto ensure you are starting from a clean baseline. - Write user-facing documentation for the feature or for any behavior changes
by a bugfix.
- Run
./check.shto confirm the baseline after the documentation changes. - Write ONE failing test for the smallest bit of functionality or a minimal bug
testcase. Tests are NOT allowed to access internal APIs or internal state of
the module being tested. If that precludes testing, ultrathink about making
the design more testable. NEVER write multiple tests at once. Feel free to
note any useful missing tests in the plan.
- Run
./check.shto observe the expected test failure. - Write the minimal code to make the test pass. Make sure to follow DRY (Don't
Repeat Yourself) principle: extract common functionality into reusable
functions or modules. If you find yourself writing similar code twice,
refactor it. Do not add obvious comments.
- Run
./check.shto confirm the test passes now. - Refactor the code if needed, one smallest possible refactoring at a time.
- Run
./check.shto confirm the refactoring did not break the code. - Go back to the refactoring step until you no longer see any good
refactorings.
- If the code change is at a logical commit size (see Commit Guidelines in
CLAUDE.md), invoke review-changes to inspect, fix, track, and repeat until
the original changes converge. Present its report and created off-path
tracking records. If it returns incomplete, resolve or surface the blocker
before advancing. During a fix owned by an already-active review-changes
loop, return to that loop for the next inspection instead of recursively
invoking it; all preceding TDD steps still apply. Skip review for routine
mechanical changes (comments, formatting, simple renames).
- Repeat for the next iteration.