Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Stage, format, lint, test, review, smoke test, and re-run itself until stable. Use when the user asks to "polish code", "refine code", "iterate on code quality", "review loop", "clean up, test, and review loop", or "run the polish loop".
.claude/skills/tobihagemann-polish-code/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-10 | ✗→✓ | ▲ Improved | 105% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 67% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 121% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 244% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 106% | 0% |
At the start of every invocation (including re-runs from Step 7), use update_plan to track each step, restating any remaining steps of a parent workflow alongside them:
$stage skill$review-code skill$evaluate-findings skill$apply-findings skill$smoke-test skill$polish-code skill if changedLoop state lives at .turbo/loops/<slug>.md — slug from the governing plan when one is in context, otherwise the current branch name with non-alphanumerics replaced by hyphens. At the start of every invocation, read the ledger if it exists.
Status: line is closed): write a fresh ledger with Status: active, then attempt create_goal with the objective: "Run the $polish-code loop on <scope> until converged: a run with no changes, an in-place-only round, or remaining findings that do not justify another re-run. Loop state: .turbo/loops/<slug>.md; re-read it after any context compaction and do not re-adjudicate findings it records as rejected. Mark this goal complete when the loop converges." If an unfinished goal already exists, an outer workflow owns it; continue without creating one.Status: active): this invocation is the iteration after the last one the ledger records, whether a Step 7 re-run or a resumption after an interruption. Continue from the recorded state. A Pending smoke-test baseline entry means a previous iteration was interrupted between delegating the smoke test and verifying the tree: reconcile the tree against that entry and clear it before Step 1, so Step 1 does not stage what the interrupted sub-agent left behind. If no unfinished goal exists, attempt create_goal with the same objective as a fresh loop.Status: closed; if this loop created the goal, mark it complete with update_goal. An inherited goal stays active for the outer workflow. A halt on an unresolved failure leaves Status: active and the goal untouched, so the next invocation resumes the recorded state.$stage SkillRun the $stage skill.
Run the project's full verification gate: every check it defines as a pass/fail condition. The goal is that passing this step means the project's own checks (and CI, where it exists) pass. Build the gate by combining every source below that the project declares (sources 1-3); run the baseline (source 4) only when the project declares none of them:
check, verify, lint, typecheck), Makefile or Taskfile targets, or a combined format+lint script.$find-dead-code.Run the formatter first so later checks see formatted code, then the rest. Fix any failure the tools do not auto-resolve. For test failures, run the $investigate skill to diagnose the root cause, apply the suggested fix, and re-run; if investigation finds no root cause, stop and report with its findings.
Stage all changes made in this step before continuing.
$review-code SkillRun the $review-code skill on the staged changes. The diff command is git diff --cached.
$evaluate-findings SkillRun the $evaluate-findings skill on the results from Step 3.
$apply-findings SkillRun the $apply-findings skill on the evaluated results.
When a fix ships with a regression test, confirm the test fails with the fix reverted, then restore the fix.
Stage the fix before mutating it (git add <file>), so git checkout -- <file> restores it exactly from the index. Stage only the files about to be mutated, and reach for git add -p <file> when one also carries unrelated changes: a broader restore point sweeps in working-tree changes the project may require stay uncommitted.
When the test still passes with the fix reverted, suspect the mutation before the test: confirm it reaches the branch under test and reproduces the original behavior rather than a third one. A test that genuinely cannot be made to fail does not pin the behavior; say so rather than counting it as coverage. When the fixed code combines several signals, also apply the plausible rewrites a maintainer might reach for — reordering the signals, substituting a fallback chain for a conjunction, dropping a term that looks redundant — and confirm each fails at least one test, then restore the fixed code. A rewrite that passes every test while changing behavior on some input means the tests pin the examples rather than the invariant; add the test that distinguishes it. When the fix guards against an unbounded loop or wait, bound the test itself so that reverting the fix fails rather than hangs: cap the iteration count for a loop; enforce a deadline for a wait.
After every mutation in this step, re-run the test and confirm it passes again before reporting the result. A clean git status looks identical whether the fix was restored or deleted.
Stage all changes made in this step before continuing.
$smoke-test SkillRun the $smoke-test skill to produce the smoke test plan.
Capture git status --short, git diff HEAD | git hash-object --stdin, and git symbolic-ref --short -q HEAD before spawning, and record all three outputs in the ledger as Pending smoke-test baseline, replacing any entry already there.
Delegate test execution to a Codex sub-agent with inherited model defaults. Pass the plan and the diff command (git diff --cached) into the sub-agent's context.
Verify the tree: re-run all three commands when the sub-agent returns, including when it terminates early or reports incomplete results. Compare against Pending smoke-test baseline. Delete what the sub-agent created, revert what it modified or staged, and return HEAD to the captured branch, leaving everything that baseline already showed untouched. Clear the entry once the tree matches.
If any test fails, fix the issues and stage the fixes.
$polish-code Skill if ChangedCheck whether any file was edited during Steps 5-6. Any edit counts.
Iteration 1 is the initial run; iteration 2 is the first auto-re-run; and so on. The loop is not capped; it terminates on its own: when a run makes no changes, when a round makes only in-place edits, or when you judge a further re-run pointless.
If changes were made, classify what Steps 5-6 edited:
$polish-code again as a fresh skill invocation. Scope the diff command to only the files modified in Steps 5-6: use git diff --cached -- <file1> <file2> ... as the diff command for $review-code. Smoke test scope remains unchanged (full feature scope, not file-narrowed). If the round contains both structural and in-place edits, treat it as structural and re-run automatically.If changes were made but you judge a re-run unnecessary, output a summary of what changed, where this round's defects lived (in the product, or in the build, CI, and gate scaffolding around it), and your reasoning for stopping, then stop instead of re-running.
Judge convergence by the trend across iterations: when rounds have stopped surfacing defects (wrong behavior, security exposures, broken contracts) and keep surfacing improvements of kinds earlier rounds already applied, a further re-run is pointless even though the edits were structural. A round that surfaces no defects is the termination signal; never add a confirmation round, an extra reviewer, or review steps beyond this skill's own.
Treat reversal as the stronger signal: when a round's accepted findings undo an earlier round's accepted findings on the same lines, the reviewers are trading equally defensible positions rather than converging on one answer. A further re-run is pointless there even though such edits classify as structural. Keep the current round's version of the reversed code, which is as likely to be the better answer as the one it replaced.
When the same class of defect recurs across iterations, stop patching the individual instance and instead encode the root-cause invariant structurally — a shared guard or type, or a regression test that pins the class against the worked failures it must prevent. In the same pass, audit the existing code against the newly encoded invariant and fix every instance it catches, including code written before it existed. Treat recurrence on a new axis of the same invariant as a signal that the invariant is incomplete: widen it to cover the new axis rather than assuming the latest fix failed.
The re-invocation is a full, fresh run of this skill. Every step (1-7) executes with its own task tracking and skill invocations. "Scoped to modified files" only affects the diff command passed to $review-code. It does not affect which steps run or whether skills are invoked. When the classification above sends the run into another iteration, supply that iteration with every rejected and escalated verdict the ledger records, across this run and earlier iterations, as the already-adjudicated list for $review-code, one line each: the finding, its verdict, and the recorded reason. Source it from the ledger rather than from in-context state, which compaction drops.
Then call update_plan to mark this step completed and continue with the next step of the active workflow.
$review-code covers correctness, security, consistency, API usage, coverage, and simplicity across parallel internal reviewers plus peer review. $evaluate-findings is a judgment gate that must run before $apply-findings.| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-10 | fail→pass | 10,457 | 5,445 | -48% | 1 | 1 | 0% | 1,700 | 3,492 | +105% | 0 | 0 | — |
case-01 | fail→fail | 4,784 | 24,666 | +416% | 1 | 1 | 0% | 228 | 3,132 | +1274% | 0 | 0 | — |
case-02 | fail→fail | 9,978 | 35,429 | +255% | 1 | 1 | 0% | 1,391 | 2,780 | +100% | 0 | 0 | — |
case-03 | fail→fail | 3,745 | 6,989 | +87% | 1 | 1 | 0% | 144 | 2,769 | +1823% | 0 | 0 | — |
case-04 | fail→fail | 7,155 | 23,389 | +227% | 1 | 1 | 0% | 1,193 | 3,448 | +189% | 0 | 0 | — |
case-09 | pass→pass | 11,062 | 2,888 | -74% | 1 | 1 | 0% | 1,974 | 3,111 | +58% | 0 | 0 | — |
case-05 | pass→pass | 11,333 | 7,649 | -33% | 1 | 1 | 0% | 1,856 | 3,907 | +111% | 0 | 0 | — |
case-06 | fail→fail | 7,269 | 3,059 | -58% | 1 | 1 | 0% | 1,203 | 3,014 | +151% | 0 | 0 | — |
case-07 | fail→pass | 11,633 | 4,222 | -64% | 1 | 1 | 0% | 1,966 | 3,277 | +67% | 0 | 0 | — |
case-08 | pass→pass | 7,821 | 4,347 | -44% | 1 | 1 | 0% | 1,394 | 3,263 | +134% | 0 | 0 | — |
case-11 | pass→pass | 11,009 | 3,985 | -64% | 1 | 1 | 0% | 1,939 | 3,202 | +65% | 0 | 0 | — |
case-12 | fail→pass | 7,972 | 2,758 | -65% | 1 | 1 | 0% | 1,363 | 3,009 | +121% | 0 | 0 | — |
case-13 | fail→pass | 5,423 | 4,243 | -22% | 1 | 1 | 0% | 963 | 3,315 | +244% | 0 | 0 | — |
case-14 | fail→fail | 4,608 | 2,384 | -48% | 1 | 1 | 0% | 945 | 2,961 | +213% | 0 | 0 | — |
case-15 | pass→pass | 6,166 | 3,296 | -47% | 1 | 1 | 0% | 1,134 | 3,127 | +176% | 0 | 0 | — |
case-16 | pass→pass | 10,402 | 3,120 | -70% | 1 | 1 | 0% | 1,708 | 3,148 | +84% | 0 | 0 | — |
case-17 | fail→pass | 8,759 | 2,949 | -66% | 1 | 1 | 0% | 1,528 | 3,146 | +106% | 0 | 0 | — |
case-18 | fail→pass | 4,564 | 3,893 | -15% | 1 | 1 | 0% | 819 | 3,313 | +305% | 0 | 0 | — |
case-19 | pass→pass | 6,831 | 2,179 | -68% | 1 | 1 | 0% | 1,140 | 2,863 | +151% | 0 | 0 | — |
case-20 | fail→pass | 9,875 | 16,747 | +70% | 1 | 1 | 0% | 1,629 | 3,201 | +97% | 0 | 0 | — |
case-21 | fail→fail | 7,026 | 9,730 | +38% | 1 | 1 | 0% | 1,192 | 3,249 | +173% | 0 | 0 | — |
case-22 | fail→fail | 20,998 | 40,485 | +93% | 1 | 1 | 0% | 3,733 | 9,553 | +156% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 17 counted toward the lift figure. The other 5 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +32 percentage points is the difference between those two pass rates over the 17 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 8/21/2026 | +32% |
Other measured skills in the registry, with their headline benchmark lift.