/code-quality:optimize [file-or-dir] [--queries|--bundle|--memory] [--target=<ms>] [--quick]from code-quality
Analyzes code, queries, and systems for performance bottlenecks including runtime, memory, database, and bundle size issues. Provides prioritized findings with measurable metrics.
Ships in code-quality. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze and suggest performance improvements for code, queries, or systems.
Identify optimization opportunities:
Determine optimization target:
# Find potentially slow patterns
grep -rn "forEach\|\.map\|\.filter\|\.reduce" --include="*.ts" --include="*.js" . | head -20
# Find nested loops (O(n²) potential)
grep -rn "for.*for\|\.forEach.*\.forEach\|\.map.*\.map" --include="*.ts" --include="*.js" . | head -10
# Find sync operations that could be async
grep -rn "readFileSync\|writeFileSync\|execSync" --include="*.ts" --include="*.js" . | head -10
# Large array operations
grep -rn "new Array\|Array\.from\|\.concat\|spread" --include="*.ts" --include="*.js" . | head -10
# Potential memory leaks (event listeners, intervals)
grep -rn "addEventListener\|setInterval\|setTimeout" --include="*.ts" --include="*.js" . | head -10
# N+1 query patterns
grep -rn "await.*find\|await.*query" --include="*.ts" --include="*.js" . | head -15
# Missing indexes hints
grep -rn "WHERE\|ORDER BY\|GROUP BY" --include="*.ts" --include="*.js" --include="*.sql" . | head -15
# Check bundle size (if applicable)
[ -f "package.json" ] && npm run build 2>/dev/null && ls -lh dist/*.js 2>/dev/null
# Large dependencies
[ -f "package.json" ] && cat package.json | jq '.dependencies | keys[]' | head -20
Rank findings by:
Target: [file/module/system] Analysis Date: [timestamp]
| Metric | Current | Target | Gap |
|---|---|---|---|
| Response time | Xms | <Yms | -Z% needed |
| Memory usage | XMB | <YMB | -Z% needed |
| Bundle size | XKB | <YKB | -Z% needed |
Problem: [What's slow and why]
Current:
// O(n²) - nested loops
users.forEach(user => {
permissions.forEach(perm => {
if (user.id === perm.userId) { ... }
});
});
Optimized:
// O(n) - Map lookup
const permMap = new Map(permissions.map(p => [p.userId, p]));
users.forEach(user => {
const perm = permMap.get(user.id);
if (perm) { ... }
});
Impact: ~10x faster for 1000 users Effort: Low (5 min) Risk: Low
| Issue | Location | Impact | Effort |
|---|---|---|---|
| [description] | file:line | [estimate] | [time] |
| Issue | Location | Impact | Effort |
|---|---|---|---|
| [description] | file:line | [estimate] | [time] |
Phase 1: Critical fixes (items 1-3)
Phase 2: High priority (items 4-6)
Phase 3: Measure and validate improvements
| Pattern | Issue | Fix |
|---|---|---|
arr.filter().map() | Two iterations | Single reduce() or flatMap() |
arr.find() in loop | O(n²) | Build Map/Set first |
[...arr1, ...arr2] | Memory allocation | arr1.concat(arr2) or push |
| Pattern | Issue | Fix |
|---|---|---|
| Loop with await | N+1 queries | Batch query with IN |
SELECT * | Over-fetching | Select only needed columns |
| Missing WHERE index | Full table scan | Add composite index |
| Pattern | Issue | Fix |
|---|---|---|
| Inline functions in JSX | Re-renders | useCallback |
| Large list rendering | DOM thrashing | Virtualization |
| Unoptimized images | Slow LCP | Next/Image, lazy loading |
| Pattern | Issue | Fix |
|---|---|---|
| Sync file operations | Blocks event loop | Async alternatives |
| JSON.parse large files | Memory spike | Streaming parser |
| No connection pooling | Connection overhead | Pool with pg-pool, etc. |
Analyze specific file:
/optimize src/services/user.ts
Focus on specific area:
/optimize --queries src/repositories/
/optimize --bundle
/optimize --memory src/workers/
With target metrics:
/optimize --target=100ms src/api/search.ts
Quick scan:
/optimize --quick
$ARGUMENTS
What SKILL.md sets; muted values are Claude Code's defaults
Use when a function or module needs performance analysis or improvements.
mediumThree short reads, in order
npx claudepluginhub florianbruniaux/claude-code-plugins --plugin code-quality18 skills in this plugin
/ast-grep-patternsStructural code search and refactoring with ast-grep: choose it over Grep, then write tested pattern and YAML rule recipes. Use when renaming calls or changing an API signature across a large codebase, migrating a framework, or finding code by shape (async functions without try/catch, empty catch blocks, long parameter lists). Not for plain text searches, which Grep handles faster./audit-codebaseCodebase health audit scoring 7 categories with progression plan/check-cache-bugsAudit Claude Code setup for cache bugs (CC#40524): sentinel, --resume/--continue, attribution header + ArkNill B3/B4/B5/design-patternsDetect, suggest, and evaluate GoF design patterns in TypeScript/JavaScript codebases. Use when refactoring code, applying singleton/factory/observer/strategy patterns, reviewing pattern quality, or finding stack-native alternatives for React, Angular, NestJS, and Vue./diagnoseInteractive troubleshooting assistant for Claude Code issues/eval-skillsAudit a project or library of skills for metadata, trigger boundaries, workflow completion criteria, local resource closure, instruction economy, tool scope, effort, and routing evidence. Use before shipping skills, after importing a skill collection, or when a skill triggers too often or not at all.Other plugins' skills for the same job