refactor

Refactor code while preserving behavior with test-aware verification.

Updated May 23, 2026
One-click install
npx skills add https://github.com/devturco/thiago-dev-template --skill refactor-devturco
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/devturco/thiago-dev-template/tree/main/.claude/skills/refactor
Command: npx skills add https://github.com/devturco/thiago-dev-template --skill refactor-devturco

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you improve code structure and readability while keeping the exact same external behavior, reducing the risk of breaking features during cleanup or restructuring.

Core Features & Use Cases

  • Behavior-Preserving Refactors: Executes refactoring steps (extract, move, rename, split, or consolidate) with an explicit requirement that behavior remains identical.
  • Test-First Safety Checks: Reads existing tests, verifies after each incremental change, and preserves test semantics unless the tests themselves are being refactored.
  • Regression Coverage When Missing: When no tests exist, it drives the creation of basic regression tests before proceeding.

Quick Start

Tell the skill what to refactor (for example, the target file, function, or code area) and ask it to refactor while preserving identical behavior and running the project checks to confirm.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor TypeScript code without changing behavior?

Refactor TypeScript code safely by applying incremental changes like extracting functions or splitting modules, then validating each step with typecheck, lint, and test runs to ensure identical behavior. This reduces the risk of breaking features during cleanup and restructuring.

What is the safest way to split large modules or consolidate logic?

The safest way to split large modules or consolidate logic is through incremental refactoring steps that preserve identical behavior, followed by test-aware verification after each change to prevent regressions. This ensures external behavior remains unchanged during the restructuring process.

Do I need existing tests to refactor safely?

You do not need existing tests to refactor safely. If no tests exist, the skill drives the creation of basic regression tests before proceeding, ensuring test-aware verification and validation after each incremental refactoring step.

How do I verify code cleanup steps like renaming files or moving functions?

Verify code cleanup steps by running typecheck, lint/check, and test runs after each incremental change like renaming files or moving functions. This test-aware validation ensures behavior preservation throughout the refactoring plan.

Can I refactor code incrementally to reduce regression risk?

Yes, you can refactor code incrementally to reduce regression risk by applying an explicit refactoring plan with behavior-preserving steps, verifying with typecheck, lint, and tests after each change. This approach keeps external behavior identical throughout the process.