refactor-optimizer

Refactors code while preserving passing tests and enforcing SOLID/DRY principles.

Updated Apr 10, 2026
One-click install
npx skills add https://github.com/yuridefranca/ai-prompts --skill refactor-optimizer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-optimizer
Source: https://github.com/yuridefranca/ai-prompts/tree/main/src/skills/refactor-optimizer
Command: npx skills add https://github.com/yuridefranca/ai-prompts --skill refactor-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Improve and simplify working code without introducing regressions by applying systematic refactoring practices that preserve passing tests and align implementation with architecture and maintainability goals.

Core Features & Use Cases

  • Readability & Naming: Extract magic numbers and clarify intent with descriptive names and helper functions.
  • Architecture Alignment: Restructure code to follow project patterns and SOLID principles, extract classes or services when responsibilities grow.
  • Duplication & Performance: Remove duplication (DRY), optimize queries and batch operations, and apply measured performance improvements where bottlenecks exist.
  • Use Case: After a minimal implementation passes tests, iteratively refactor a feature branch to improve clarity, reduce technical debt, and optimize hot paths while running the test suite after each change.

Quick Start

Ask the refactor-optimizer to refactor the changed module while running the full test suite after each change to ensure tests remain green.

Frequently Asked Questions about refactor-optimizer

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

FAQPage Schema
How do I refactor code without breaking passing tests?

To refactor code without breaking passing tests, apply systematic changes iteratively and run the full test suite after each modification. If any test fails, revert the change immediately to preserve the green test state and ensure no regressions are introduced.

What is the best way to clean up code after a minimal TDD implementation?

Cleaning up code after a minimal TDD implementation involves iteratively improving readability, applying SOLID principles, and removing duplication. Extract magic numbers, clarify naming, and optimize queries while continuously running tests to validate each refactoring step.

Can I optimize database queries and batch operations during a refactor cycle?

Yes, you can optimize database queries and batch operations during a refactor cycle. Identify performance bottlenecks in hot paths and apply measured improvements to reduce query overhead, while ensuring the test suite remains green after each optimization change.

Does this refactoring approach work with feature branches and iterative cycles?

This refactoring approach works directly with feature branches and iterative cycles. You apply it to finished minimal implementations on feature branches, progressively reducing technical debt and improving clarity through repeated, test-validated refactoring passes.

When should I extract classes or services to align with SOLID principles?

You should extract classes or services to align with SOLID principles when module responsibilities grow beyond a single concern. Restructure the code to follow project patterns, ensuring architecture alignment and maintainability while keeping tests green.

Why does code refactoring require running tests after every single change?

Code refactoring requires running tests after every single change to guarantee that structural improvements do not introduce regressions. This test-driven safety net allows you to confidently apply DRY principles and readability enhancements, reverting immediately if failures occur.