Clean code

From ariadoss/superskills · View interactive version

Clean code is an AI agent skill from the GitHub repository ariadoss/superskills. Audit → fix → verify the branch diff against KISS, DRY, SOLID, and YAGNI. Finds duplicated logic, units with more than one reason to change, needless abstraction or speculative extensibility, wrong-altitude code, and dead code in the changed files — then applies the smallest safe refactor for each,

How to use this skill

Skill file

/clean-code

Apply the superskills quality standard — KISS, DRY, SOLID, YAGNI — to the

code that changed on this branch, and prove each cleanup with tests. This is the

in-tree counterpart to Claude Code's built-in /simplify: it can be invoked from

inside any session or pipeline (/qa-full Step 3 runs it), and it works the same

in every tool ./setup targets.

The principles are defined once, in ENGINEERING_STANDARDS.md in the

superskills install (a plugin install exposes it at

${CLAUDE_PLUGIN_ROOT}/ENGINEERING_STANDARDS.md). Read its DRY, SOLID,

and YAGNI sections before auditing — this file does not restate them, it

only lists the diff-level signals to look for. Do not expect the file in the

project under review, and do not flag it as missing. KISS is not a separate

section there: it is the standard's "smallest correct change" + YAGNI rules

applied to structure — the simplest design that passes the tests.

Hard rules

issues, or performance problems. If you notice one, record it as an

out-of-scope note for /review / /defense and move on.

modules is itself a YAGNI violation. The one exception: when the diff

duplicates a helper that already exists elsewhere, the fix is to use the

existing helper, which may touch its file.

git checkout -- <files>, which discards everything uncommitted in those

files. So no fix is attempted while unrelated uncommitted work exists

(Step 1.4). Never use git stash as the revert mechanism — it stashes the

whole tree, not one change.

runs under the existing tests; if the code you're restructuring has no test,

write a characterization test first (/tdd), then refactor under green.

needless indirection, not the whole module. Stop when the finding is gone.

responsibilities a unit mixes, the abstraction with one implementation, the

config nobody reads. No "this feels complex."

(e.g. clean-code: DRY — extract parseRange() used by 3 call sites). Never

push.

left as warnings — don't polish indefinitely.

Step 1: Scope and preconditions

  1. Base ref: detect the base the same way /qa-full Step 1 does (`gh repo

view default branch → origin/HEAD → main/master`), unless

$ARGUMENTS names one, then diff against origin/<base> when that ref

exists (fetch it first), else local <base>. When invoked from /qa-full,

use the diff ref and scope it resolved — do not re-detect.

  1. Changed files: git diff --name-only <diff-ref>...HEAD -- <scope paths>

(omit the -- part when no --scope was given) plus any uncommitted

changes to those paths. Keep only source files: skip lockfiles, generated

code, vendored dirs, and pure docs unless docs are the deliverable.

  1. Tests: find the test command (CLAUDE.md, package.json scripts,

Makefile, pyproject.toml) and run it once. **If the suite is red,

stop** — refactoring can't be verified on a red suite. Report and exit.

  1. Clean tree: if git status --porcelain is non-empty, ask the user (via

AskUserQuestion) whether to commit the in-progress work now

(recommended) or stash it before continuing. Do not audit-and-fix on a

dirty tree; a revert in Step 3 would take the user's work with it. (Inside

/qa-full this was already handled in its Step 1 — the tree is clean.)

Step 2: Audit (report-only discovery)

Read every changed file in full. For each principle, apply the definition from

ENGINEERING_STANDARDS.md and hunt for these diff-level signals. Record

findings as PRINCIPLE — file:line — evidence — smallest fix, with severity

HIGH (duplicated logic, a unit doing two jobs that will diverge, dead code

on a live path), MEDIUM (wrong altitude, needless abstraction, speculative

config), or LOW (naming, ordering, minor simplification).

distinctive identifiers, string literals, and regexes — a hit is a duplicate.

Two near-identical branches or helpers within the diff differing by one

argument. A rule or constant pasted where a reference would do (docs and

governance text count). Accepted duplication with no inline reason.

implementation that throws or no-ops where its interface's contract returns;

a parameter object passed to read one field; an interface where callers use

two of eight methods; a unit reaching straight for $HOME, the network, the

clock, a global singleton, or new Concrete() where a seam would make it

testable in isolation. Name both responsibilities when flagging a unit that

has two reasons to change.

implementation; low-level detail inline in a high-level orchestrator, or a

business rule buried in a utility; nested ternaries, reduce-as-control-flow,

or a regex doing a parser's job; a function whose branches exceed what a

reader holds in one pass (split by responsibility, not line count).

subclass, or toggles nothing consumes (Grep for each consumer — a flag

advertised but never read is a finding); unreachable branches, unused

exports/params/imports, commented-out blocks, TODOs for unplanned work;

restructuring in the diff of code that had no reason to change.

Also note (not as findings) any existing helper you found that the diff should

reuse — that becomes the DRY fix.

Step 3: Fix

For each HIGH and MEDIUM finding, and any LOW whose fix is a one-liner:

  1. If the code being restructured has no test that would catch a behavior

change, write a characterization test first and watch it pass.

  1. Apply the smallest safe refactor:

and delete the duplicate).

interface; keep public signatures stable unless the diff introduced them.

move code to its right altitude.

want it back, say so in the commit message rather than leaving it in.

  1. Run the test suite. Green ⇒ commit atomically. Red ⇒ revert **only the

files this fix touched** with git checkout -- <those files> (safe because

the tree was clean before the fix), and record the finding as UNFIXED

with the failing test name.

Do not touch findings outside the diff scope, and do not "improve" the tests

themselves beyond what a refactor needs.

Step 4: Verify + report

  1. Re-run the audit signals on the changed files (now including your fix

commits). Each fixed finding must no longer appear; the fixes must not have

introduced a new duplicate or a new one-use abstraction.

  1. Run the tests that cover the files you changed, by name. Do not run the whole suite: it runs once at the merge gate (suite-stamp.sh ensure). Report that command and its result in the Suite: field. When git config --local superskills.suiteCommand is empty, end with one plain sentence: "No whole-suite gate is set up here. Run the whole suite once before merging, or run suite-stamp.sh init '<command>' so it runs once per tree."
  2. Print:
# clean-code — <branch> @ <YYYY-MM-DD>
Base: <base>  Files audited: N  Suite: <command> → green/red

## Fixed (principle — finding — commit)
1. DRY — src/x.ts:40 duplicated parseRange() from src/util/range.ts — <sha>
- (or) None needed.

## Unfixed / deferred (with reason)
- SOLID — src/y.ts:12 mixes validation + persistence — needs interface change beyond the diff

## Warnings (LOW, left as-is)
- …

## Out of scope (hand to /review or /defense)
- …

Every fix lists a commit SHA; every unfixed finding lists why. No claim without

the re-audit and the fresh suite run behind it.

Anti-patterns (do not do)

subclass — that's trading a DRY smell for a YAGNI violation.

Related commands

it (or /code-review) for bugs, run this for quality.

use them when typing commands yourself. Pipelines and other tools use this

skill because it's invocable everywhere.

untested.

pass, passing it the base and scope it resolved.

clean up here.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.