Use when refactoring code - test-preserving transformations in small steps, running tests between each change
View on GitHubwithzombies/hyperpowers
withzombies-hyper
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/withzombies/hyperpowers/blob/main/skills/refactoring-safely/SKILL.md -a claude-code --skill refactoring-safelyInstallation paths:
.claude/skills/refactoring-safely/<skill_overview> Refactoring changes code structure without changing behavior; tests must stay green throughout or you're rewriting, not refactoring. </skill_overview> <rigidity_level> MEDIUM FREEDOM - Follow the change→test→commit cycle strictly, but adapt the specific refactoring patterns to your language and codebase. </rigidity_level> <quick_reference> | Step | Action | Verify | |------|--------|--------| | 1 | Run full test suite | ALL pass | | 2 | Create bd refactoring task | Track work | | 3 | Make ONE small change | Compiles | | 4 | Run tests immediately | ALL still pass | | 5 | Commit with descriptive message | History clear | | 6 | Repeat 3-5 until complete | Each step safe | | 7 | Final verification & close bd | Done | **Core cycle:** Change → Test → Commit (repeat until complete) </quick_reference> <when_to_use> - Improving code structure without changing functionality - Extracting duplicated code into shared utilities - Renaming for clarity - Reorganizing file/module structure - Simplifying complex code while preserving behavior **Don't use for:** - Changing functionality (use feature development) - Fixing bugs (use hyperpowers:fixing-bugs) - Adding features while restructuring (do separately) - Code without tests (write tests first using hyperpowers:test-driven-development) </when_to_use> <the_process> ## 1. Verify Tests Pass **BEFORE any refactoring:** ```bash # Use test-runner agent to keep context clean Dispatch hyperpowers:test-runner agent: "Run: cargo test" ``` **Verify:** ALL tests pass. If any fail, fix them FIRST, then refactor. **Why:** Failing tests mean you can't detect if refactoring breaks things. --- ## 2. Create bd Task for Refactoring Track the refactoring work: ```bash bd create "Refactor: Extract user validation logic" \ --type task \ --priority P2 bd edit bd-456 --design " ## Goal Extract user validation logic from UserService into separate Validator class. ## Why - Validation duplicated across 3 services - Makes