Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Perf?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/alexander-tyagunov-perf)
---
name: perf
description: Performance profiling and optimization, baseline first. Use when something is slow or must hit a latency/throughput target.
allowed-tools: Read, Grep, Glob, Bash(ugrep *), Bash(rg *), Bash(grep *), Bash(kg query *), Bash(kg blast *), Bash(kg neighbors *)
argument-hint: "[what is slow] [target, e.g. p99<500ms]"
---
# /perf — Performance Profiling
> **Bundled command:** if `kg` is not found, run it as `${CLAUDE_PLUGIN_ROOT}/tools/kg` and give subagents that full path. If that is missing too (Claude chat ships no plugin tools), skip the `kg` steps and search the code directly.
Profile and optimize performance systematically. No optimization without measurement.
Scale [/effort](../../lore/models.md) to the optimization scope: low for a single hot path, high for cross-cutting work. (Haiku and the 4.5 generation have no effort axis at all — don't suggest a level there.)
Scope the work with the knowledge graph when the repo is indexed: `kg query "<slow area>"` to locate the hot code and `kg blast`/`kg neighbors` to see what it touches — so you profile and change the right thing, in fewer tokens than grepping.
<HARD-GATE>
Establish a baseline measurement BEFORE making any changes. Optimization without a baseline is guesswork.
</HARD-GATE>
## Autonomy
Gates: none. Everything else runs without asking, except one plain question when the request does not say what is slow.
Benchmarks and profilers are not pre-approved, so Claude Code prompts for them outside auto mode. Apply the Phase 4 fix without a separate approval: the request to make it faster is the approval, and Phase 5 proves or disproves the fix ([lore/autonomy.md](../../lore/autonomy.md)).
## Process
### Phase 1: Define the Target
Take what is slow and the target from `$ARGUMENTS` and the request. Do not ask for what they already say.
- **What is slow** is missing: ask in plain text, "What is slow? Name the page, endpoint, query or command." End the turn. This is the only thing the skill cannot measure for itself.
- **The target** is missing: do not ask. Take the project's stated budget when one exists (a performance test, an SLO in the docs). Otherwise measure the baseline and state the target you will work to: "No target given. Baseline p95 is 840 ms; I will aim for a clear gain and report it. Say a number to set a target."
### Phase 2: Baseline
Measure current performance using the appropriate tool:
**API:**
```bash
wrk -t4 -c100 -d30s http://localhost:8080/api/endpoint
# or: hey -n 1000 -c 50 http://localhost:8080/api/endpoint
```
**Web (browser):**
Use the Lighthouse CLI if it is already installed (or the project's own Lighthouse script):
```bash
lighthouse http://localhost:3000 --output json --output-path baseline.json
```
**Python:**
```python
import cProfile, pstats
profiler = cProfile.Profile()
profiler.enable()
# ... run the slow code ...
profiler.disable()
stats = pstats.Stats(profiler).sort_stats('cumulative')
stats.print_stats(20)
```
**Go:**
```go
import _ "net/http/pprof"
// Then: go tool pprof http://localhost:6060/debug/pprof/profile
```
Record baseline numbers.
### Phase 3: Profile to Find Bottleneck
Use the profiler to identify the actual bottleneck. The bottleneck is where the most time is spent — not the most obvious place.
### Phase 4: Targeted Fix
Fix ONLY the identified bottleneck. Common fixes:
- DB: add index, use JOIN instead of N+1, batch queries
- API: cache response, reduce payload size, move work async
- Frontend: code splitting, lazy loading, image optimization
- Computation: use better algorithm, vectorize, parallelize
### Phase 5: Measure Again
Run the same benchmark as Phase 2. Compare: baseline vs. optimized.
This is a **bounded evaluator-optimizer loop**: if the target isn't met, return to Phase 3 and attack the next bottleneck — but stop after a few rounds, when a round's marginal gain is negligible, or when the `/effort`/token budget is exhausted, then report the best result with the target marked met/not-met. Never loop indefinitely. For long benchmarks or load tests, start them with the Bash tool's background option and read the output when Claude Code reports the command finished, instead of blocking the turn.
## Circulate the result (optional)
For a result worth circulating, you can publish the baseline→optimized report as a Claude Code **Artifact** (a live page on claude.ai, team-co-editable on Team/Enterprise) — mention it in the closing line, and create it only when the user asks. Publishing to a **public** link (anyone with the URL can view it) is an outward sharing action: **confirm it, keep it account-private by default, and never expose proprietary/internal system detail or secrets to a public link.**
**Dashboard offer.** Offer a Dashboard artifact (a page that re-runs its queries) only when both conditions hold:
- the session has the Artifact tool;
- the metrics come from a warehouse or a query source (BigQuery, Snowflake, Redshift, ClickHouse, a metrics database), not from a one-off local benchmark.
Offer it in one closing line after the Phase 5 report, as a statement and not a question. Do not build it without a yes. Keep it account-private, and never put credentials in the page.
## Obstacles
If this skill runs as a dispatched unit and hits something that blocks or degrades the work, do not wait for a human who is not there and do not silently ship a degraded result — return the Obstacles block from [lore/obstacles.md](../../lore/obstacles.md) (fields: STATUS, OBSTACLE, BLOCKER, SEVERITY, WORKAROUND, RECURRENCE, SCOPE, NEXT) to the caller alongside whatever you completed; interactively, say the same in prose.
## Completion Signal
"Perf complete. Baseline: <N>. Optimized: <N>. Improvement: <X>%. Target <met/not met>."