⌘ /optimize
Optimize code for performance, readability, or efficiency
Command Usage
Invoke this command in Claude Code:
/optimizedescription: Optimize code for performance, readability, or efficiency disable-model-invocation: false
Optimize the specified code for better performance, maintainability, or resource efficiency.
Process
Use the performance-optimization skill from bushido to:
- Identify optimization target: Performance, memory, readability, or bundle size
- Measure current state: Establish baseline metrics
- Analyze bottlenecks: Profile and identify actual issues
- Apply optimizations: Make targeted improvements
- Measure impact: Verify improvements with evidence
- Ensure correctness: Run tests to confirm behavior unchanged
Optimization Types
Performance:
- Algorithm complexity reduction
- Database query optimization
- Caching strategies
- Lazy loading and code splitting
Code Quality:
- Simplification and clarity
- Removing duplication
- Better naming and structure
- Pattern improvements
Resource Efficiency:
- Memory usage reduction
- Bundle size optimization
- Network request reduction
- Asset optimization
Examples
When the user says:
- "This function is too slow"
- "Optimize the database queries in this module"
- "Reduce the bundle size for this component"
- "Make this code more readable"
- "This page takes too long to load"
Important Principles
- Measure first: Don't optimize without data
- Profile before fixing: Find real bottlenecks, not imagined ones
- One change at a time: Measure impact of each optimization
- Preserve correctness: Tests must still pass
- Avoid premature optimization: Focus on actual problems
Output Format
- Current state: Baseline metrics or issues
- Analysis: What's causing the problem
- Proposed changes: Specific optimizations
- Expected impact: Predicted improvements
- Verification: Proof of improvement (use proof-of-work skill)
Notes
- Use TodoWrite to track optimization steps
- Always provide before/after metrics
- Consider trade-offs (complexity vs performance)
- Document why optimizations were made