refactor

Plan behavior-preserving code refactors into commit-by-commit steps.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/jnlanahan/Product-Agents-and-Skills --skill refactor-jnlanahan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/jnlanahan/Product-Agents-and-Skills/tree/main/skills/2-Define-Refactor
Command: npx skills add https://github.com/jnlanahan/Product-Agents-and-Skills --skill refactor-jnlanahan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactors often get risky and uncontrolled because it’s unclear what to change, how to preserve behavior, and how to keep progress verifiable with tests.

Core Features & Use Cases

  • Find mode (opportunity scanning): identifies where modules are too shallow, where seams/adapters could improve testability, and where refactoring would increase leverage and locality.
  • Plan mode (known refactor): scopes a specific refactor target, decomposes it into behavior-preserving tiny commits, and documents interface/seam decisions.
  • Safety-first refactor planning: emphasizes characterization tests when coverage is thin, working-tree cleanliness, and a commit-by-commit verification mindset.
  • Claude-Code refactoring workflow: produces a refactor plan written to .claude/refactor-plan.md and uses refactoring best practices (scope control, tests between commits, and stop for destructive operations).

Quick Start

Ask the AI to plan a safe refactor by saying: "Use the refactor skill to plan a shallow-to-deepening refactor for my codebase, then write the plan to .claude/refactor-plan.md."

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I plan a safe code refactor without breaking existing behavior?

To plan a safe code refactor, decompose the target into behavior-preserving tiny commits with pre-flight checks and characterization tests. This approach emphasizes a clean working tree and commit-by-commit verification to ensure behavior remains unchanged throughout the process.

What are seams and ports-adapters in refactoring?

Seams and ports-adapters in refactoring are interface boundaries that improve module testability and locality of change. By restructuring code around these boundaries, you increase leverage at the interface and isolate dependencies for safer, more verifiable modifications.

How do I find refactoring opportunities in an existing codebase?

To find refactoring opportunities in an existing codebase, scan for shallow modules that lack leverage. Identify where introducing seams or adapters would improve testability and increase locality of change, allowing for safer restructuring without adding new features.

How do I break down a large module refactor into testable steps?

Break down a large module refactor by scoping the target and decomposing it into tiny, testable commits. Document interface and seam decisions while running characterization tests between commits to verify behavior preservation at each step of the restructuring process.

Can I use this refactoring approach with low test coverage?

Yes, you can use this refactoring approach with low test coverage by writing characterization tests before starting. The safety-first planning method identifies thin coverage during pre-flight checks and prioritizes establishing verification tests before making structural changes.

When should I avoid restructuring modules for testability?

You should avoid restructuring modules for testability when the work involves introducing new features alongside structural changes. Safe refactoring requires strict scope control to separate behavior preservation from feature development, ensuring modifications remain verifiable and controlled.