refactor

Automate safe code refactoring with Red-Green-Refactor cycles and tests.

Updated Apr 12, 2026
One-click install
npx skills add https://github.com/mguinada/agent-skills --skill refactor-mguinada
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/mguinada/agent-skills/tree/main/skills/refactor
Command: npx skills add https://github.com/mguinada/agent-skills --skill refactor-mguinada

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactor Skill helps software teams simplify growing codebases while preserving existing functionality by enforcing a disciplined test-driven process.

Core Features & Use Cases

  • Incremental Red-Green-Refactor cycles to reduce risk during changes.
  • Maintain behavior with comprehensive tests, lint checks, and type hints.
  • Identify and address code smells, improve readability, and clarify responsibilities.

Quick Start

Choose a target module with an existing test suite and perform a small refactor iteration: write a failing test if needed (Red), implement the minimal change to pass (Green), and then refactor for clarity (Refactor). Repeat until all tests pass and quality checks are green.

Frequently Asked Questions about refactor

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

FAQPage Schema
What is the best way to refactor code without breaking existing functionality?

Safe code refactoring requires preserving functionality through tests using incremental Red-Green-Refactor cycles. Write a failing test, implement the minimal change to pass, then refactor for clarity while maintaining lint and type checks.

How do I start refactoring a module with an existing test suite?

To start refactoring, choose a target module with an existing test suite and perform a small iteration: write a failing test if needed, implement the minimal change to pass it, then refactor for clarity. Repeat until all tests pass.

Do I need an existing test suite to refactor code safely?

Yes, an existing test suite is required to refactor code safely. The process relies on tests to preserve functionality and verify incremental changes, ensuring that refactoring for clarity does not alter the original behavior.

Can I use the Red-Green-Refactor cycle to fix architectural debt and code smells?

Yes, the Red-Green-Refactor cycle is applicable to projects with architectural debt and code smells. It helps identify and address these issues by emphasizing incremental, verifiable changes that improve readability and clarify responsibilities.

What are the limitations of refactoring with TDD guardrails?

The primary limitation is the strict requirement for an existing test suite and clear goals for each refactor. Without tests to verify behavior, the incremental Red-Green-Refactor cycle cannot safely preserve functionality during changes.