code-refactor

Refactor existing code to improve structure without changing external behavior.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

在不改变外部行为的前提下,提升代码结构、可读性和可维护性,消除代码异味并降低维护成本。

Core Features & Use Cases

  • 提取函数、拆分大型函数或类以降低复杂度
  • 重构模块边界以提升可维护性、测试性和可扩展性
  • 消除重复代码、改善命名和接口设计以减少后续修改成本
  • 适用于渐进式改造现有代码,而非一次性重写

典型用例示例:将一个长函数拆分为多个职责明确的小函数,并确保外部接口保持一致。

Quick Start

请指定需要改造的目标代码段,AI 将在不改变外部行为的前提下执行渐进式重构。

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 safely without changing its external behavior?

To refactor code safely without changing behavior, apply small incremental changes to functions and modules while ensuring test coverage before and after the process. This eliminates code smells while keeping interfaces consistent.

What is the best way to split a large function into smaller modules?

The best way to split a large function is through gradual refactoring, extracting distinct responsibilities into smaller, well-named functions. This module extraction reduces complexity and improves maintainability without altering external behavior.

How do I eliminate code smells in an existing codebase?

You eliminate code smells in an existing codebase by applying gradual refactoring principles, removing duplicate code, and improving naming and interface design incrementally to lower maintenance costs without a full rewrite.

Do I need test coverage before refactoring a module?

Yes, test coverage is required before refactoring a module to ensure behavior remains unchanged. Emphasizing tests before and after the process validates that the structural improvements do not introduce regressions.

Can I use gradual refactoring instead of rewriting a legacy codebase?

Yes, gradual refactoring is designed for existing codebases requiring incremental improvements rather than one-time rewrites. It safely extracts modules and improves architecture over time while preserving the original behavior.

When should I avoid refactoring code?

You should avoid refactoring code when there is insufficient test coverage to verify behavior, as the process emphasizes keeping external behavior unchanged and relies on tests before and after making incremental structural changes.