refactor

Coordinates safe refactoring of duplicated Java/C++ code in TDD cycles.

Updated Nov 17, 2025
One-click install
npx skills add https://github.com/craigtkhill/atui-tools --skill refactor-craigtkhill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/craigtkhill/atui-tools/tree/main/skills/refactor
Command: npx skills add https://github.com/craigtkhill/atui-tools --skill refactor-craigtkhill

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides developers through the REFACTOR phase of the RED-GREEN-REFACTOR cycle in Test-Driven Development. It emphasizes a search-first mindset to identify duplication, improve patterns, and apply safe refactoring strategies.

Core Features & Use Cases

  • Search-first approach: Prior to writing new code, search for existing patterns and duplications to avoid unnecessary changes.
  • Duplication analysis: Ask critical questions to determine whether duplication can be unified or should be kept to avoid coupling.
  • Refactoring strategies: Choose from extraction, parameterization, interface extraction, or introducing abstractions to reduce duplication.
  • Safe refactoring workflow: Follow safety rules (green tests, small commits, run tests after each change, revert if needed).

Quick Start

Refactor the codebase with duplicated logic by following this workflow: identify duplicates, plan a single abstraction, implement changes incrementally, and verify all tests pass after each step.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I eliminate code duplication safely during refactoring?

Eliminate duplication by following the refactor phase of Test-Driven Development: search for existing patterns first, analyze whether duplication should be unified, choose a refactoring strategy (extract function, parameterize, extract interface, or introduce abstraction), then implement incrementally with all tests passing after each change.

What's the best way to reduce code duplication without breaking existing tests?

Use a search-first approach to identify duplications, plan a single abstraction, implement changes in small incremental steps, and run all tests after each change. Keep all tests green before refactoring, revert if needed, and keep refactoring separate from feature work.

When should I refactor duplicated code versus keeping it separate?

Ask critical questions during duplication analysis: can the duplication be safely unified into a single abstraction, or would combining it create unwanted coupling? Refactor only when unification improves patterns without changing behavior, and always verify tests pass before and after changes.

How do I choose between extract function, parameterization, and interface extraction for refactoring?

Refactoring strategies depend on duplication scope and coupling risk. Extract function for isolated duplicated logic, parameterize for similar functions with varying inputs, extract interface for shared behavior across types, and introduce abstraction for complex pattern drift.

Can I refactor code while adding new features in TDD?

No. Keep refactoring separate from feature work to maintain a safe, predictable workflow. Complete feature cycles in the red-green-refactor pattern, then perform refactoring in dedicated phases with all tests green, ensuring changes don't alter behavior.

Why is a search-first mindset important before writing refactoring code?

Searching for existing patterns and duplications first prevents unnecessary changes and redundant abstractions. This approach identifies what already exists in the codebase, reduces over-engineering, and ensures refactoring decisions are informed by the actual code structure.