/codspeed:codspeed-write-benchmarksfrom codspeed
Writes, fixes, and maintains CodSpeed benchmarks for valid and stable measurements. Covers relevance, validity, determinism, state isolation, and sizing rules.
Ships in codspeed. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A benchmark is useful when a change in its result means a change in the code. Apply the rules below when writing a benchmark, and use them as the checklist when one misbehaves.
Run benchmarks through the CodSpeed CLI (codspeed run, codspeed exec) and read results with the CodSpeed MCP tools, not from raw framework output.
Relevance: One benchmark answers one question about a real hot path or user-facing operation. Use inputs with a realistic size and distribution.
Validity: The code under test must actually run. Use its result (return it, or pass it to the framework's black box) and keep inputs opaque to the optimizer, otherwise the work can be removed or computed at compile time. See optimized-out benchmarks.
Measured region: Measure only the operation under test. Build inputs outside the measured code. If the operation mutates its input, give every iteration a fresh copy through the framework's setup hook. Every iteration must do the same work.
Determinism: The same code must do the same work on every run. Seed random generators, use fixed-seed hashing or ordered containers, sort directory listings, and read committed fixtures. No network, clock, or environment-dependent branches. See Benchmark Variance.
State isolation: A result must not depend on which benchmarks ran before it. Avoid shared caches and globals. Allocator and garbage collector state carries over between benchmarks, so allocate inputs in setup rather than in the measured code. If a micro-benchmark still moves with unrelated code changes, build it into its own binary. See Reducing Variance.
Sizing: Size each benchmark so it gives a valid result under every instrument it runs with. One benchmark can run under several instruments, and each one has its own limits:
Naming: A benchmark's identity sets its history. Framework integrations use the file path, name, and parameters. The exec harness uses the name field, or the full command when there is none. Keep the identity stable, unique within a run, and descriptive of the scenario.
Environment: Pin the toolchain and commit lockfiles. Avoid latest and stable tags in CI. Run walltime benchmarks on CodSpeed Macro Runners. Base and head must run on the same hardware.
get_run reports no issue on it.query_flamegraph shows the function under test, not setup code, as the main cost.get_benchmark_result shows the spread across rounds and the outliers.If the CLI or the MCP tools are not available, report the findings from step 1 and state that nothing was measured.
compare_runs on two runs that disagree. If it lists environment differences (hardware, toolchain, integration version), fix rule 8 first.query_flamegraph on both runs and find what differs. Allocator, garbage collector, hashing, or I/O frames point to rules 4 and 5.List the benchmarks with get_run. Merge or remove benchmarks that answer the same question. Fix or remove those that break a rule. Shrink or split those that dominate the run time. Report hot paths without a benchmark, but do not add speculative ones.
A change to a benchmark's identity (rule 7) starts a new history, and the old benchmark shows up as skipped. Do not change it without a reason. After a rename, move, or removal, confirm the old benchmark no longer runs, then tell the user to archive it in the dashboard (organization admins only).
Keep the name, the input, and the measured region so the history stays comparable. If the benchmark now measures something different, give it a new name.
The rules apply to every language. These are the points that differ. For framework APIs, follow the linked docs.
black_box. With divan, with_inputs(..) provides a fresh input per iteration: use bench_values to take it by value, or bench_refs / bench_local_refs to mutate it in place. HashMap seeds are random per process, so use a fixed hasher or a BTreeMap for benchmark data.@pytest.mark.benchmark measures the whole test. Use the benchmark fixture to measure only the call, and benchmark.pedantic(setup=...) for a fresh input per round.entrypoint with a custom harness to measure a sub-part. Keep debug symbols so flamegraphs are readable.What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/codspeed-optimizeAutonomously 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./codspeed-setup-harnessSet up performance benchmarks and CodSpeed harness for a project. Use this skill whenever the user wants to set up CodSpeed, configure codspeed.yml, integrate a benchmarking framework (criterion, divan, pytest-benchmark, vitest bench, go test -bench, google benchmark), or when the user says 'set up perf tests', 'add CodSpeed', or wants to measure performance of a project that has no benchmarks yet. Also trigger when the optimize skill needs benchmarks that don't exist yet. To write, fix, or maintain benchmarks in a project that already runs CodSpeed, use codspeed-write-benchmarks instead.npx claudepluginhub codspeedhq/codspeed --plugin codspeedOther plugins' skills for the same job