Back to list
nguyenthienthanh

refactor-expert

by nguyenthienthanh

Aura Frog — AI-powered structured development plugin for Claude Code Turn Claude Code into a full-fledged dev platform: Aura Frog brings 24 specialized agents, a 9-phase TDD workflow, built-in quality gates and 70+ commands so your team doesn’t need to manually draft prompts — just call the right command and follow guided instructions.

3🍴 2📅 Jan 22, 2026

SKILL.md


name: refactor-expert description: "Guide safe, incremental refactoring that improves code quality without changing behavior." autoInvoke: false priority: medium triggers:

  • "refactor"
  • "code cleanup"
  • "improve code"
  • "refactor:analyze"
  • "refactor:plan"

Skill: Refactor Expert

Category: Dev Expert Version: 1.1.0 Used By: All development agents


Overview

Guide safe, incremental refactoring that improves code quality without changing behavior.


Documentation Commands

Generate analysis and implementation plans before refactoring:

CommandPurposeOutput
refactor:analyze <file>Code analysis document.claude/logs/refactors/{target}-analysis.md
refactor:plan <file>Implementation plan.claude/logs/refactors/{target}-plan.md
refactor:docs <file>Both documentsAnalysis + Plan + Summary

Templates: templates/refactor-analysis.md, templates/refactor-plan.md


1. Refactoring Decision

SignalAction
Code smell detectedIdentify specific smell
Tests passingSafe to refactor
No testsWrite tests FIRST
Large change neededBreak into small steps

Golden Rule: Never refactor and add features simultaneously.


2. Common Refactoring Patterns

Extract Method

// Before
function processOrder(order: Order) {
  // validate
  if (!order.items.length) throw new Error('Empty')
  if (!order.customer) throw new Error('No customer')
  // calculate
  let total = 0
  for (const item of order.items) {
    total += item.price * item.qty
  }
  return total
}

// After
function processOrder(order: Order) {
  validateOrder(order)
  return calculateTotal(order.items)
}

Replace Conditional with Polymorphism

// Before
function getPrice(type: string, base: number) {
  if (type === 'premium') return base * 0.8
  if (type === 'vip') return base * 0.7
  return base
}

// After
interface PricingStrategy { calculate(base: number): number }
class PremiumPricing implements PricingStrategy { calculate(base: number) { return base * 0.8 } }

Simplify Conditional

// Before
if (date.before(SUMMER_START) || date.after(SUMMER_END)) { charge = qty * winterRate }
else { charge = qty * summerRate }

// After
const isSummer = !date.before(SUMMER_START) && !date.after(SUMMER_END)
charge = qty * (isSummer ? summerRate : winterRate)

3. Code Smells → Refactoring

SmellRefactoring
Long MethodExtract Method
Large ClassExtract Class
Long Parameter ListIntroduce Parameter Object
Duplicate CodeExtract Method/Class
Feature EnvyMove Method
Data ClumpsExtract Class
Primitive ObsessionReplace with Object
Switch StatementsReplace with Polymorphism
Speculative GeneralityRemove unused abstraction
Dead CodeDelete it

4. Safe Refactoring Steps

1. Ensure tests pass ✅
2. Make ONE small change
3. Run tests ✅
4. Commit
5. Repeat

Never: Multiple changes between test runs.


5. Refactoring Checklist

Before:

  • Tests exist and pass
  • Understand current behavior
  • Identify specific smell

During:

  • One change at a time
  • Tests after each change
  • Commit frequently

After:

  • All tests pass
  • Code cleaner
  • Behavior unchanged

Best Practices

Do's

  • Test first, refactor second
  • Small, incremental changes
  • Commit after each successful refactor
  • Use IDE refactoring tools
  • Document why (not what)

Don'ts

  • Refactor without tests
  • Mix refactoring with features
  • Make large changes at once
  • Refactor code you don't understand
  • Over-refactor working code

  • refactor <file> - Full refactoring workflow
  • refactor:analyze <file> - Analysis document only
  • refactor:plan <file> - Implementation plan only
  • refactor:docs <file> - Both documents
  • refactor:quick <file> - Skip approvals
  • refactor:performance <file> - Performance-focused
  • refactor:structure <file> - Structure-focused

Version: 1.1.0 | Last Updated: 2025-12-04

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon