refactoring

Restructure code without changing behavior using test-guarded micro-commits.

Updated May 21, 2026
One-click install
npx skills add https://github.com/CagesThrottleUs/private-ai-harness --skill refactoring-cagesthrottleus
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring
Source: https://github.com/CagesThrottleUs/private-ai-harness/tree/main/skills/refactoring
Command: npx skills add https://github.com/CagesThrottleUs/private-ai-harness --skill refactoring-cagesthrottleus

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Code that works but has the wrong shape — god classes, duplication, deep nesting, long methods — is risky to change because restructuring can silently break behavior. This Skill enforces a disciplined refactoring workflow where every structural move is guarded by a passing test baseline and committed independently. ## Core Features & Use Cases - Smell identification: Names the exact structural problem (god class, long method, duplicate code, primitive obsession, shallow module, and more) before any change, keeping scope to one smell per session. - Test-guarded micro-commits: Establishes a passing test baseline first, then applies one structural move per commit — extract, inline, rename, move, collapse nesting — with tests re-run after every move. - Zero new behavior enforcement: Hard rule against mixing refactoring with features or bug fixes; any behavior change is routed to a separate lane and commit. - Use Case: You inherit a 400-line method with nested conditionals. The Skill verifies test coverage exists, runs the baseline suite, then guides you through extract-method and collapse-nesting moves, each independently revertable. ## Quick Start Ask the AI to refactor the god class in your payment module using the refactoring skill, keeping all existing tests green with one move per commit.

Frequently Asked Questions about refactoring

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

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

Establish a passing test baseline before touching anything, then make one structural move per commit — extract, inline, rename, or move — re-running the covering tests after each step. If tests fail after a move, revert that move immediately instead of debugging forward.

How to refactor a god class or long method safely?

Name the specific smell first, map the symbol's callers and blast radius, then apply extract class or extract method moves one at a time. Each move must be independently revertable and verified by the covering tests before the next move begins.

Can I refactor code that has no tests?

No — refactoring untested code is rewriting, not refactoring. The correct path is to write characterization tests first as a separate task, then begin the refactoring session once those tests pass.

Should I fix bugs while refactoring the same code?

Never mix refactoring with behavior changes in one commit. Commit the current structural work, open a separate lane for the bug fix, and return afterward — mixing both makes changes harder to review and revert.

When should I stop a refactoring session?

Stop when the single named smell you targeted is gone. Do not continue to a second smell in the same session — open a new lane instead, and run the full test suite plus lint gates before the final commit.