optimize-loop
Use when the user wants to iteratively improve an artifact under a hard correctness bound while minimizing a measured cost — refactoring a code module to cut complexity while its test suite stays green, OR speeding up a SQL query while it returns the same rows. Each iteration applies one focused change, checks a correctness gate that must pass, measures a metric that must drop, and keeps the change only if both hold, else reverts; loops to a plateau or budget. Not for adding features, fixing bugs, or any change that is allowed to alter behaviour or results.
npx skills add gaasher/Agent-Loop-Skills --skill optimize-loop --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Optimize Loop An **evaluator-optimizer** loop with a **pluggable correctness gate + minimized metric**. The artifact is some editable thing (a code module or a SQL query); the feedback signal is two-part: a **bound gate that must pass** (behaviour/results unchanged) and a **bound metric that must drop** (the cost you minimize). You apply one change, check the gate, measure the metric, and keep the change only if the gate passes AND the metric improves — otherwise you revert. Repeat until the metric stops improving or the budget runs out. Once the loop starts, do not pause for permission. Two ready bindings ship in `tools/` (both vendored, stdlib-only): - **code mode** — gate: `<gate_cmd>` (the test suite) exits 0; metric: `tools/metrics.py` prints `complexity` (primary), `max_nesting`, `loc` (lexicographic tie-breakers). Lower is better. - **sql mode** — gate: the result-set `hash` from `tools/bench.py` matches the baseline; metric: the same tool's `median_ms`. Lower is better. The gate is non-negotiable in both modes: a change that fails it is a regression, not an improvement. Never edit the ground truth (the tests / `tools/metrics.py` in code mode, the database / `tools/bench.p
- When to use
- Setup
- The loop (until plateau or <budget>)
- Ledger
- Constraints
What does the optimize-loop skill do?
Use when the user wants to iteratively improve an artifact under a hard correctness bound while minimizing a measured cost — refactoring a code module to cut complexity while its test suite stays green, OR speeding up a SQL query while it returns the same rows. Each iteration applies one focused change, checks a correctness gate that must pass, measures a metric that must drop, and keeps the change only if both hold, else reverts; loops to a plateau or budget. Not for adding features, fixing bugs, or any change that is allowed to alter behaviour or results.
How do I install it?
Run `npx skills add gaasher/Agent-Loop-Skills --skill optimize-loop --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From gaasher/Agent-Loop-Skills, a repository with 146 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
