/perf
Comprehensive performance analysis and optimization with intelligent profiling and sub-agent coordination
How 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
/perf
Context preview
What this command does when you run it.
Comprehensive performance analysis and optimization with intelligent profiling and sub-agent coordination
Command definition
perf.mdallowed-tools: Task, Read, Write, Bash(rg:*), Bash(fd:*), Bash(ps:*), Bash(htop:*), Bash(jq:*), Bash(gdate:*), Bash(kubectl:*), Bash(docker:*), Bash(cargo:*), Bash(go:*), Bash(mvn:*), Bash(gradle:*)
name: "Perf"
description: "Comprehensive performance analysis and optimization with intelligent profiling and sub-agent coordination"
author: "wcygan"
tags: ["ops","perf"]
version: "1.0.0"
created_at: "2025-07-14T00:00:00Z"
updated_at: "2025-07-14T00:00:00Z"
Context
- Session ID: !`gdate +%s%N 2>/dev/null || date +%s%N 2>/dev/null || echo "$(date +%s)$(jot -r 1 100000 999999 2>/dev/null || shuf -i 100000-999999 -n 1 2>/dev/null || echo $RANDOM$RANDOM)"`
- Performance target: $ARGUMENTS
- Project structure: !`fd "(package\.json|Cargo\.toml|go\.mod|pom\.xml|build\.gradle|deno\.json)" . -d 3 | head -5 || echo "No build files detected"`
- Running processes: !`ps aux | rg "(java|go|rust|node|deno|python)" | head -5 || echo "No target processes detected"`
- System resources: !`echo "CPU: $(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 'unknown') cores | RAM: $(free -h 2>/dev/null | rg 'Mem:' | awk '{print $2}' || echo 'unknown')" 2>/dev/null || echo "System info unavailable"`
- Container status: !`docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null | head -5 || echo "No Docker containers"`
- K8s resources: !`kubectl get pods --all-namespaces 2>/dev/null | head -5 || echo "No Kubernetes cluster"`
Your Task
STEP 1: Initialize comprehensive performance analysis session
- CREATE performance analysis state: `/tmp/perf-analysis-$SESSION_ID.json`
- ANALYZE project technology stack from Context section
- DETERMINE analysis scope based on target: $ARGUMENTS
- VALIDATE required profiling tools availability
# Initialize performance analysis session
echo '{
"sessionId": "'$SESSION_ID'",
"target": "'$ARGUMENTS'",
"technologyStack": [],
"profiledComponents": [],
"optimizationOpportunities": [],
"performanceBaseline": {}
}' > /tmp/perf-analysis-$SESSION_ID.jsonSTEP 2: Technology-aware performance profiling strategy
TRY:
CASE detected_technology: WHEN "java_project":
- EXECUTE JVM performance profiling with JProfiler/async-profiler
- ANALYZE JMX metrics, heap dumps, GC logs
- CHECK Spring Boot actuator endpoints for metrics
- VALIDATE connection pool configurations (HikariCP)
WHEN "go_project":
- ENABLE pprof profiling endpoints: `go tool pprof`
- EXECUTE CPU and memory profiling: `go test -bench . -cpuprofile`
- ANALYZE goroutine usage and channel patterns
- CHECK for race conditions: `go test -race`
WHEN "rust_project":
- GENERATE flame graphs: `cargo flamegraph`
- PROFILE with perf and valgrind for memory analysis
- ANALYZE async runtime performance (Tokio/async-std)
- CHECK for unnecessary allocations and clones
WHEN "typescript_node_project":
- ENABLE Node.js profiling: `node --prof` or `clinic.js`
- ANALYZE event loop utilization and async patterns
- CHECK for memory leaks with heap snapshots
- VALIDATE worker thread usage patterns
WHEN "deno_project":
- USE Deno's built-in profiling: `deno run --inspect`
- ANALYZE V8 performance patterns
- CHECK import resolution and dependency loading
- VALIDATE async/await patterns and Promise usage
**Language-Specific Profiling Commands:**
# Java profiling
if fd "pom\.xml|build\.gradle" . | head -1 >/dev/null; then
echo "โ Java project detected - enabling JVM profiling"
# async-profiler or JProfiler integration
fi
# Go profiling
if fd "go\.mod" . | head -1 >/dev/null; then
echo "๐น Go project detected - enabling pprof"
# go tool pprof integration
fi
# Rust profiling
if fd "Cargo\.toml" . | head -1 >/dev/null; then
echo "๐ฆ Rust project detected - enabling cargo profiling"
# cargo flamegraph integration
fi
STEP 3: Parallel performance analysis using sub-agent architecture
IF performance_scope == "comprehensive" OR target_complexity == "high":
LAUNCH parallel sub-agents for systematic performance exploration:
- **Agent 1: Algorithm Analysis**: Analyze computational complexity and algorithm efficiency
- Focus: Big O analysis, nested loops, recursive patterns, memoization opportunities
- Tools: Static code analysis, complexity detection, pattern recognition
- Output: Algorithm bottlenecks with complexity ratings and optimization suggestions
- **Agent 2: Data Structure Optimization**: Evaluate data structure choices and access patterns
- Focus: Array vs Set vs Map usage, inefficient lookups, cache locality, memory layout
- Tools: Code pattern analysis, data structure usage tracking
- Output: Data structure recommendations with performance impact estimates
- **Agent 3: Database Performance**: Analyze database queries and connection patterns
- Focus: N+1 queries, missing indexes, JOIN optimization, connection pooling
- Tools: Query analysis, EXPLAIN ANALYZE, database metrics
- Output: Database optimization plan with query improvements
- **Agent 4: Async/Concurrency Analysis**: Evaluate async patterns and parallel processing
- Focus: Thread pools, async/await usage, goroutines/channels, reactive patterns
- Tools: Concurrency pattern analysis, deadlock detection
- Output: Concurrency optimization with scalability improvements
- **Agent 5: Caching Strategy**: Analyze current caching and propose improvements
- Focus: Application-level caching, distributed caching, cache invalidation
- Tools: Cache hit rate analysis, TTL optimization, cache pattern evaluation
- Output: Comprehensive caching strategy with implementation plan
- **Agent 6: Resource Optimization**: Analyze resource usage and efficiency
- Focus: Memory allocation, I/O patterns, connection pooling, resource cleanup
- Tools: Resource tracking, allocation analysis, leak detection
- Output: Resource optimization plan with memory and I/O improvements
**Sub-Agent Coordination:**
# Each agent reports findings to session state
echo "Launching parallel perf
Read more
allowed-tools: Task, Read, Write, Bash(rg:*), Bash(fd:*), Bash(ps:*), Bash(htop:*), Bash(jq:*), Bash(gdate:*), Bash(kubectl:*), Bash(docker:*), Bash(cargo:*), Bash(go:*), Bash(mvn:*), Bash(gradle:*) name: "Perf" description: "Comprehensive performance analysis and optimization with intelligent profiling and sub-agent coordination" author: "wcygan" tags: ["ops","perf"] version: "1.0.0" created_at: "2025-07-14T00:00:00Z" updated_at: "2025-07-14T00:00:00Z"
Context
- Session ID: !`gdate +%s%N 2>/dev/null || date +%s%N 2>/dev/null || echo "$(date +%s)$(jot -r 1 100000 999999 2>/dev/null || shuf -i 100000-999999 -n 1 2>/dev/null || echo $RANDOM$RANDOM)"`
- Performance target: $ARGUMENTS
- Project structure: !`fd "(package\.json|Cargo\.toml|go\.mod|pom\.xml|build\.gradle|deno\.json)" . -d 3 | head -5 || echo "No build files detected"`
- Running processes: !`ps aux | rg "(java|go|rust|node|deno|python)" | head -5 || echo "No target processes detected"`
- System resources: !`echo "CPU: $(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 'unknown') cores | RAM: $(free -h 2>/dev/null | rg 'Mem:' | awk '{print $2}' || echo 'unknown')" 2>/dev/null || echo "System info unavailable"`
- Container status: !`docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null | head -5 || echo "No Docker containers"`
- K8s resources: !`kubectl get pods --all-namespaces 2>/dev/null | head -5 || echo "No Kubernetes cluster"`
Your Task
STEP 1: Initialize comprehensive performance analysis session
- CREATE performance analysis state: `/tmp/perf-analysis-$SESSION_ID.json`
- ANALYZE project technology stack from Context section
- DETERMINE analysis scope based on target: $ARGUMENTS
- VALIDATE required profiling tools availability
# Initialize performance analysis session
echo '{
"sessionId": "'$SESSION_ID'",
"target": "'$ARGUMENTS'",
"technologyStack": [],
"profiledComponents": [],
"optimizationOpportunities": [],
"performanceBaseline": {}
}' > /tmp/perf-analysis-$SESSION_ID.jsonSTEP 2: Technology-aware performance profiling strategy
TRY:
CASE detected_technology: WHEN "java_project":
- EXECUTE JVM performance profiling with JProfiler/async-profiler
- ANALYZE JMX metrics, heap dumps, GC logs
- CHECK Spring Boot actuator endpoints for metrics
- VALIDATE connection pool configurations (HikariCP)
WHEN "go_project":
- ENABLE pprof profiling endpoints: `go tool pprof`
- EXECUTE CPU and memory profiling: `go test -bench . -cpuprofile`
- ANALYZE goroutine usage and channel patterns
- CHECK for race conditions: `go test -race`
WHEN "rust_project":
- GENERATE flame graphs: `cargo flamegraph`
- PROFILE with perf and valgrind for memory analysis
- ANALYZE async runtime performance (Tokio/async-std)
- CHECK for unnecessary allocations and clones
WHEN "typescript_node_project":
- ENABLE Node.js profiling: `node --prof` or `clinic.js`
- ANALYZE event loop utilization and async patterns
- CHECK for memory leaks with heap snapshots
- VALIDATE worker thread usage patterns
WHEN "deno_project":
- USE Deno's built-in profiling: `deno run --inspect`
- ANALYZE V8 performance patterns
- CHECK import resolution and dependency loading
- VALIDATE async/await patterns and Promise usage
**Language-Specific Profiling Commands:**
# Java profiling if fd "pom\.xml|build\.gradle" . | head -1 >/dev/null; then echo "โ Java project detected - enabling JVM profiling" # async-profiler or JProfiler integration fi # Go profiling if fd "go\.mod" . | head -1 >/dev/null; then echo "๐น Go project detected - enabling pprof" # go tool pprof integration fi # Rust profiling if fd "Cargo\.toml" . | head -1 >/dev/null; then echo "๐ฆ Rust project detected - enabling cargo profiling" # cargo flamegraph integration fi
STEP 3: Parallel performance analysis using sub-agent architecture
IF performance_scope == "comprehensive" OR target_complexity == "high":
LAUNCH parallel sub-agents for systematic performance exploration:
- **Agent 1: Algorithm Analysis**: Analyze computational complexity and algorithm efficiency
- Focus: Big O analysis, nested loops, recursive patterns, memoization opportunities
- Tools: Static code analysis, complexity detection, pattern recognition
- Output: Algorithm bottlenecks with complexity ratings and optimization suggestions
- **Agent 2: Data Structure Optimization**: Evaluate data structure choices and access patterns
- Focus: Array vs Set vs Map usage, inefficient lookups, cache locality, memory layout
- Tools: Code pattern analysis, data structure usage tracking
- Output: Data structure recommendations with performance impact estimates
- **Agent 3: Database Performance**: Analyze database queries and connection patterns
- Focus: N+1 queries, missing indexes, JOIN optimization, connection pooling
- Tools: Query analysis, EXPLAIN ANALYZE, database metrics
- Output: Database optimization plan with query improvements
- **Agent 4: Async/Concurrency Analysis**: Evaluate async patterns and parallel processing
- Focus: Thread pools, async/await usage, goroutines/channels, reactive patterns
- Tools: Concurrency pattern analysis, deadlock detection
- Output: Concurrency optimization with scalability improvements
- **Agent 5: Caching Strategy**: Analyze current caching and propose improvements
- Focus: Application-level caching, distributed caching, cache invalidation
- Tools: Cache hit rate analysis, TTL optimization, cache pattern evaluation
- Output: Comprehensive caching strategy with implementation plan
- **Agent 6: Resource Optimization**: Analyze resource usage and efficiency
- Focus: Memory allocation, I/O patterns, connection pooling, resource cleanup
- Tools: Resource tracking, allocation analysis, leak detection
- Output: Resource optimization plan with memory and I/O improvements
**Sub-Agent Coordination:**
# Each agent reports findings to session state echo "Launching parallel perf
A lightweight (~46kB) and comprehensive CLI tool for managing Claude commands, configurations, and workflows.
Repo: kiliczsh/claude-cmd
Other commands on claude-cmd.
- /agent-browser-automation
Automate browser interactions for development testing using Puppeteer MCP
Open command - /agent-prep-merge
Prepare branches for merging across multiple worktrees and coordinate integration
Open command - /agent-persona-accessibility-expert
Transform into accessibility expert for WCAG compliance and inclusive design
Open command - /agent-persona-api-designer
Transform into an API design specialist who creates well-structured, developer-friendly APIs
Open command - /agent-persona-backend-specialist
Transform into backend specialist for scalable API and system design
Open command - /agent-persona-cloud-architect
Cloud architect persona for designing scalable, secure cloud infrastructure using modern cloud-native technologies
Open command

