Turn messy, complex code into clean, maintainable solutions with intelligent refactoring suggestions. Get specific improvements with before/after examples and risk assessments - like having a senior architect review your code and show you exactly how to make it better.
Quick Start
Jump straight in with these copy-paste prompts that'll transform your code:
Please suggest refactoring improvements for C:/project/src/UserService.ts
How can I improve the performance of this React component? C:/components/Dashboard.tsx
This legacy PHP code needs modernising - what would you change? C:/legacy/OldUserClass.php
Can you help make this code more readable and maintainable? C:/utils/DataProcessor.js
Pro Tip
The more specific you are about your concerns (performance, readability, maintainability), the more targeted and actionable the suggestions will be.
What It Does
Think of this as having a master craftsperson look at your work and show you the elegant solution you couldn't quite see. suggest_refactoring
performs sophisticated code analysis to identify meaningful refactoring opportunities with project-specific patterns and expert-level risk assessment.
It's not about nitpicking every small detail - this function focuses on improvements that genuinely matter:
- Performance bottlenecks that slow down your application
- Readability issues that make maintenance a nightmare
- Maintainability problems that make future changes risky
- Architectural improvements that reduce coupling and complexity
- Modern patterns that leverage your framework's best features
Every suggestion comes with clear explanations, before/after examples, and a realistic assessment of implementation effort and risk. You'll know exactly what to change, why it matters, and how to do it safely.
Parameters
Here's what you can customise to get exactly the refactoring guidance you need:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
filePath |
string | Yes* | - |
Path to the file you want refactoring suggestions for Example:
"C:/project/src/components/UserProfile.tsx" |
code |
string | Yes* | - |
Code content directly (alternative to filePath) Perfect for pasting problematic functions you want improved
|
projectPath |
string | No | - |
Project root for architectural context analysis Helps understand project patterns and conventions
|
focusAreas |
array | No | ["readability", "maintainability"] |
What to focus on: "readability", "performance", "maintainability", "architecture" Example:
["performance", "maintainability"] |
analysisDepth |
string | No | "detailed" |
Analysis depth: "basic", "detailed", "comprehensive" Use "comprehensive" for complex refactoring projects
|
context |
object | No | {} |
Project context, framework preferences, and specific requirements Example:
{"framework": "React", "patterns": ["hooks", "functional"]} |
maxDepth |
number | No | 3 |
Maximum directory depth for multi-file analysis (1-5) Useful when providing projectPath
|
*Either filePath or code is required - choose whichever suits your workflow
Real-World Examples
Here's how to use it in different scenarios:
React Component Optimisation
houtini-lm:suggest_refactoring with:
- filePath: "C:/project/src/components/Dashboard.tsx"
- focusAreas: ["performance", "maintainability"]
- context: {
"framework": "React",
"patterns": ["hooks", "functional", "typescript"],
"performance": "high_traffic"
}
Legacy PHP Modernisation
houtini-lm:suggest_refactoring with:
- filePath: "C:/legacy/UserManager.php"
- projectPath: "C:/legacy"
- focusAreas: ["readability", "maintainability", "architecture"]
- analysisDepth: "comprehensive"
- context: {
"modernise": true,
"target_php": "8.1",
"patterns": ["PSR-4", "dependency_injection"]
}
Node.js API Refactoring
houtini-lm:suggest_refactoring with:
- filePath: "C:/api/routes/users.js"
- focusAreas: ["performance", "architecture"]
- context: {
"framework": "Express.js",
"database": "PostgreSQL",
"patterns": ["async_await", "error_handling"]
}
Quick Function Improvement
houtini-lm:suggest_refactoring with:
- code: "function processUsers(users) {
let result = [];
for(let i = 0; i < users.length; i++) {
if(users[i].active == true) {
result.push({...users[i], processed: true});
}
}
return result;
}"
- focusAreas: ["readability", "performance"]
- context: {"language": "JavaScript", "modern": true}
What You Get Back
The refactoring suggestions are practical, actionable, and designed to help you improve your code immediately:
๐ง Specific Improvement Recommendations
- Before/after code examples showing exactly what to change
- Clear explanations of why each change improves the code
- Implementation steps with the safest order of changes
- Alternative approaches when multiple solutions are viable
โ๏ธ Risk Assessment for Each Suggestion
- Low risk - Safe changes that won't break functionality
- Medium risk - Changes requiring careful testing
- High risk - Significant architectural changes with detailed migration guidance
- Impact analysis - What parts of the system might be affected
โก Performance Impact Analysis
- Quantified improvements - estimated speed gains, memory savings
- Bottleneck identification - the changes with biggest impact
- Scalability considerations - how changes affect performance at scale
- Framework-specific optimisations - leveraging your tech stack's strengths
๐๏ธ Architectural Pattern Improvements
- Design pattern opportunities - when and how to apply them
- Dependency reduction strategies - loosening tight coupling
- Separation of concerns - clearer responsibility boundaries
- Code organisation suggestions - better file and function structure
๐งช Testing Enhancement Recommendations
- Testability improvements - making code easier to test
- Coverage enhancement - areas that need better test coverage
- Mock-friendly refactoring - reducing dependencies for unit tests
- Test strategy guidance - what types of tests to add after changes
Focused on What Matters
Every suggestion is prioritised by impact. You'll get the changes that make the biggest difference to your code's quality, performance, and maintainability first.
Focus Areas Explained
Choose the right focus areas to get targeted suggestions for your specific needs:
๐ Readability Focus
Perfect for code that works but is hard to understand or maintain:
- Variable and function naming improvements
- Code structure and organisation enhancements
- Comment and documentation suggestions
- Complexity reduction strategies
- Consistent formatting and style recommendations
โก Performance Focus
When you need speed improvements and efficiency gains:
- Algorithm optimisation opportunities
- Memory usage improvements
- Database query optimisation
- Caching strategy recommendations
- Bundle size reduction for web applications
- Framework-specific performance patterns
๐ง Maintainability Focus
For code that needs to be sustainable long-term:
- Separation of concerns improvements
- Dependency injection opportunities
- Error handling enhancements
- Configuration and environment management
- Testing and debugging improvements
๐๏ธ Architecture Focus
When you need structural improvements and design pattern implementation:
- Design pattern opportunities
- Component and module organisation
- Interface and abstraction improvements
- Dependency management strategies
- Scalability and extensibility enhancements
Perfect Use Cases
Here's when this function becomes your secret weapon for better code:
๐ฅ Legacy Code Modernisation
Inherited some old code that needs updating? Get a clear roadmap for bringing it up to modern standards whilst maintaining functionality. Perfect for gradual migration strategies.
๐ Performance Optimisation
When your application is running slow, paste the bottleneck code and get specific suggestions for improvements. Great for both micro-optimisations and architectural changes.
๐ฅ Code Review Preparation
Before submitting code for peer review, run it through refactoring suggestions to identify potential improvements. Show up with cleaner, more thoughtful code.
๐ Learning Better Patterns
Paste your working code and learn how experienced developers would approach the same problem. It's like having a mentor show you better techniques.
๐ง Technical Debt Reduction
Tackle that growing technical debt systematically. Get prioritised suggestions for which improvements will have the biggest impact on long-term maintainability.
๐ Framework Migration
Moving from class components to hooks? From jQuery to vanilla JS? Get guidance on modern patterns and migration strategies that preserve functionality whilst improving code quality.
Test After Refactoring
Always test your changes thoroughly, especially for medium and high-risk suggestions. The analysis provides great guidance, but your specific use case and requirements are unique.
Best Practices
Get the most out of your refactoring suggestions with these proven approaches:
๐ฏ Be Specific About Your Goals
The more specific you are about what you want to achieve, the better the suggestions:
- Mention performance requirements: "high traffic", "large datasets"
- Include framework preferences: "prefer hooks over classes"
- Note constraints: "must maintain backward compatibility"
- Specify skill level: "junior developer friendly" or "advanced patterns welcome"
๐ Focus Your Analysis
Choose the right focus areas for your situation:
- Start with "readability" for inherited or complex code
- Use "performance" when investigating slow operations
- Choose "maintainability" for long-term projects
- Select "architecture" when planning major changes
๐ฌ Implement Changes Gradually
Follow the suggested implementation order:
- Low-risk changes first - build confidence and see immediate improvements
- Test thoroughly after each change before moving to the next
- Medium-risk changes with comprehensive testing
- High-risk architectural changes with feature flags or branches
๐ Provide Project Context
Include your project path when possible for better suggestions:
- Helps understand your existing patterns and conventions
- Provides context about architectural decisions
- Identifies opportunities for consistency improvements
- Suggests patterns that fit your existing codebase
๐ Use for Learning
Make refactoring suggestions part of your professional development:
- Paste well-written code to understand why it's good
- Compare your solutions with suggested improvements
- Build a collection of patterns that work well in your projects
- Share interesting suggestions with your team for discussion
Learn as You Go
Each refactoring suggestion is a mini-lesson in better coding practices. Pay attention to the explanations - they're often as valuable as the code changes themselves.
Troubleshooting
Hit a snag? Here are solutions to common issues:
Suggestions seem generic or not specific to my framework
The refactoring suggestions don't seem tailored to React, Laravel, or your specific technology.
- Include detailed framework context:
{"framework": "React", "version": "18", "patterns": ["hooks"]}
- Mention specific technologies:
{"database": "PostgreSQL", "orm": "Sequelize"}
- Use "comprehensive" analysis depth for framework-specific insights
- Provide project path to help understand architectural patterns
Too many suggestions - feeling overwhelmed
The analysis returned too many suggestions and you're not sure where to start.
- Focus on specific areas: use
focusAreas: ["performance"]
instead of all areas - Start with "basic" analysis depth for high-level suggestions
- Look for "Low risk" suggestions first - they're safe to implement immediately
- Implement one category at a time (readability first, then performance, etc.)
Suggestions don't consider my constraints
The recommendations don't account for your specific requirements or limitations.
- Include constraints in context:
{"constraints": ["backward_compatibility", "no_dependencies"]}
- Mention team considerations:
{"team": "junior_developers", "learning_curve": "minimal"}
- Specify performance requirements:
{"performance": "high_traffic", "memory": "limited"}
- Note deployment considerations:
{"deployment": "legacy_servers", "php_version": "7.4"}
No architectural insights for larger improvements
Missing big-picture suggestions about overall code organisation and structure.
- Include "architecture" in your focus areas:
focusAreas: ["architecture", "maintainability"]
- Provide project path for full context:
projectPath: "C:/my-project"
- Use "comprehensive" analysis depth for architectural insights
- Mention current architecture:
{"current_pattern": "MVC", "considering": "microservices"}
Analysis takes too long for large files
The function times out or takes much longer than expected with large files.
- Try "basic" analysis depth first for large files
- Break large files into smaller functions and analyse separately
- Use the
code
parameter with specific functions rather than entire files - Ensure your LM Studio model has sufficient memory and isn't swapping