code-refactor

Split modules, extract functions, and remove dead code while preserving behavior.

16|1|Updated Jan 2, 2026
One-click install
npx skills add https://github.com/bahayonghang/my-ai-cli-toolkit --skill code-refactor-bahayonghang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-refactor
Source: https://github.com/bahayonghang/my-ai-cli-toolkit/tree/main/skills/development-workflows/code-refactor
Command: npx skills add https://github.com/bahayonghang/my-ai-cli-toolkit --skill code-refactor-bahayonghang

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the complexity of maintaining large codebases by providing a structured, safe, and verifiable approach to refactoring without altering existing functionality.

Core Features & Use Cases

  • Safe Refactoring: Implements behavior-preserving transformations like module splitting, function extraction, and dead-code removal.
  • Verification-First Workflow: Ensures every change is backed by baseline checks and verification steps to prevent regressions.
  • Use Case: Use this skill when you need to split a bloated 1000-line service file into smaller, modular components or when you need to clean up duplicated logic across your project while ensuring the public API remains stable.

Quick Start

Use the code-refactor skill to identify and extract duplicated logic into a private helper function within the specified file.

Frequently Asked Questions about code-refactor

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

FAQPage Schema
How do I safely refactor a large codebase without altering existing functionality?

Safe code refactoring uses behavior-preserving transformations like module splitting, function extraction, and dead-code removal. It applies systematic structural verification and baseline testing to improve code quality and modularity in complex projects without changing the external API.

What is the best way to split a bloated service file into smaller modular components?

The best way to split bloated service files is through systematic module splitting and function extraction. This behavior-preserving refactoring approach breaks down large files into modular components while ensuring the public API remains stable and backed by baseline checks.

How does behavior-preserving refactoring prevent regressions during dead-code removal?

Behavior-preserving refactoring prevents regressions by enforcing a verification-first workflow. It ensures every dead-code removal or structural change is backed by baseline checks and verification steps, verifying that the original functionality remains intact before and after the transformation.

Can I extract duplicated logic into a private helper function without breaking the public API?

Yes, you can extract duplicated logic into private helper functions while maintaining a stable public API. This refactoring technique isolates shared behavior internally, ensuring the external interface remains unchanged and fully verified through baseline testing.

When do I need structural verification for code maintenance tasks?

Structural verification is needed during code maintenance when improving modularity, readability, or cleaning up complex projects. It ensures that transformations like module splitting and dead-code removal preserve the original behavior and prevent functional regressions.

Does code refactoring work for cleaning up duplicated logic across a complex project?

Yes, code refactoring works for cleaning up duplicated logic across complex projects by extracting shared behavior into private helpers. It applies structural verification to ensure the cleanup improves code quality without altering the project's existing functionality.