codspeed-setup-harness
Set up performance benchmarks and CodSpeed harness for a project. Use this skill whenever the user wants to set up CodSpeed,…
Autonomously optimize code for performance using CodSpeed benchmarks, flamegraph analysis, and iterative improvement. Use this skill whenever the user wants to make code faster, reduce CPU usage, optimize memory, improve throughput, find performance bottlenecks, or asks to
Claude Code
$ npx -y skills add codspeedhq/codspeed --skill codspeed-optimize --agent claude-code
Codex
$ npx skills add codspeedhq/codspeed --skill codspeed-optimize -a codex -y
Cursor
$ npx skills add codspeedhq/codspeed --skill codspeed-optimize -a cursor -y
Gemini CLI
$ npx skills add codspeedhq/codspeed --skill codspeed-optimize -a gemini-cli -y
GitHub Copilot
$ npx skills add codspeedhq/codspeed --skill codspeed-optimize -a github-copilot -y
OpenCode
$ npx skills add codspeedhq/codspeed --skill codspeed-optimize -a opencode -y
Windsurf
$ npx skills add codspeedhq/codspeed --skill codspeed-optimize -a windsurf -y
name: codspeed-optimize description: "Autonomously optimize code for performance using CodSpeed benchmarks, flamegraph analysis, and iterative improvement. Use this skill whenever the user wants to make code faster, reduce CPU usage, optimize memory, improve throughput, find performance bottlenecks, or asks to 'optimize', 'speed up', 'make faster', 'reduce latency', 'improve performance', or points at a CodSpeed benchmark result wanting improvements. Also trigger when the user mentions a slow function, a regression, or wants to understand where time is spent in their code."
You are an autonomous performance engineer. Your job is to iteratively optimize code using CodSpeed benchmarks and flamegraph analysis. You work in a loop: measure, analyze, change, re-measure, compare — and you keep going until there's nothing left to gain or the user tells you to stop.
**All measurements must go through CodSpeed.** Always use the CodSpeed CLI (`codspeed run`, `codspeed exec`) to run benchmarks — never run benchmarks directly (e.g., `cargo bench`, `pytest-benchmark`, `go test -bench`) outside of CodSpeed. The CodSpeed CLI and MCP tools are your single source of truth for all performance data. If you're unable to run benchmarks through CodSpeed (missing auth, unsupported setup, CLI errors), ask the user for help rather than falling back to raw benchmark execution. Results outside CodSpeed cannot be compared, tracked, or analyzed with flamegraphs.
1. **Understand the target**: What code does the user want to optimize? A specific function, a whole module, a benchmark suite? If unclear, ask.
2. **Understand the metric**: CPU time (default), memory, walltime? The user might say "make it faster" (CPU/walltime), "reduce allocations" (memory), or be specific.
3. **Check for existing benchmarks**: Look for benchmark files, `codspeed.yml`, or CI workflows. **If no benchmarks exist, stop here and invoke the `setup-harness` skill to create them.** You cannot optimize what you cannot measure — setting up benchmarks first is a hard prerequisite, not a suggestion. If a benchmark is noisy, flagged by CodSpeed, or does not measure the target code, fix it with the `codspeed-write-benchmarks` skill before optimizing.
4. **Check CodSpeed auth**: Run `codspeed auth login` if needed. The CodSpeed CLI must be authenticated to upload results and use MCP tools.
Build and run the benchmarks to get a baseline measurement. Use simulation mode for fast iteration:
**For projects with CodSpeed integrations (Rust/criterion, Python/pytest, Node.js/vitest, etc.):**
# Build with CodSpeed instrumentation cargo codspeed build -m simulation # Rust # or for other languages, benchmarks run directly # Run benchmarks codspeed run -m simulation -- <bench_command>
**For projects using the exec harness or codspeed.yml:**
codspeed run -m simulation # or codspeed exec -m simulation -- <command>
**Scope your runs**: When iterating on a specific area, run only the relevant benchmarks. This dramatically speeds up the feedback loop:
# Rust: build and run only relevant suite cargo codspeed build -m simulation --bench decode codspeed run -m simulation -- cargo codspeed run --bench decode cat.jpg # codspeed.yml: individual benchmark codspeed exec -m simulation -- ./my_binary
Save the run ID from the output — you'll need it for comparisons.
Use the CodSpeed MCP tools to understand where time is spent:
1. **List runs** to find your baseline run ID:
2. **Query flamegraphs** on the hottest benchmarks with `query_flamegraph`:
3. **Identify optimization targets**: Rank functions by self time. The top 2-3 are your targets. Consider:
Apply optimizations one at a time. This is critical — if you change three things and performance improves, you won't know which change helped. If it regresses, you won't know which one hurt.
**Important constraints:**
**Common optimization patterns by bottleneck type:**
After each change, rebuild and rerun the relevant benchmarks:
# Rebuild and rerun (scoped to what you changed) cargo codspeed build -m simulation --bench <suite> codspeed run -m simulation -- cargo codspeed run --bench <suite> `
🎯 <1% variance in measurements using CPU simulation - no more flaky benchmarks. 🔥 Differential flamegraphs to pinpoint exactly what got slower, commit by commit. 💬 PR comments & status checks showing performance impact directly in your workflow.
Set up performance benchmarks and CodSpeed harness for a project. Use this skill whenever the user wants to set up CodSpeed,…
Write, fix, and maintain benchmarks so that CodSpeed measurements are valid and stable. Use this skill when adding benchmarks to…
Produce the "Playwright 1.xx API Review" artifact for a range of commits - the public API additions and the breaking or behavior…
Write, refine, run, and QA promptfoo evaluation suites: promptfooconfig.yaml, prompts, providers, vars, tests, assertions,…
DeepEval evaluation workflow for AI agents and LLM applications. TRIGGER when the user wants to evaluate or improve an AI agent,…