From stdd-agents
Use during REFACTOR phase of TDD (after GREEN), when logic is duplicated, or when locality of behavior is violated. Defines search-first workflow, duplication detection, locality principles, and safe refactoring practices.
npx claudepluginhub craigtkhill/stdd-agents --plugin stdd-agentsThis skill uses the workspace's default tool permissions.
This skill provides detailed guidance for the **REFACTOR** phase of the RED-GREEN-REFACTOR cycle and for any situation where code structure needs improvement without changing behavior.
Creates isolated Git worktrees for feature branches with prioritized directory selection, gitignore safety checks, auto project setup for Node/Python/Rust/Go, and baseline verification.
Executes implementation plans in current session by dispatching fresh subagents per independent task, with two-stage reviews: spec compliance then code quality.
Dispatches parallel agents to independently tackle 2+ tasks like separate test failures or subsystems without shared state or dependencies.
This skill provides detailed guidance for the REFACTOR phase of the RED-GREEN-REFACTOR cycle and for any situation where code structure needs improvement without changing behavior.
When to use this skill:
Refactoring belongs exclusively in the REFACTOR phase — never while RED or during GREEN.
RED → Write a failing test (no refactoring here)
GREEN → Write minimal code to pass (no refactoring here)
REFACTOR → Improve structure NOW ← (this skill)
VERIFY → Run all tests again
REPEAT → Next test
The GREEN phase produces working but possibly messy code. The REFACTOR phase is the designated time to clean it up. Mixing feature work and refactoring in the same step makes both harder and riskier.
Duplicated logic is not just a style concern — it is a correctness risk. When the same logic exists in two places, a bug fix or behavior change applied to one copy will silently leave the other broken.
Triggers that require refactoring:
Apply the rule of three: the first occurrence is fine, the second is a warning, the third is a mandate to extract.
Definition: Behavior that belongs to a concept should live close to that concept. Code that changes together should live together.
Locality of behavior means:
Violations to watch for:
Balancing locality vs. deduplication:
Always search before implementing new functionality.
Use code search tools to find:
Search strategies:
When similar code is found, evaluate:
Questions to ask:
Red flags for duplication:
See STRATEGIES.md for the full list of strategies with When/Action/Benefit.
Safety rules for refactoring:
All tests must be GREEN before starting
Make small, incremental changes
Run ALL tests after each change
If tests fail, revert immediately
Keep refactoring separate from feature work
After refactoring:
Verification checklist:
Refactoring belongs in Step 4 of the RED-GREEN-REFACTOR cycle:
When implementing new features:
See STRATEGIES.md for the full list of anti-patterns.
Skip refactoring when:
Before writing new code:
During refactoring:
After refactoring:
For guidance on splitting large files into modules: See FILE-ORGANIZATION.md for guidelines on when and how to split files.