code-refactor

Refactor code in small verifiable steps while preserving external behavior.

2|2|Updated Dec 23, 2017
One-click install
npx skills add https://github.com/xriu/dotfiles --skill code-refactor-xriu
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: code-refactor
Source: https://github.com/xriu/dotfiles/tree/main/home/.skills/code-refactor
Command: npx skills add https://github.com/xriu/dotfiles --skill code-refactor-xriu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate unclear names, dead code, duplication, and convoluted logic that slow down development. This Skill restructures code safely in small, verifiable steps without changing external behavior, so improvements never introduce regressions. ## Core Features & Use Cases - Behavior-Preserving Refactoring: Renames unclear symbols, extracts helper functions, removes dead code, and simplifies control flow while keeping functionality identical. - Test-First Safety: Checks existing test coverage and adds tests for risky behavior before making changes, then re-runs verification afterward. - Scoped Execution: Focuses on requested files or symbols, avoids speculative abstractions and broad rewrites, and reports out-of-scope improvements instead of making them. - Use Case: Ask it to clean up a tangled utility module, and it will inspect call sites, plan small steps, simplify the logic, run the test suite, and summarize exactly what changed and what stayed the same. ## Quick Start Refactor the payment processing module to remove duplication and simplify the conditionals without changing its public interface.

Frequently Asked Questions about code-refactor

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

FAQPage Schema
How do I refactor code without breaking existing functionality?▼

Refactor in small steps while preserving external behavior: inspect call sites and dependencies first, confirm test coverage for risky behavior, make focused changes, and re-run tests after each step. This Skill follows exactly that process and summarizes verification results.

What types of code cleanup does refactoring cover?▼

Common refactor types include renaming unclear symbols, extracting cohesive helper functions, removing dead code, collapsing unnecessary wrappers, reducing duplication, and simplifying conditionals. It avoids speculative abstractions and broad architecture changes unless explicitly requested.

Should I write tests before refactoring legacy code?▼

Yes, when tests do not cover risky behavior, add or update them before refactoring. Tests act as a safety net that confirms external behavior stayed the same after each change, which is essential for legacy code with unclear constraints.

When should I avoid refactoring code?▼

Avoid refactoring when the code does not clearly benefit from it, when the change would require modifying public interfaces without approval, or when it mixes with unrelated feature work. Clear code should not be replaced with clever code.

Can refactoring change a module's public API?▼

No, safe refactoring preserves public interfaces and external behavior by default. Changes to public APIs are only made when explicitly requested, and worthwhile improvements outside the requested scope are reported rather than applied.