refactor

Apply surgical refactoring to improve code quality without changing behavior.

20|2|Updated Oct 18, 2025
One-click install
npx skills add https://github.com/xdg/xdg-claude --skill refactor-xdg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/xdg/xdg-claude/tree/main/refactoring-agent/skills/refactor
Command: npx skills add https://github.com/xdg/xdg-claude --skill refactor-xdg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Surgical refactoring to improve code quality without changing behavior, enabling safer maintenance of large codebases.

Core Features & Use Cases

  • Surgical changes: targeted edits that fix smells while preserving interfaces and external behavior.
  • Behavior-preserving: preserves runtime behavior and external effects while restructuring.
  • Use cases: cleanup legacy code, extract modules, rename and extract methods for readability.

Quick Start

Provide the codebase path and the exact refactor goal so the agent can apply surgical changes.

Frequently Asked Questions about refactor

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

FAQPage Schema
What is surgical refactoring and when do I need it for legacy code?

Behavior-preserving refactoring applies targeted edits to fix code smells while preserving runtime behavior and external effects. It restructures code safely by ensuring no runtime changes occur during the cleanup of legacy code.

Can I rename methods and extract modules without breaking existing unit tests?

You clean up duplicated logic by applying surgical refactoring techniques like extracting modules and methods. This improves readability and maintainability in modular software projects with clear interfaces.

Do I need focused unit tests to verify a surgical refactor?

Yes, focused unit tests and static checks verify that surgical refactoring changes do not introduce runtime changes. They validate that the behavior-preserving transformations maintain the original external output.

What are the limitations of behavior-preserving refactoring for code cleanup?

Behavior-preserving refactoring is limited to modular software projects with clear interfaces. It targets naming inconsistencies, duplicated logic, and long functions, but may not suit projects lacking clear module boundaries or test coverage.