The find_refactoring tool analyzes your codebase to identify areas that would benefit from refactoring. It detects code duplication, complexity hotspots, organization issues, and interface problems, then provides prioritized recommendations with effort estimates.
Stellarion uses multiple analysis techniques: hash-based duplication detection (with intelligent comment filtering), ComplexityAnalyzer for real complexity metrics, file system analysis for organization issues, and AST parsing for interface analysis. Results are prioritized by impact and effort for actionable improvement planning.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
path | string | No | . | Directory to analyze |
focus | string | No | all | all, duplication, complexity, organization, or interfaces |
threshold | number | No | 10 | Complexity threshold for flagging |
includeTests | boolean | No | false | Include test files in analysis |
includePriority | boolean | No | false | Calculate and sort by priority |
includeEffort | boolean | No | false | Include effort estimates |
outputFormat | string | No | json | json, markdown, or both |
saveToDisk | boolean | No | false | Save markdown report to docs/ |
maxOpportunities | number | No | 100 | Maximum opportunities to return |
mcp__stellarion__find_refactoring focus:complexity path:src/ includePriority:true includeEffort:true
Natural Language:
Find all refactoring opportunities in this project
Direct MCP Call:
mcp__stellarion__find_refactoring focus:all includePriority:true includeEffort:true
Finds: Duplication, complexity, organization, and interface issues
Find repeated code patterns that should be abstracted.
Natural Language:
Where is there code duplication in this project?
Direct MCP Call:
mcp__stellarion__find_refactoring focus:duplication path:src/
Finds:
Find overly complex code that's hard to maintain.
Natural Language:
Find complex functions that need refactoring. Show priority and effort.
Direct MCP Call:
mcp__stellarion__find_refactoring focus:complexity threshold:15 includePriority:true includeEffort:true
Finds:
Find structural issues in the codebase.
Natural Language:
Are there any files that are too large or directories too crowded?
Direct MCP Call:
mcp__stellarion__find_refactoring focus:organization
Finds:
Find interface and signature problems.
Natural Language:
Find functions with too many parameters
Direct MCP Call:
mcp__stellarion__find_refactoring focus:interfaces
Finds:
Natural Language:
Find the most important complexity issues to fix, sorted by priority
Direct MCP Call:
mcp__stellarion__find_refactoring focus:complexity threshold:15 includePriority:true includeEffort:true outputFormat:markdown
Natural Language:
Generate a refactoring report and save it to the docs folder
Direct MCP Call:
mcp__stellarion__find_refactoring focus:all includePriority:true includeEffort:true outputFormat:markdown saveToDisk:true
Creates: docs/refactoring-report.md
Natural Language:
Find refactoring opportunities in production code only, excluding tests
Direct MCP Call:
mcp__stellarion__find_refactoring focus:all includeTests:false includePriority:true
Natural Language:
Find only the most complex functions (complexity > 25)
Direct MCP Call:
mcp__stellarion__find_refactoring focus:complexity threshold:25 includePriority:true
Natural Language:
Find duplication issues in the services directory
Direct MCP Call:
mcp__stellarion__find_refactoring focus:duplication path:src/services/
Each opportunity includes:
| Field | Description |
|---|---|
| Description | What the issue is |
| Location | File path and line numbers |
| Type | duplication, complexity, organization, or interfaces |
| Severity | critical, high, medium, low |
| Priority | Calculated priority score (when enabled) |
| Effort | Estimated fix time (when enabled) |
Priority is calculated from:
| Factor | Description |
|---|---|
| Severity | How bad is the issue? |
| Impact | How important is the affected code? |
| Frequency | How often is this code changed? |
Priority values:
| Level | Typical Time | Description |
|---|---|---|
| low | < 1 hour | Simple fixes, single-file changes |
| medium | 1-4 hours | Moderate refactoring, few files |
| medium-high | 4-8 hours | Significant changes, testing needed |
| high | 1-3 days | Major refactoring, multiple files |
| Field | Description |
|---|---|
| Code block | The duplicated code |
| Occurrences | Number of times it appears |
| Files | List of files containing the duplicate |
| Lines | Line numbers in each file |
| Field | Description |
|---|---|
| Function name | The complex function |
| Cyclomatic | Number of decision paths |
| Cognitive | Understanding difficulty |
| Suggested action | How to simplify |
| Field | Description |
|---|---|
| File/directory | The problematic location |
| Issue | Too large, too crowded, etc. |
| Metric | Current size/count |
| Threshold | Expected maximum |
| Field | Description |
|---|---|
| Function | The problematic function |
| Parameter count | Number of parameters |
| Suggestion | How to improve |
includeEffort: true for planning: Helps with sprint planningincludeTests: false