/refactor-code
Intelligently refactor and improve code quality
$ npx -y skills add qdhenry/Claude-Command-Suite --agent claude-codeHow it fires
How this command gets triggered: by you, by Claude, or both.
- Fires itselfClaude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/refactor-code
Context preview
What this command does when you run it.
Intelligently refactor and improve code quality
Command definition
refactor-code.mdIntelligently Refactor and Improve Code Quality
Intelligently refactor and improve code quality
Instructions
Follow this systematic approach to refactor code: **$ARGUMENTS**
1. **Pre-Refactoring Analysis**
- Identify the code that needs refactoring and the reasons why
- Understand the current functionality and behavior completely
- Review existing tests and documentation
- Identify all dependencies and usage points
2. **Test Coverage Verification**
- Ensure comprehensive test coverage exists for the code being refactored
- If tests are missing, write them BEFORE starting refactoring
- Run all tests to establish a baseline
- Document current behavior with additional tests if needed
3. **Refactoring Strategy**
- Define clear goals for the refactoring (performance, readability, maintainability)
- Choose appropriate refactoring techniques:
- Extract Method/Function
- Extract Class/Component
- Rename Variable/Method
- Move Method/Field
- Replace Conditional with Polymorphism
- Eliminate Dead Code
- Plan the refactoring in small, incremental steps
4. **Environment Setup**
- Create a new branch: `git checkout -b refactor/$ARGUMENTS`
- Ensure all tests pass before starting
- Set up any additional tooling needed (profilers, analyzers)
5. **Incremental Refactoring**
- Make small, focused changes one at a time
- Run tests after each change to ensure nothing breaks
- Commit working changes frequently with descriptive messages
- Use IDE refactoring tools when available for safety
6. **Code Quality Improvements**
- Improve naming conventions for clarity
- Eliminate code duplication (DRY principle)
- Simplify complex conditional logic
- Reduce method/function length and complexity
- Improve separation of concerns
7. **Performance Optimizations**
- Identify and eliminate performance bottlenecks
- Optimize algorithms and data structures
- Reduce unnecessary computations
- Improve memory usage patterns
8. **Design Pattern Application**
- Apply appropriate design patterns where beneficial
- Improve abstraction and encapsulation
- Enhance modularity and reusability
- Reduce coupling between components
9. **Error Handling Improvement**
- Standardize error handling approaches
- Improve error messages and logging
- Add proper exception handling
- Enhance resilience and fault tolerance
10. **Documentation Updates**
- Update code comments to reflect changes
- Revise API documentation if interfaces changed
- Update inline documentation and examples
- Ensure comments are accurate and helpful
11. **Testing Enhancements**
- Add tests for any new code paths created
- Improve existing test quality and coverage
- Remove or update obsolete tests
- Ensure tests are still meaningful and effective
12. **Static Analysis**
- Run linting tools to catch style and potential issues
- Use static analysis tools to identify problems
- Check for security vulnerabilities
- Verify code complexity metrics
13. **Performance Verification**
- Run performance benchmarks if applicable
- Compare before/after metrics
- Ensure refactoring didn't degrade performance
- Document any performance improvements
14. **Integration Testing**
- Run full test suite to ensure no regressions
- Test integration with dependent systems
- Verify all functionality works as expected
- Test edge cases and error scenarios
15. **Code Review Preparation**
- Review all changes for quality and consistency
- Ensure refactoring goals were achieved
- Prepare clear explanation of changes made
- Document benefits and rationale
16. **Documentation of Changes**
- Create a summary of refactoring changes
- Document any breaking changes or new patterns
- Update project documentation if needed
- Explain benefits and reasoning for future reference
17. **Deployment Considerations**
- Plan deployment strategy for refactored code
- Consider feature flags for gradual rollout
- Prepare rollback procedures
- Set up monitoring for the refactored components
Remember: Refactoring should preserve external behavior while improving internal structure. Always prioritize safety over speed, and maintain comprehensive test coverage throughout the process.
Read more
Intelligently Refactor and Improve Code Quality
Intelligently refactor and improve code quality
Instructions
Follow this systematic approach to refactor code: **$ARGUMENTS**
1. **Pre-Refactoring Analysis**
- Identify the code that needs refactoring and the reasons why
- Understand the current functionality and behavior completely
- Review existing tests and documentation
- Identify all dependencies and usage points
2. **Test Coverage Verification**
- Ensure comprehensive test coverage exists for the code being refactored
- If tests are missing, write them BEFORE starting refactoring
- Run all tests to establish a baseline
- Document current behavior with additional tests if needed
3. **Refactoring Strategy**
- Define clear goals for the refactoring (performance, readability, maintainability)
- Choose appropriate refactoring techniques:
- Extract Method/Function
- Extract Class/Component
- Rename Variable/Method
- Move Method/Field
- Replace Conditional with Polymorphism
- Eliminate Dead Code
- Plan the refactoring in small, incremental steps
4. **Environment Setup**
- Create a new branch: `git checkout -b refactor/$ARGUMENTS`
- Ensure all tests pass before starting
- Set up any additional tooling needed (profilers, analyzers)
5. **Incremental Refactoring**
- Make small, focused changes one at a time
- Run tests after each change to ensure nothing breaks
- Commit working changes frequently with descriptive messages
- Use IDE refactoring tools when available for safety
6. **Code Quality Improvements**
- Improve naming conventions for clarity
- Eliminate code duplication (DRY principle)
- Simplify complex conditional logic
- Reduce method/function length and complexity
- Improve separation of concerns
7. **Performance Optimizations**
- Identify and eliminate performance bottlenecks
- Optimize algorithms and data structures
- Reduce unnecessary computations
- Improve memory usage patterns
8. **Design Pattern Application**
- Apply appropriate design patterns where beneficial
- Improve abstraction and encapsulation
- Enhance modularity and reusability
- Reduce coupling between components
9. **Error Handling Improvement**
- Standardize error handling approaches
- Improve error messages and logging
- Add proper exception handling
- Enhance resilience and fault tolerance
10. **Documentation Updates**
- Update code comments to reflect changes
- Revise API documentation if interfaces changed
- Update inline documentation and examples
- Ensure comments are accurate and helpful
11. **Testing Enhancements**
- Add tests for any new code paths created
- Improve existing test quality and coverage
- Remove or update obsolete tests
- Ensure tests are still meaningful and effective
12. **Static Analysis**
- Run linting tools to catch style and potential issues
- Use static analysis tools to identify problems
- Check for security vulnerabilities
- Verify code complexity metrics
13. **Performance Verification**
- Run performance benchmarks if applicable
- Compare before/after metrics
- Ensure refactoring didn't degrade performance
- Document any performance improvements
14. **Integration Testing**
- Run full test suite to ensure no regressions
- Test integration with dependent systems
- Verify all functionality works as expected
- Test edge cases and error scenarios
15. **Code Review Preparation**
- Review all changes for quality and consistency
- Ensure refactoring goals were achieved
- Prepare clear explanation of changes made
- Document benefits and rationale
16. **Documentation of Changes**
- Create a summary of refactoring changes
- Document any breaking changes or new patterns
- Update project documentation if needed
- Explain benefits and reasoning for future reference
17. **Deployment Considerations**
- Plan deployment strategy for refactored code
- Consider feature flags for gradual rollout
- Prepare rollback procedures
- Set up monitoring for the refactored components
Remember: Refactoring should preserve external behavior while improving internal structure. Always prioritize safety over speed, and maintain comprehensive test coverage throughout the process.
A comprehensive development toolkit designed following Anthropic's Claude Code Best Practices for AI-assisted software development.
Repo: qdhenry/Claude-Command-Suite
Other commands on claude-command-suite.
- /boundary-bbcr-fallback
Execute automatic BBCR (Collapse-Rebirth Correction) when knowledge boundaries are exceeded or reasoning fails.
Open command - /boundary-detect
Analyze semantic position relative to knowledge boundaries to prevent hallucination and identify uncertainty zones.
Open command - /boundary-heatmap
Generate a visual heatmap of knowledge boundaries showing safe zones, risk areas, and semantic coverage.
Open command - /boundary-risk-assess
Evaluate the current risk level and provide detailed analysis of potential hallucination or reasoning failure.
Open command - /boundary-safe-bridge
Find and construct semantic bridges to safely navigate from current position to target concept without crossing dangerous boundaries.
Open command - /optimize-prompt
Takes an input prompt and returns ONLY a token-optimized version that preserves meaning while minimizing token count. Based on LLM tokenization principles: common words tokenize more efficiently, unusual words break into more tokens, and conciseness reduces cost.
Open command

