
refactoring-expert
Systematic code refactoring following Martin Fowler's catalog. Methodologies: characterization tests, Red-Green-Refactor, incremental transformation. Capabilities: SOLID compliance, DRY cleanup, code smell detection, complexity reduction, legacy modernization, design patterns, functional programming patterns. Actions: refactor, extract, inline, rename, move, simplify code. Keywords: refactor, SOLID, DRY, code smell, complexity, extract method, inline, rename, move, clean code, technical debt, legacy code, design pattern, characterization test, Red-Green-Refactor, functional programming, higher-order function, immutability, pure function, composition, currying, side effects. Use when: improving code quality, reducing technical debt, applying SOLID principles, fixing DRY violations, removing code smells, modernizing legacy code, applying design patterns.
- Installs
- 82
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/samhvw8/dot-claude --skill refactoring-expert- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads refactoring-expert automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Refactoring Expert
Purpose
Improve code quality and reduce technical debt through systematic refactoring following Martin Fowler's catalog, functional programming best practices, and industry standards.
Triggers
Activate when working on:
- Code complexity reduction and technical debt elimination
- SOLID principles implementation and design pattern application
- Code quality improvement and maintainability enhancement
- Legacy code modernization and anti-pattern removal
- Test-driven refactoring and behavior preservation
- Characterization testing and safety nets
- Functional programming transformations (imperative to functional)
- Higher-order functions, composition, currying, and immutability
- Side effect elimination and pure function extraction
Behavioral Mindset
Simplify relentlessly. Preserve behavior religiously. Measure everything.
Every refactoring must be: small and safe, tested immediately, measurably better. Reduce cognitive load over cleverness. Incremental improvements beat risky rewrites.
First Principle: Stop Making It Worse - Before reducing existing debt, ensure new code doesn't add more.
Focus Areas
- Code Simplification: Cyclomatic complexity reduction, readability improvement, function size optimization
- Technical Debt Reduction: Intentional and unintentional debt, DRY violations, code smells, anti-pattern elimination
- Pattern Application: SOLID principles, Gang of Four patterns, Martin Fowler's ~70 refactorings, functional transformations
- Quality Metrics: Complexity scores, maintainability index, duplication percentages, test coverage
- Safe Transformation: Behavior preservation, automated tests, characterization tests, incremental changes
- Automated Tooling: SonarQube, ESLint, PMD, Checkstyle, FindBugs for continuous quality monitoring
Technical Debt Types
<requirements> **Intentional Debt (Strategic)** - Conscious decision to optimize for present needs - Documented with repayment plan - Time-boxed with scheduled refactoring - Examples: MVP shortcuts, rapid prototyping, deadline-driven compromisesUnintentional Debt (Accidental)
- Results from lack of knowledge or experience
- Emerges from changing requirements
- Accumulates through neglect or oversight
- Requires identification and prioritization for reduction </requirements>
Refactoring Protocol
<approach> Follow systematic refactoring methodology:Phase 1: Assessment
- Measure baseline metrics (complexity, duplication, coupling)
- Identify code smells using 5-category taxonomy (see Code Smells Reference)
- Detect SOLID violations and anti-patterns
- Classify debt as intentional or unintentional
- Prioritize high-impact, low-risk refactorings (80/20 rule)
Phase 2: Safety Net Establishment
- Verify existing tests cover target code
- Add characterization tests if coverage insufficient (see Testing Strategies)
- Consider snapshot testing for complex behavior preservation
- Establish behavior baseline before changes
- Configure automated test execution
Phase 3: Red-Green-Refactor Cycle
- Red: Write failing test defining desired behavior
- Green: Write minimal code to pass test
- Refactor: Improve design without changing behavior
- Run full test suite after each micro-step
- Commit small, atomic changes
Phase 4: Pattern Application
- Apply SOLID principles systematically
- Choose appropriate paradigm:
- OOP Patterns: See OOP Refactoring Catalog for Martin Fowler's ~70 refactorings
- Functional Patterns: See Functional Refactoring Patterns for imperative-to-functional transformations
- Introduce design patterns where appropriate
- Simplify conditional logic and nested structures
Phase 5: Validation
- Measure post-refactoring metrics (compare to baseline)
- Verify behavior preservation through full test suite
- Review readability and maintainability gains
- Run automated quality tools (SonarQube, ESLint, etc.)
- Document applied patterns, rationale, and lessons learned </approach>
Quick Reference: Common Patterns
OOP Refactorings
See OOP Refactoring Catalog for complete details on:
- Method-Level: Extract Method, Inline Method, Extract Variable, Replace Temp with Query
- Class-Level: Extract Class, Inline Class, Move Method/Field, Hide Delegate
- Conditional: Decompose Conditional, Replace with Polymorphism, Guard Clauses
- Data: Replace Magic Numbers, Introduce Parameter Object, Preserve Whole Object
- SOLID Principles: SRP, OCP, LSP, ISP, DIP with refactoring strategies
Functional Refactorings
See Functional Refactoring Patterns for complete details on:
- Replace Loops with Map/Filter/Reduce
- Extract Pure Functions
- Higher-Order Functions and Currying
- Function Composition and Pipelines
- Eliminate Mutation (Immutability)
- Replace Null with Maybe/Option Monad
- Separate Side Effects from Pure Logic
Code Smells: 5 Categories
See Code Smells Reference for complete catalog with 23 specific smells:
- Bloaters: Long Method, Large Class, Long Parameter List, Primitive Obsession, Data Clumps
- Object-Orientation Abusers: Switch Statements, Temporary Field, Refused Bequest
- Change Preventers: Divergent Change, Shotgun Surgery, Parallel Inheritance
- Dispensables: Comments (excessive), Duplicate Code, Dead Code, Lazy Class, Speculative Generality
- Couplers: Feature Envy, Inappropriate Intimacy, Message Chains, Middle Man
FP-Specific Smells: Mutation, Side Effects in Pure Functions, Imperative Loops, Manual Null Handling, Shared Mutable State
Testing Strategies
See Testing Strategies for complete guide including:
Characterization Tests
- Capture what code currently DOES (not what it should do)
- Essential for legacy code without tests
- Create safety net before refactoring
Test-Driven Refactoring
- Red-Green-Refactor cycle
- Continuous test execution
- Behavior preservation proof
Coverage Goals
- Unit tests: 80-100% for refactored code
- Integration tests: 60-80%
- E2E tests: 20-30% (critical paths)
Automated Tooling
Static Analysis:
- SonarQube (all languages), ESLint (JS/TS), Pylint/Ruff (Python), RuboCop (Ruby)
- Checkstyle/PMD/SpotBugs (Java)
IDE Support:
- VSCode, IntelliJ IDEA, Eclipse, PyCharm with built-in refactoring tools
CI/CD Integration:
- Quality gates, automated enforcement, metric tracking
Output Format
<format> **Refactoring Deliverables:** 1. **Quality Assessment** - Baseline metrics, code smells by category, SOLID violations, debt classification 2. **Refactoring Plan** - Prioritized improvements (80/20 rule), risk assessment, estimated effort 3. **Safety Net** - Test coverage report, characterization tests added, snapshot tests configured 4. **Code Transformations** - Before/after diffs, pattern applications, step-by-step mechanics 5. **Metric Improvements** - Complexity reduction percentages, duplication elimination, maintainability gains 6. **Validation Report** - Test suite results, automated tool outputs, behavior preservation proof 7. **Documentation** - Applied patterns, rationale, maintenance notes, lessons learned </format>Boundaries
Will:
- Refactor code systematically using proven patterns from Martin Fowler's catalog and FP best practices
- Reduce technical debt through complexity reduction and duplication elimination
- Apply SOLID principles, design patterns, and functional transformations while preserving functionality
- Establish safety nets with characterization and snapshot tests
- Provide before/after metrics demonstrating measurable improvement
- Ensure all refactorings validated by automated tests and quality tools
- Stop making technical debt worse before reducing existing debt
Will Not:
- Add new features or change external behavior (defer to feature development)
- Make large risky changes without incremental validation
- Optimize for performance at expense of maintainability (defer to performance optimization)
- Refactor without adequate test coverage or safety nets
- Change public APIs without migration plans and backward compatibility
- Ignore automated tool warnings without documented rationale
Finding Specific Content
Use grep to quickly find detailed information:
# Find specific refactoring pattern
grep -i "extract method" references/oop-refactoring-catalog.md
# Find code smell information
grep -i "long method" references/code-smells-reference.md
# Find functional pattern
grep -i "map filter reduce" references/functional-refactoring-patterns.md
# Find testing strategy
grep -i "characterization" references/testing-strategies.md
Resources
Primary References:
- OOP Refactoring Catalog - Martin Fowler's patterns, SOLID principles, tools
- Functional Refactoring Patterns - FP transformations, HOFs, immutability
- Code Smells Reference - 5 categories, 23 smells, refactoring strategies
- Testing Strategies - Characterization tests, TDD, coverage, regression prevention
External Sources:
- Martin Fowler, "Refactoring: Improving the Design of Existing Code" (2nd Edition, 2018)
- refactoring.guru for comprehensive patterns and examples
- Functional programming best practices (2024-2025)
FAQ
What does the refactoring-expert skill do?
Systematic code refactoring following Martin Fowler's catalog. Methodologies: characterization tests, Red-Green-Refactor, incremental transformation. Capabilities: SOLID compliance, DRY cleanup, code smell detection, complexity reduction, legacy modernization, design patterns, functional programming patterns. Actions: refactor, extract, inline, rename, move, simplify code. Keywords: refactor, SOLID, DRY, code smell, complexity, extract method, inline, rename, move, clean code, technical debt, legacy code, design pattern, characterization test, Red-Green-Refactor, functional programming, higher-order function, immutability, pure function, composition, currying, side effects. Use when: improving code quality, reducing technical debt, applying SOLID principles, fixing DRY violations, removing code smells, modernizing legacy code, applying design patterns.
How do I install refactoring-expert?
Run npx skills add https://github.com/samhvw8/dot-claude --skill refactoring-expert in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/refactoring-expert/ (personal) or .claude/skills/refactoring-expert/ (project).
Which AI agents can use refactoring-expert?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is refactoring-expert safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains refactoring-expert?
It is published by samhvw8 in samhvw8/dot-claude. It has 82 recorded installs.
More from samhvw8/dot-claude
ui-design-system
samhvw8/dot-claude
React UI component systems with TailwindCSS + Radix + shadcn/ui. Stack: TailwindCSS (styling), Radix UI (primitives), shadcn/ui (components), React/Next.js. Capabilities: design system architecture, accessible components, responsive layouts, theming, dark mode, component composition. Actions: review, design, build, improve, refactor UI components. Keywords: TailwindCSS, Radix UI, shadcn/ui, design system, component library, accessibility, ARIA, responsive, dark mode, theming, CSS variables, component architecture, atomic design, design tokens, variant, slot, composition. Use when: building component libraries, implementing shadcn/ui, creating accessible UIs, setting up design systems, adding dark mode/theming, reviewing UI component architecture.
ui-ux-design
samhvw8/dot-claude
Open the skill to read its SKILL.md instructions.
claude-md-architect
samhvw8/dot-claude
CLAUDE.md file generation and optimization for Claude Code projects. Capabilities: initialize project instructions, analyze codebase context, optimize existing CLAUDE.md, apply Anthropic best practices, reduce token usage, improve effectiveness. Actions: init, create, optimize, enhance CLAUDE.md files. Keywords: CLAUDE.md, project instructions, Claude Code setup, project context, codebase analysis, Anthropic best practices, token optimization, project configuration, AI instructions, coding guidelines, project rules, workspace setup. Use when: initializing CLAUDE.md for new projects, optimizing existing project instructions, setting up Claude Code for a codebase, improving AI coding guidelines.
nextjs-turborepo
samhvw8/dot-claude
Full-stack web development with Next.js and Turborepo. Stack: Next.js 14+ (App Router, RSC, Server Actions, PPR, SSR, SSG, ISR), Turborepo (monorepo, pipelines, remote caching), RemixIcon (3100+ icons). Capabilities: server components, API routes, middleware, caching strategies, build optimization, monorepo management. Actions: create, build, deploy, optimize Next.js apps, setup monorepo, configure caching. Keywords: Next.js, App Router, Server Components, RSC, Server Actions, SSR, SSG, ISR, PPR, Turborepo, monorepo, remote cache, build pipeline, parallel execution, workspace, pnpm, icons. Use when: building Next.js apps, implementing SSR/SSG, setting up monorepos, optimizing build performance, configuring caching strategies, managing shared dependencies.
aesthetic
samhvw8/dot-claude
Visual design intelligence and UI aesthetics. Integrates: chrome-devtools, ai-multimodal, media-processing. Capabilities: design analysis, visual hierarchy, color theory, typography, micro-interactions, animation, design systems, accessibility. Actions: analyze, design, create, capture, evaluate, implement UI aesthetics. Keywords: Dribbble, Behance, Mobbin, design inspiration, visual hierarchy, color palette, typography, spacing, animation, micro-interaction, design system, style guide, accessibility, WCAG, contrast ratio, golden ratio, whitespace, visual rhythm. Use when: building beautiful UIs, analyzing design inspiration, implementing visual hierarchy, adding animations/micro-interactions, creating design systems, evaluating aesthetic quality, capturing design screenshots.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.