refactor

Refactor code by extracting functions and renaming variables in small steps.

Updated Feb 4, 2026
One-click install
npx skills add https://github.com/ytqh/agent-skills --skill refactor-ytqh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/ytqh/agent-skills/tree/main/skills/refactor
Command: npx skills add https://github.com/ytqh/agent-skills --skill refactor-ytqh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactor code to improve maintainability without changing external behavior. This skill helps teams progressively improve code quality by extracting functions, renaming variables for clarity, breaking down large functions, strengthening type safety, eliminating code smells, and introducing proven design patterns. It is less drastic than a full rewrite and is intended for gradual improvements.

Core Features & Use Cases

  • Incremental extraction: Break large functions into focused units.
  • Renaming & typing improvements: Improve readability and type safety with minimal risk.
  • Gradual pattern introduction: Introduce design patterns and structure without altering behavior.
  • Use Case: When you have a monolithic function that's hard to test, refactor it step by step.

Quick Start

Start with a clearly delimited area of code identified for improvement. Write or run tests to lock in current behavior, then apply one focused refactor (e.g., extract a function, rename a variable) and run tests again. Repeat in small steps, committing frequently.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor large functions to improve code maintainability without changing behavior?

Refactoring large functions safely requires locking in current behavior with tests, applying focused extraction or renaming changes in small steps, and running tests after each modification. This incremental approach prevents behavior changes while improving maintainability.

What is the best way to eliminate code smells in a legacy codebase?

Eliminating code smells is best achieved through gradual, version-controlled improvements rather than a full rewrite. You incrementally extract methods, rename variables for clarity, and introduce proven design patterns while validating behavior with tests.

Can I introduce design patterns and improve type safety without breaking existing tests?

Yes, you can introduce design patterns and strengthen type safety without breaking tests by applying small-step changes. After each focused refactor, run your test suite to ensure external behavior remains unchanged and architecture gradually improves.

How do I start refactoring a monolithic function that is hard to test?

Start refactoring a monolithic function by delimiting the target area and writing tests to capture current behavior. Apply one focused refactor, such as extracting a method, run tests again, and repeat with frequent version-controlled commits.

When should I choose gradual refactoring over a full codebase rewrite?

Choose gradual refactoring over a full rewrite when targeting architectural debt, code smells, or large functions that still function correctly. It allows progressive maintainability improvements with minimal risk compared to drastic rewrites.