refactor-task

Refactor code in isolated git worktrees with regression test validation.

4|Updated Oct 24, 2020
One-click install
npx skills add https://github.com/Ynakatsuka/dotfiles --skill refactor-task
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-task
Source: https://github.com/Ynakatsuka/dotfiles/tree/main/dot_claude/skills/refactor-task
Command: npx skills add https://github.com/Ynakatsuka/dotfiles --skill refactor-task

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactoring tasks maintain external behavior by enforcing regression tests, ensuring code changes do not alter how the software behaves.

Core Features & Use Cases

  • Safe refactoring workflow: isolate changes, run baseline tests, and verify equivalence after edits.
  • Incremental changes: apply small, verifiable updates (extracts, renames, module reorganizations) with immediate test feedback.
  • Regression-driven guarantees: use dedicated worktrees to isolate development from main branches and compare results.

Quick Start

Create a new git worktree branch dedicated to the refactor, so changes are isolated from the main branch. Run the baseline test suite to establish the current behavior. Make small, incremental refactor changes and commit after each successful test. Run the full regression suite again to verify that behavior remains unchanged. If tests fail, revert the last change and investigate, then retry. When complete, delete the worktree and merge the changes back to main.

Frequently Asked Questions about refactor-task

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

FAQPage Schema
How do I refactor code safely without breaking existing behavior?

To refactor code safely, you should isolate changes in a dedicated git worktree, run baseline tests before editing, apply incremental updates, and validate post-refactor tests to enforce behavioral equivalence.

What is regression testing and how does it verify behavioral equivalence during refactoring?

Regression testing verifies behavioral equivalence by comparing baseline test results against post-refactor test results, ensuring that extracting functions or reorganizing modules does not alter the external software contracts.

How do I use a git worktree to isolate incremental refactoring changes?

Create a dedicated git worktree branch to isolate incremental refactoring changes from your main branch, allowing you to apply small updates, commit after each successful test, and revert easily if tests fail.

What is the step by step process for reorganizing modules while preserving external contracts?

The process involves creating a worktree, running baseline tests, making incremental module reorganization changes, running the full regression suite, reverting on failure, and merging completed changes back to main.

Why should I run baseline tests before extracting functions or splitting classes in a codebase?

Running baseline tests before extracting functions or splitting classes establishes the current external behavior, providing a definitive comparison point to verify that your incremental refactoring changes maintain behavioral equivalence.

What should I do when regression tests fail after an incremental codebase refactor?

When regression tests fail after an incremental codebase refactor, you should revert the last change, investigate the cause of the behavioral discrepancy, and retry the refactoring step to preserve external contracts.