refactor-code

Refactor code incrementally with test-driven validation and automatic rollback.

2|2|Updated Oct 28, 2025
One-click install
npx skills add https://github.com/adolfoaranaes12/BMAD-ENHANCED --skill refactor-code-adolfoaranaes12
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-code
Source: https://github.com/adolfoaranaes12/BMAD-ENHANCED/tree/main/.claude/skills/refactor-code
Command: npx skills add https://github.com/adolfoaranaes12/BMAD-ENHANCED --skill refactor-code-adolfoaranaes12

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps teams safely identify refactoring opportunities from quality findings and apply changes in a test-driven, incremental fashion. It ensures behavior stays intact by running tests after each change and automatically rolling back on failures, reducing technical debt while preserving functionality.

Core Features & Use Cases

  • Test-driven refactoring with per-change validation
  • Automatic rollback on test failures
  • Risk-based prioritization (P0-P3) and incremental application
  • Full traceability via a refactoring log
  • Quality metrics before/after
  • Use during quality reviews to systematically reduce debt without breaking behavior

Quick Start

  • Load a task specification describing quality findings and ensure tests pass
  • Choose an aggressiveness level (Conservative, Moderate, Aggressive) or skip
  • Run the refactor-code skill to apply changes one at a time, validating tests after each step
  • Review the refactoring log and commit any approved changes

Frequently Asked Questions about refactor-code

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely refactor code without breaking functionality?

Safe code refactoring uses test-driven validation: apply changes incrementally, run tests after each step, and automatically rollback on failures. This preserves behavior while reducing technical debt, ensuring every modification is verified before commit.

Can I refactor code automatically based on quality findings?

Yes. Refactoring automation scans quality findings, prioritizes issues by risk level (P0-P3), and applies changes one at a time with test validation. You control aggressiveness (Conservative, Moderate, Aggressive) and review a full refactoring log before accepting changes.

What prerequisites do I need to run test-driven refactoring?

You need an existing test suite that passes, a task specification describing quality findings, and quality gates in place. The refactoring process validates against these tests incrementally, so comprehensive test coverage is essential for safe automation.

How does automatic rollback work if refactoring breaks tests?

After each refactoring change, tests run automatically. If any test fails, that specific change rolls back immediately, and the process continues with the next refactoring. This prevents broken code from persisting while maintaining forward progress.

What metrics and visibility do I get from the refactoring process?

The process generates comprehensive output: refactorings applied and failed counts, files modified, quality impact metrics (before/after), and a complete refactoring log for traceability. Use this data to review progress and commit approved changes.