refactor

Refactor codebases with a four-phase workflow and test safety.

5|1|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/agentpatterns/craft --skill refactor-agentpatterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/agentpatterns/craft/tree/main/plugins/crafter/skills/refactor
Command: npx skills add https://github.com/agentpatterns/craft --skill refactor-agentpatterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Refactoring code can destabilize behavior if tests are not preserved, documented, or properly scoped.

Core Features & Use Cases

  • Structured, end-to-end refactoring workflow with four phases: Prep, Main Refactoring, Final Evaluation, and Summary.
  • Emphasis on test safety, incremental commits, and clear traceability to minimize regressions.
  • Use Case: clean up a large module without changing external behavior while keeping a record of changes.

Quick Start

Identify the scope, propose a minimal safe refactor, implement it with small commits, and run tests after each change.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I safely refactor code without breaking existing behavior?

To safely refactor code without breaking behavior, follow a structured workflow with prep, main refactoring, evaluation, and summary phases, making incremental commits and running tests after each change to ensure test safety.

What is the best way to reorganize a large code module across multiple files?

The best way to reorganize a large module across multiple files is to identify the scope, propose minimal safe refactors, implement with small incremental commits, and run tests after each change to ensure external behavior remains unchanged.

How does test safety work during complex code cleanup and method extraction?

Test safety works by enforcing a strict workflow where all tests must pass after each incremental change, ensuring that method extraction and reorganization do not destabilize existing behavior during complex code cleanup.

Do I need existing tests to perform maintainability-focused refactoring?

Yes, existing tests are required for refactoring. The workflow mandates that all tests pass after each incremental change to ensure behavior remains unchanged and to minimize regressions during the reorganization process.

When should I not use a structured refactoring workflow?

A structured refactoring workflow with strict test safety and incremental commits may not suit rapid prototyping or experimental code changes where external behavior is intentionally unstable and full test coverage does not exist.