refactor

Guide test-driven code refactoring with characterization tests and incremental commits.

1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/paulingham/.claude --skill refactor-paulingham
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/paulingham/.claude/tree/main/skills/refactor
Command: npx skills add https://github.com/paulingham/.claude --skill refactor-paulingham

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Safe, test-driven refactoring helps engineers identify and address code smells without changing observable behavior.

Core Features & Use Cases

  • Worktree isolation to sandbox changes and avoid disrupting the main branch.
  • Characterization tests to document current behavior before touching any code.
  • Small-step commits to ensure reversibility and traceability during refactoring.
  • Guided workflow for common refactoring patterns (Extract Method, Introduce Value Object, etc.) with safety checks. Use Case: When a module shows a long method or high coupling, apply safe refactoring with incremental validation.

Quick Start

Start a refactoring session by launching the software-engineer agent with worktree isolation, apply small changes with characterization tests, commit after each step, and discard the worktree if rejected.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor code safely without changing its observable behavior?

To refactor code safely, you need to isolate changes in a worktree, write characterization tests to document existing behavior, and apply small, validated changes with incremental commits to ensure traceability and reversibility.

What are characterization tests and when do I need them for refactoring?

Characterization tests document the current behavior of a module before you modify it. You need them during refactoring to create a safety net that catches unintended changes when applying patterns like Extract Method or Introduce Value Object.

How do I start a stepwise refactoring workflow using an isolated worktree?

Start a refactoring workflow by launching your agent with worktree isolation to sandbox changes away from the main branch. Apply small modifications, verify them with tests, commit after each step, and discard the worktree if the refactoring is rejected.

Can I use this guided refactoring approach for high coupling and long methods?

Yes, this guided refactoring approach is designed specifically for modules exhibiting long methods or high coupling. It applies safety checks and incremental validation to address these code smells without disrupting the software's functionality.

What is the best way to ensure reversibility during a code refactoring session?

The best way to ensure reversibility during code refactoring is to enforce small-step commits after every validated change. This practice provides traceability and allows straightforward recovery procedures if a specific refactoring step fails.

What happens if a refactoring step fails during the incremental validation process?

If a refactoring step fails during validation, the workflow enforces specific recovery procedures. You can revert the failed step using the traceable commit history or completely discard the isolated worktree to restore the original state.