refactor-analyzer
Skill0 starsChanged 49 days agoMITView on GitHub
Analyze code for refactoring opportunities with impact/effort scoring. Detects code smells, complexity hotspots, duplication, tight coupling. Trigger on 'refactor', 'code smells', 'technical debt', 'simplify', 'reduce complexity'.
- Installs packages
In this repository20 other files it gives its agents.
- examples/CLAUDE.mdCLAUDE.md
- Anti-Hallucination VerificationSkill
- backup-snapshotSkill
- Multi-Agent BrainstormSkill
- Browser UATSkill
- ci-cd-builderSkill
- Code Patterns ReferenceSkill
- Conventional Commits WorkflowSkill
- Context Curator AdministrationSkill
- email-composerSkill
- git-detectiveSkill
- imap-emailSkill
- ollama-model-managerSkill
- Ollama Code VerificationSkill
- project-bootstrapperSkill
- prompt-engineerSkill
- release-managerSkill
- scheduleSkill
- skill-creatorSkill
- Work LogSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
Look for: copy-pasted blocks (>10 lines)
- Distinctive: line 96
Test coverage: easier to test?
- Distinctive: line 120
Current State: Before code snippet
- Distinctive: line 126
Target State: After code snippet
- Distinctive: line 134
Use Ollama for initial code smell detection:
- Distinctive: line 148
No code leaves your server
- Distinctive: line 150
Use output to guide manual detailed analysis
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor Analyzer Skill
Overview
Systematically identify refactoring opportunities, prioritize by impact/effort ratio, and provide step-by-step refactoring plans with before/after examples.
Phase 1: SCAN
Analyze code for antipatterns and complexity indicators:
Cyclomatic Complexity
- Install:
pip install radon - Scan:
radon cc -s src/— score each function - Flag: functions with CC > 10 (very high)
- Target: reduce to CC < 5
Code Duplication
- Look for: copy-pasted blocks (>10 lines)
- Commands:
radon mi src/— maintainability index - Manual scan: identical if/else branches, repeated loops, similar class structures
Long Functions
- Flag: functions > 50 lines
- Action: extract helper functions
- Target: average function length < 30 lines
Deep Nesting
- Count: nesting depth in if/for/while
- Flag: depth > 3 levels
- Refactoring: early returns, guard clauses, helper functions
Large Files
- Flag: files > 300 lines
- Action: split into modules/classes
- Analysis: identify logical groupings
God Classes
- Characteristics:
- Multiple responsibilities (doing too much)
- High method count (>20 methods)
- Large state (>10 fields)
- Difficult to test individual parts
- Symptom: class name doesn't match main responsibility
Tight Coupling
- Red flags:
- Imports from many modules
- Passing entire objects when only 1-2 fields used
- Circular dependencies
- Mock many dependencies in tests
- Analysis: dependency graph visualization
Other Smells
- Long parameter lists (>5 params)
- Magic numbers/strings (use named constants)
- Feature envy (using many methods from another class)
- Divergent change (change for multiple reasons)
- Comments explaining "what" (should be obvious from code)
Phase 2: CLASSIFY
Map findings to refactoring patterns:
Extraction Patterns
- Extract Method: Long function to multiple small functions
- Extract Class: God class split into focused classes
- Extract Constant: Magic numbers to named constant
- Extract Variable: Complex expression to readable temp var
Simplification Patterns
- Simplify Conditional: Nested if to guard clause, ternary, switch
- Replace Parameter with Method: Passing derived value computed in function
- Remove Parameter: Function doesn't use parameter
- Introduce Parameter Object: Many params bundled into class
Redesign Patterns
- Replace Inheritance with Delegation: Tight coupling via inheritance to composition
- Introduce Strategy Pattern: Multiple algorithms with if/else to strategy objects
- Replace Enum with Polymorphism: Enum with switch to subclasses with override
- Extract Interface: High coupling depends on interface not class
Organization Patterns
- Move Method: Method in wrong class moved to class that uses it
- Move Field: Field accessed more by other class
- Inline Class: Useless class with 1-2 methods merged into other class
- Rename: Misleading name clarified with better name
Phase 3: PRIORITIZE
Score each opportunity by Impact and Effort:
Impact Score (1-10)
- Complexity reduction: how many functions simplified?
- Maintainability: easier to change/extend?
- Test coverage: easier to test?
- Coupling reduction: fewer dependencies?
- Reusability: code can be shared?
Effort Score (1-10)
- Lines to change: 1-50 = 2, 50-200 = 5, 200+ = 8
- Dependencies affected: changes in 1 file = 2, 3+ files = 6
- Risk: low = 0, medium = +3, high = +5
- Testing effort: simple = 1, integration tests = 3, complex = 5
Priority Calculation
Priority = Impact / Effort Risk adjustment: if Risk > 6, multiply by 0.5
Categorization
- Quick Wins: Priority > 3 (do first)
- Important: Priority 1-3 (significant value)
- Maintenance: Priority < 1 (nice to have)
Phase 4: PLAN
Top 5 opportunities with step-by-step plan:
For each refactoring:
- Name: Clear description
- Current State: Before code snippet
- Problem: What's bad about current state
- Refactoring Steps (numbered):
- Step 1: [action]
- Step 2: [action]
- Step 3: [run tests]
- Target State: After code snippet
- Benefits: Specific improvements
- Risk: Any gotchas or edge cases
- Test Plan: How to verify correctness
- Effort Estimate: hours/days
- Priority: Quick Win / Important / Maintenance
Local-First Analysis
Use Ollama for initial code smell detection:
ollama run qwen3-coder << 'PROMPT'
Analyze this Python/TypeScript code for refactoring opportunities.
Look for: long functions, duplication, complexity, god classes, tight coupling.
Format as JSON with: file, function_name, smell_type, severity (1-10), suggestion.
[CODE SNIPPET]
PROMPTBenefits:
- Fast local execution vs cloud API
- No code leaves your server
- Iterative refinement with follow-up prompts
- Use output to guide manual detailed analysis
Then perform detailed analysis with radon, manual code review, and structured refactoring plans.
Example Workflow
Scan
radon cc -s src/auth.py
# Output: auth.py:verify_token cc=12
radon mi src/
# Output: Maintainability Index = 65 (Medium)Analyze with Ollama
ollama run qwen3-coder << 'EOF'
I'm seeing high complexity in my verify_token function (CC=12).
Here's the code: [PASTE 50 LINES]
What refactoring would help most?
EOFCreate Plan
Extract nested conditions into helper functions:
- check_expiry(token)
- validate_signature(token)
- verify_permissions(token, required_perms)
Then refactor verify_token to call these helpers.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

