Skip to content

Disciplined refactoring plugin for Claude Code with analysis-first workflow

Notifications You must be signed in to change notification settings

finereli/refactoring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Refactoring Plugin for Claude Code

A disciplined refactoring plugin based on principles from "Refactoring" (Fowler) and "Working Effectively with Legacy Code" (Feathers).

Features

  • Analysis-First Approach: Identifies code smells and prioritizes high-impact refactorings
  • 80/20 Principle: Focus on the least refactorings that give the most impact
  • Safe Transformations: Step-by-step refactoring with verification at each step
  • Incremental Changes: One transformation at a time, with git commits
  • Multi-Language Examples: Python, TypeScript, Go, Dart, and more

Installation

From Local Directory

If you're in this directory:

claude plugins install .

Or specify the scope:

claude plugins install . --scope user    # Available in all your projects
claude plugins install . --scope project # Only in current project

From Git Repository

Install from GitHub:

claude plugins install https://github.com/elifiner/refactoring

Or with SSH:

claude plugins install git@github.com:elifiner/refactoring.git

Usage

Invoke the refactoring skill with:

/refactor [file or code to analyze]

Workflow

The skill follows a two-phase approach:

Phase 1: Analysis

  1. Analyzes code for common code smells
  2. Prioritizes issues by impact (HIGH/MEDIUM/LOW)
  3. Applies 80/20 thinking - finds the least refactorings for most impact
  4. Presents findings and gets your approval

Phase 2: Refactoring

  1. Identifies ONE safe transformation
  2. Applies the change
  3. Verifies (tests, compiler, or manual inspection)
  4. Commits the change
  5. Suggests next step

Example

> /refactor src/services/orderProcessor.js

Code Smell Analysis:

🔴 HIGH IMPACT (start here):
- Line 45: processOrder() is 150 lines, does 5 different things
- Lines 67-89: Validation logic duplicated in 3 places

🟡 MEDIUM IMPACT:
- Line 120: Deep nesting (4 levels) in calculateTotal()

Recommendation: Start with extracting validation logic.
This unlocks easier testing and future changes.

Proceed with extracting validation? (y/n)

Philosophy

This plugin follows a strict discipline:

  • Analysis before refactoring - Don't refactor everything, prioritize impact
  • 80/20 principle - Focus on high-leverage changes
  • One transformation at a time - Never mix multiple changes
  • Always verify - Run tests or verify mechanically after each step
  • Small steps - If you can't verify it, make it smaller
  • Observe and adapt - Don't plan all steps upfront
  • Know when to stop - Perfect code is not the goal

Common Code Smells Detected

  • Long functions (> 50 lines)
  • Duplicated code blocks
  • Deep nesting (> 3 levels)
  • Unclear names
  • Complex conditionals
  • God classes/modules (> 500 lines)
  • Long parameter lists (> 4 parameters)

Safe Transformations

  • Extract Method/Function
  • Inline Method/Function
  • Rename (Variable, Function, Class, File)
  • Move Method/Function
  • Extract Variable
  • Inline Variable
  • Split Loop
  • Replace Nested Conditional with Guard Clauses

See the detailed guide for complete explanations and examples in multiple languages.

Plugin Structure

refactoring/
├── .claude-plugin/
│   └── plugin.json          # Plugin metadata
├── skills/
│   └── refactor/
│       ├── SKILL.md         # Main skill workflow
│       └── guide.md         # Detailed refactoring guide
└── README.md                # This file

When NOT to Refactor

The skill will help you identify when NOT to refactor:

  • Code that rarely changes
  • Low-impact cosmetic improvements
  • Areas with unclear requirements
  • When you have higher priorities

Contributing

To modify this plugin:

  1. Edit files in skills/refactor/
  2. Update version in .claude-plugin/plugin.json
  3. Test locally: claude --plugin-dir .
  4. Reinstall: claude plugins install .

License

MIT

References

  • "Refactoring: Improving the Design of Existing Code" by Martin Fowler
  • "Working Effectively with Legacy Code" by Michael Feathers

About

Disciplined refactoring plugin for Claude Code with analysis-first workflow

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •