| name | refactoring |
| description | Use proactively at the end of each implementation slice when project workflow requires it, or when a user asks to refactor, simplify, clean up, or restructure code while preserving behavior. Do not wait for an explicit user request if the workflow already mandates a post-implementation pass (features and bug fixes). Applies Martin Fowler style refactoring discipline and points to one reference file per refactoring from the official catalog. |
Refactoring Fowler
Use this skill when the goal is to improve code structure without changing observable behavior.
When your repository agent guide or team workflow mandates it, run this skill as a required pass after each implementation slice finishes green—feature or bug fix—before calling that slice complete or moving to the next review gate. Start that pass on your own initiative; do not wait for the user to say “refactor” or ask for cleanup. In-loop tidy-ups while coding are not a substitute.
The official source is Martin Fowler's Refactoring and the online catalog:
Read references/fowler-refactoring.md for the high-level principles.
Read exactly one per-refactoring reference file from references/refactorings/ when you decide which transformation to apply.
Core Rules
- Refactor in small, behavior-preserving steps.
- Keep the code working at each meaningful checkpoint.
- Run fast tests often while refactoring.
- Prefer many safe changes over one large rewrite.
- Rename for clarity early when names are misleading.
- Remove duplication only when it is real duplication, not coincidence.
- Inline indirection that no longer earns its keep.
- Delete dead code, debug scaffolding, and speculative abstractions.
Standard Workflow
- Identify the behavior that must not change.
- Find or add the smallest useful tests around that behavior.
- Choose the lightest refactoring that addresses the current smell.
- Make one small structural change.
- Run the fastest relevant tests.
- Repeat until the design is materially simpler.
- Run the broader validation pass.
Refactoring Index
Use the linked file for the exact mechanics you want. Do not load all references by default.
Validation Discipline
- Run fast unit tests often during the refactor.
- Run integration tests before declaring the work done.
- If UI changed, do a manual visual verification pass after automated tests.
- If behavior is uncertain, stop and add characterization coverage before proceeding.