From odin
Locates a hot path in code, fans out multiple transformation agents, benchmarks candidates, and commits the winning speedup with proven measurement.
How this skill is triggered — by the user, by Claude, or both
Slash command
/odin:optimizeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
A self-contained diagnose→optimize→verify loop. Locate the hot path (lightly — no full
A self-contained diagnose→optimize→verify loop. Locate the hot path (lightly — no full
investigation ledger), fan out five candidate transformations as worktree-isolated Agent calls,
benchmark each, gate on behavior, commit the winner. The deliverable is a committed, measured
change — not a verdict, not a report, not a list of suggestions.
Op-cell is context-dependent: correct + Restores: spec:<budget> when a --budget or a named
regression is the target; compress when removing wasted work with no stated budget; extend when
the winning change adds an approximation or cache contract that changes observable semantics.
Rejection grounds: Excess (micro-opt with no measured hotspot), Graft (optimization applied
before the hotspot is confirmed), Sprawl (added complexity that outweighs the earned speedup).
Reference files (verbatim prompts, agent dispatch shapes, harness templates):
references/lenses.md — five lens prompts sent to candidate agents, one per lensreferences/tooling.md — per-language benchmark/profile tooling matrix + minimal harness
templates for the author-a-harness phaseperf-profile output — or run Phase 2's light locate. Never fan out candidates against unmeasured code.hyperfine --warmup 3 --min-runs 10 measurement (variance-aware). If no harness exists, author a minimal throwaway under .outline/optimize/. Fall back to a rigorous complexity/allocation argument only when benchmarking is genuinely impractical — label it [UNMEASURED] in the commit body.<symbol>".--budget) and the current code does not meet it.perf-profile. Use it first if the hotspot is unknown; then come back here.perf-investigate. Use it when you need an auditable case file across multiple experiments.simplify. It runs no benchmarks and explicitly forbids behavior-affecting speedups.perf-investigate or a plain planning session. Optimization surgery within a hot path is in scope; full module rewrites are not.If /optimize <path|symbol|diff> was given, use that as the target. If no arg, detect active
context (current diff, current file in editor, top of git stack) as tidy does — if the context is
empty or unresolvable, error explicitly rather than guessing.
Auto-skip check: if the resolved target is a single function <50 LOC and only one obvious concern is visible, declare auto-skip, note it aloud, and proceed with a single-pass loop (Phases 3 → 5 single-agent → 6 → 7 → 8). Otherwise proceed with the full five-agent fan-out.
Parse --budget <metric> (e.g. --budget p95<3ms, --budget throughput>10k/s,
--budget alloc<1MB) — sets the op-cell to correct and the stop condition.
If a profile artifact, flamegraph, or named symbol was supplied, accept it and skip profiling.
Otherwise run a light locate:
hyperfine '<workload cmd>' — confirm the workload takes measurable wall-clock time.references/tooling.md for per-language choice).HOT_PATH.If no hotspot clears a 5 % share of total time, exit 11 — no actionable target.
Author or locate a benchmark harness for HOT_PATH (see references/tooling.md). If none exists,
write a minimal throwaway harness under .outline/optimize/<target>/bench.* that exercises the hot
function in isolation. Run:
hyperfine '<bench cmd>' --warmup 3 --min-runs 10 --export-json .outline/optimize/<target>/before.json
Record: median, stddev, min/max. This is the before measurement. Do not proceed if stddev >
20 % of median — fix measurement noise first (pin CPU frequency, isolate the process, widen
--min-runs).
Launch five worktree-isolated agents in one tool-call message (independent by construction —
disjoint lenses, no shared files). For each lens L in {algo, data, cache, concur,
arch}:
Agent(
prompt = references/lenses.md § <L> + "\n\n---\n\nHOT_PATH: " + <symbol> +
"\n\nCODE:\n" + <hot-path source> +
"\n\nBEFORE (hyperfine median): " + <before_median>,
isolation = "worktree"
)
Each agent must:
hyperfine '<bench cmd>' --warmup 3 --min-runs 10 --export-json after.json.{lens, change_summary, before_median, after_median, speedup_ratio, behavior_self_assessment, readability_cost, diff_patch}.Document the independence argument in the spawn message: "disjoint lenses, isolated worktrees, read-only phase after reporting".
Collect the five result objects (null = agent failed; .filter(Boolean) before ranking). Compute:
composite = speedup_ratio × behavior_safety × (1 - readability_cost × 0.3)
Where behavior_safety = 1.0 (exact behavior claimed), 0.7 (approximation with disclosed
contract), or 0.0 (unsafe / undisclosed). Sort descending. Name the winner and the runner-up.
If speedup_ratio < 1.05 for all candidates, exit 12 — no candidate clears noise.
If the winner relies on approximation (behavior_safety < 1.0) and the user has not already
confirmed in prose: present the exact contract change and wait for confirmation. If declined, exit
14. If confirmed, set op-cell to extend and document the contract change in the commit body.
Dispatch a single adversarial reviewer agent:
Agent(
prompt = "You are an adversarial reviewer. The following optimization diff was applied to <HOT_PATH>.
Try hard to construct any input or call sequence where the optimized version produces
a different observable result than the original. Check: output identity, error
semantics, public API contract, edge inputs (empty, max, negative, NaN, concurrent).
If approximation is claimed, check that the contract was disclosed correctly.
Return: {passed: bool, failure_scenario: string|null}"
)
If passed = false, log the failure scenario, revert the candidate worktree, promote the
runner-up, and repeat Phase 6. If all candidates fail the gate, exit 13.
Apply the winner's diff_patch to the main worktree.
Integrated benchmark gate (pre-commit). Run hyperfine on the main tree — not the worktree — to confirm the win survives integration:
hyperfine '<bench_cmd>' --warmup 3 --min-runs 10 \
--export-json .outline/optimize/<target>/after-integrated.json
Compute integrated_speedup = before_median / after_integrated_median. Values > 1.0 mean
faster; values < 1.0 mean a regression. If integrated_speedup < 1.05 the win fell into noise
— discard the patch with git restore . and exit 12. Do not commit a change whose speedup
cannot survive integration; the deliverable is a proven win, not a worktree artifact.
Run repo-native tests. On red, discard the patch with git restore . (nothing is committed yet) and exit 13. Do not use git revert HEAD — that would revert the previous commit, not the uncommitted patch.
Commit with:
<type>(optimize): <hot-path>: <lens>: <speedup summary>
<prose rationale + evidence>
Before: <before_median> ± <stddev>
After: <after_integrated_median> ± <stddev> (integrated, main tree)
Win: <integrated_speedup>× (<pct>%)
Op: correct | compress | extend
Restores: spec:<budget> ← only when --budget was given or regression restored
rm -rf .outline/optimize/<target>/agent-*.The integrated win was already confirmed in Phase 7 before the commit. Phase 8 records the guard recommendation only.
Suggest (do not force) adding a CI regression guard: a benchmark invocation that fails if the
median regresses past before_median × 1.05. Place the guard command in the project's CI config
or a Justfile / Makefile target named bench-guard. The before-benchmark JSON artifact at
.outline/optimize/<target>/before.json can seed the threshold.
| Gate | Pass Criteria | Blocking |
|---|---|---|
| Hotspot identified | Hot path supplied or located with ≥5 % self-time share | Yes — exit 11 if no hotspot |
| Baseline captured | Before-benchmark median with stddev <20 % | Yes — fix measurement noise first |
| Fan-out dispatched | All candidate agents launched in one tool-call message (or auto-skip declared) | Yes |
| Composite score non-zero | At least one candidate speedup_ratio ≥1.05 | Yes — exit 12 if none |
| Approximation confirmed | If any winner claims approximation, user confirmed contract change | Yes — exit 14 if declined |
| Adversarial gate cleared | Adversarial reviewer returned passed=true for the winner | Yes — promote runner-up or exit 13 |
| Tests green | Repo-native tests pass after apply, before commit | Yes — discard patch with git restore . on red, exit 13 |
| Op trailer present | Commit body carries Op: correct|compress|extend | Yes |
| Worktrees cleaned | .outline/optimize/<target>/agent-* dirs removed | Yes |
| Code | Meaning |
|---|---|
| 0 | Clean — optimization landed, win proven, all gates passed |
| 11 | No measurable target — active context too trivial, no hotspot with ≥5 % share, or workload too fast to measure |
| 12 | No winning candidate — all five lens agents ran; none cleared the 1.05× noise threshold; no change committed |
| 13 | Behavior regression — adversarial gate rejected all candidates, or repo tests went red after apply; reverted |
| 14 | Approximation declined — user did not confirm the contract change; optimization aborted |
| 15 | Mixed-concern commit — more than one optimization concern bundled; split before committing |
/optimize if the hotspot is unknown. /optimize accepts perf-profile output as a Phase 2 bypass..outline/perf/ ledger, baseline series, multiple keep/stop experiments, and an auditable verdict. Use when a case file and multi-experiment record are required. /optimize delivers a committed change in one pass; perf-investigate delivers a verdict across many./optimize when runtime performance is the target./optimize never breaks public API contracts (except the disclosed approximation path, which requires explicit user confirmation).npx claudepluginhub outlinedriven/odin-claude-plugin --plugin odinAutonomously optimizes code performance using CodSpeed benchmarks, flamegraph analysis, and iterative improvement. Activates on optimization requests, slow functions, or regression mentions.
Guides measure-first optimization: profile to identify hot spots, apply algorithm/data-structure improvements before micro-optimizations, and validate each change to prevent regression.
Identifies and fixes performance bottlenecks by profiling code, suggesting targeted optimizations, implementing with TDD, and verifying improvements. Supports backend (Python, Go, Node), frontend (JS), full scopes.