Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Perform safe refactoring operations while preserving behavior and maintaining code integrity. Use when: renaming identifiers, extracting functions/modules, inlining code, moving files, or restructuring code without changing functionality. Do NOT use when: adding new features, fixing bugs (use standard editing), or making breaking API changes.
.claude/skills/marco-souza-refactor/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-07 | ✗→✓ | ▲ Improved | 56% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 55% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 55% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 67% | 0% |
| case-21 | ✗→✓ | ▲ Improved | 64% | 0% |
Execute safe refactoring operations with verification at each step. Refactoring changes code structure without altering external behavior.
Preserve behavior. Every refactoring must pass tests before and after. If behavior changes, it's not refactoring—it's a rewrite.
Rename variables, functions, classes, files, or directories while maintaining all references.
When to use:
Steps:
bash# Find all usages before renaming grep -r "oldName" --include="*.ts" --include="*.js" --include="*.py"
Pull out a code block into a new function, method, class, or module.
When to use:
Steps:
Extraction targets:
Replace a function call with the function body.
When to use:
Steps:
Relocate code to a more appropriate location in the codebase.
When to use:
Steps:
Before any refactoring, verify:
bash# 1. Ensure clean git state git status git stash # or commit work-in-progress # 2. Run existing tests to establish baseline # Pick the appropriate test command for your project npm test 2>/dev/null || go test ./... 2>/dev/null || pytest 2>/dev/null || cargo test 2>/dev/null # 3. Create a checkpoint git checkout -b refactor/<description>
Pre-refactoring checklist:
bash # Ensure tests exist # If no tests, consider adding characterization tests first
# Create refactoring branch git checkout -b refactor/<description>
bash # Run tests npm test 2>/dev/null || go test ./...
# Verify build succeeds npm run build 2>/dev/null || go build ./...
bash git add -A git commit -m "ref: <what changed>"
bash # Comprehensive verification npm test 2>/dev/null && npm run lint 2>/dev/null
bash # Remove any dead code # Update documentation if needed # Merge or create PR
typescript// Before function processOrder(order: Order) { // 50 lines of validation // 30 lines of calculation // 20 lines of persistence } // After function processOrder(order: Order) { const validated = validateOrder(order); const calculated = calculateTotals(validated); return persistOrder(calculated); }
bash# Before: utils.js has 500 lines # After: Split into organized modules mkdir -p src/utils/validation mkdir -p src/utils/formatting # Move validation functions mv src/utils/validateUser.js src/utils/validation/ mv src/utils/validateOrder.js src/utils/validation/ # Update imports find . -name "*.ts" -exec sed -i 's|from.*utils/validateUser|from../utils/validation/validateUser|g' {} \;
bash# For large codebases, use language server # TypeScript npx tsserver --rename <file> <oldName> <newName> # Or use find + sed for simpler cases grep -rl "oldFunctionName" src/ | xargs sed -i 's/oldFunctionName/newFunctionName/g'
When moving code creates circular imports:
If refactoring must change public API:
For codebase-wide changes:
bash# 1. Check what changed git diff HEAD~1 # 2. Verify test expectations # Look for tests that assert implementation details # 3. Consider if test needs updating (rare) # Only if refactoring exposed test as brittle
bash# TypeScript: Check for missing imports npx tsc --noEmit # Go: Check for unused imports goimports -l . # General: Search for references to old names grep -r "oldName" --include="*.ts" --include="*.js" --include="*.go"
bash# Profile before and after # Compare key metrics # Ensure refactoring didn't introduce N+1 queries or unnecessary copies
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 13,642 | 8,877 | -35% | 1 | 1 | 0% | 2,737 | 3,960 | +45% | 0 | 0 | — |
case-02 | fail→fail | 12,746 | 10,053 | -21% | 1 | 1 | 0% | 2,462 | 3,823 | +55% | 0 | 0 | — |
case-03 | pass→pass | 11,061 | 8,450 | -24% | 1 | 1 | 0% | 2,384 | 3,773 | +58% | 0 | 0 | — |
case-04 | pass→pass | 9,652 | 7,982 | -17% | 1 | 1 | 0% | 2,086 | 3,372 | +62% | 0 | 0 | — |
case-05 | pass→pass | 12,764 | 11,935 | -6% | 1 | 1 | 0% | 2,277 | 4,090 | +80% | 0 | 0 | — |
case-06 | pass→pass | 11,534 | 7,258 | -37% | 1 | 1 | 0% | 2,161 | 3,243 | +50% | 0 | 0 | — |
case-07 | fail→pass | 12,253 | 11,364 | -7% | 1 | 1 | 0% | 2,756 | 4,286 | +56% | 0 | 0 | — |
case-08 | fail→pass | 11,886 | 9,280 | -22% | 1 | 1 | 0% | 2,381 | 3,698 | +55% | 0 | 0 | — |
case-09 | pass→pass | 10,463 | 4,610 | -56% | 1 | 1 | 0% | 1,939 | 2,781 | +43% | 0 | 0 | — |
case-10 | pass→pass | 12,519 | 11,410 | -9% | 1 | 1 | 0% | 2,438 | 3,966 | +63% | 0 | 0 | — |
case-11 | fail→fail | 10,769 | 7,821 | -27% | 1 | 1 | 0% | 2,026 | 3,248 | +60% | 0 | 0 | — |
case-12 | fail→fail | 7,141 | 3,763 | -47% | 1 | 1 | 0% | 1,298 | 2,526 | +95% | 0 | 0 | — |
case-13 | pass→pass | 11,259 | 9,435 | -16% | 1 | 1 | 0% | 2,153 | 3,623 | +68% | 0 | 0 | — |
case-14 | fail→pass | 12,081 | 11,617 | -4% | 1 | 1 | 0% | 2,445 | 3,778 | +55% | 0 | 0 | — |
case-15 | fail→fail | 11,829 | 10,317 | -13% | 1 | 1 | 0% | 1,755 | 3,815 | +117% | 0 | 0 | — |
case-16 | fail→fail | 10,746 | 8,207 | -24% | 1 | 1 | 0% | 2,209 | 3,566 | +61% | 0 | 0 | — |
case-17 | fail→pass | 9,199 | 5,411 | -41% | 1 | 1 | 0% | 1,781 | 2,967 | +67% | 0 | 0 | — |
case-18 | fail→fail | 13,820 | 10,215 | -26% | 1 | 1 | 0% | 2,533 | 3,962 | +56% | 0 | 0 | — |
case-19 | pass→pass | 11,608 | 7,483 | -36% | 1 | 1 | 0% | 2,100 | 3,288 | +57% | 0 | 0 | — |
case-20 | pass→fail | 8,121 | 4,790 | -41% | 1 | 1 | 0% | 1,463 | 2,754 | +88% | 0 | 0 | — |
case-21 | fail→pass | 10,816 | 8,307 | -23% | 1 | 1 | 0% | 2,161 | 3,553 | +64% | 0 | 0 | — |
case-22 | fail→fail | 7,723 | 4,304 | -44% | 1 | 1 | 0% | 1,461 | 2,582 | +77% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +18 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.