skills/clean-code/SKILL.md
Audit code against the bbv Clean Code Cheat Sheet and write CLEAN_CODE_AUDIT.md with findings plus a priority-phased plan. User-invoked: use when the user runs /clean-code or requests a clean-code audit. Don't use for general coding, bug-fixing, or PR review.
npx skillsauth add luongnv89/skills clean-codeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Audit code against the bbv Clean Code Cheat Sheet (Urs Enzler, V2.2) — Clean Code principles plus Clean ATDD/TDD practices — then deliver a findings report and a phased, task-level implementation plan ordered by priority.
This skill is user-invoked only. Run it only when the user explicitly:
/clean-code, orDo not auto-trigger on general coding, bug-fixing, feature work, performance tuning, or ordinary PR review — those belong to code-review, code-optimizer, or test-coverage. If a request is ambiguous (plain "review this code"), assume the user wants code-review and ask before running this audit.
CLEAN_CODE_AUDIT.md (always), written to the repo root, containing:
file:line and a principle/smell label.file:line, the principle it fixes, an effort estimate, and an acceptance check.Optional CLEAN_CODE_AUDIT.html — a single self-contained, offline-safe visual report (dark-IDE theme: metric tiles, a severity donut, effort-by-phase bars, collapsible findings, and an interactive phased plan with progress tracking). Offer it after writing the .md; build it from references/report-template.html following references/html-report-guide.md. Same data as the .md, visual form — keep counts consistent between the two.
This skill does not edit source code. It audits and plans; a human (or a follow-up skill like code-review/test-coverage) executes the tasks.
This skill writes CLEAN_CODE_AUDIT.md into the repository, so sync the current branch with remote before writing:
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin
git pull --rebase origin "$branch"
If the working tree is not clean, stash first, sync, then restore:
git stash push -u -m "pre-sync"
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin && git pull --rebase origin "$branch"
git stash pop
If origin is missing, pull is unavailable, or rebase/stash conflicts occur, stop and ask the user before continuing. If the target is not a git repo at all, note that and write the report anyway.
CLEAN_CODE_AUDIT.md and verify against Acceptance Criteria (Phase 4).Determine what to audit and how deep:
git diff --name-only). Default when the user points at something.main, index, app), core business logic, then the rest.git log), and confirm before proceeding. Record the chosen subset in the report header.Detect the primary language(s) so checks are idiomatic — do not flag a Python idiom as a smell in JavaScript, or vice versa.
Read both checklist references and apply them to the in-scope code. To respect the agent's context budget, load only the reference you need when you need it; don't hold both in context if the scope is one-sided.
references/clean-code-checklist.md: smells, class design (SOLID), package cohesion/coupling, design principles, dependencies, naming, methods, source structure, conditionals, maintainability killers, exception handling.references/tdd-checklist.md: kinds of tests, design for testability, unit-test principles, test smells, TDD process smells, red/green patterns, ATDD, the test pyramid, and CI practices.For each issue found, capture: the principle/smell name, the exact file:line, a one-line description of the violation, and a proposed fix direction (what clean-code pattern resolves it).
Use the Severity Levels table below to classify each finding as you go.
(file, line, principle).Convert findings into actionable tasks, grouped into priority phases. Phasing is by severity — see the Severity Levels table below for the Critical/Major/Minor definitions and their phase mapping.
Each task MUST have: a stable ID (1.1, 1.2, 2.1…), a short title, the target file:line(s), the principle/smell it addresses, an effort estimate (e.g. ~15m, ~2h, ~1d), dependencies (other task IDs that must come first, or none), and an acceptance check (how to confirm the task is done).
Order tasks within a phase so that enabling refactors (extract method, introduce abstraction) precede the changes that depend on them.
Write CLEAN_CODE_AUDIT.md (format below). Then verify it against the Acceptance Criteria. Emit the Step Completion Report.
Then offer the optional HTML report: "Want a visual CLEAN_CODE_AUDIT.html too?" If yes, build it from references/report-template.html per references/html-report-guide.md — fill every {{placeholder}}, expand the REPEAT blocks, and confirm zero {{ tokens remain and counts match the .md.
| Level | Meaning | Phase | | ------------ | --------------------------------------------------------------- | ------- | | Critical | Bugs, security risks, broken core principles, risky-untested | Phase 1 | | Major | Code smells, high coupling, maintainability blockers, test smells | Phase 2 | | Minor | Naming, small conditionals, dead code, style | Phase 3 | | Info | Suggestions/alternatives; not scheduled into a phase | — |
Write CLEAN_CODE_AUDIT.md with this structure:
# Clean Code Audit
**Date**: YYYY-MM-DD
**Scope**: [files/dirs or "Full audit (subset: …)"]
**Files Audited**: N
**Source standard**: bbv Clean Code Cheat Sheet V2.2
## Summary
| Severity | Count |
| -------- | ----- |
| Critical | X |
| Major | X |
| Minor | X |
| Info | X |
## Findings
### Critical
#### [Principle/Smell]: Short title
**File**: `path/to/file.ext:42`
**Principle**: [e.g. Single Responsibility Principle]
One-line description of the violation.
**Fix direction**: [which clean-code pattern resolves it]
```language
// optional: minimal illustrative snippet
```
### Major
…
### Minor
…
### Info
…
## Implementation Plan
### Phase 1 — Critical (do first)
- [ ] **1.1 — [title]**
- File: `path/to/file.ext:42`
- Principle: [name]
- Effort: ~2h
- Depends on: none
- Acceptance: [how to confirm done]
- [ ] **1.2 — [title]**
- …
### Phase 2 — Major
- [ ] **2.1 — [title]**
- …
### Phase 3 — Minor
- [ ] **3.1 — [title]**
- …
## Notes
- [Cross-file patterns, sampling notes, excluded files, language-specific caveats]
For a finding, the report should read like this:
#### [Single Responsibility Principle]: UserService does too much
**File**: `src/user_service.py:1`
**Principle**: Single Responsibility Principle (Class Design)
`UserService` (312 lines) handles persistence, validation, and email — three reasons to change.
**Fix direction**: Extract persistence into `UserRepository` and email into `Notifier`; keep only orchestration here.
And the matching plan task:
- [ ] **1.1 — Split UserService into focused classes**
- File: `src/user_service.py:1`
- Principle: Single Responsibility Principle
- Effort: ~3h
- Depends on: none
- Acceptance: `UserService` ≤100 lines; persistence and email live in their own classes; tests pass.
A run passes when all are true:
CLEAN_CODE_AUDIT.md exists at the repo root, first heading # Clean Code Audit.## Summary table with Critical/Major/Minor/Info rows is present and matches the findings count.path/to/file.ext:line and a named principle/smell from the cheat sheet.## Implementation Plan exists with Phase 1/2/3 sections; each task has ID, file:line, principle, effort, dependencies, and acceptance check.CLEAN_CODE_AUDIT.html has no remaining {{ placeholder tokens, and its severity counts match the .md Summary table.dist/, *.min.js, lockfiles): exclude and note them in the report header.## Notes.<<<<<<<, =======, >>>>>>>) in source: surface as a Critical finding; never silently ignore.After each major phase, output a status report:
◆ [Step Name] ([step N of M] — [context])
··································································
[Check 1]: √ pass
[Check 2]: √ pass (note if relevant)
[Check 3]: × fail — [reason]
[Criteria]: √ N/M met
____________________________
Result: PASS | FAIL | PARTIAL
Use √ for pass, × for fail, — for context. Skill-specific checks per phase:
Scope determined, Language(s) detected, Size guard checkedClean Code checks run, TDD/ATDD checks run, Findings captured with file:lineDeduplicated, Cross-file patterns surfaced, Severity assignedTasks created, Phased by severity, Each task has acceptance checkCLEAN_CODE_AUDIT.md written, Acceptance criteria met, No source editedtools
Run Herdr loops for one open GitHub issue (resolve→review→fix) or an existing PR (review→lazy fixer) until CLEAN. Don't use for plain resolution without review, review-only/no-fix requests, backlog automation, or merging.
tools
Manage AI agent fleets in Herdr: split root + sub-agents into one tab as a tiled grid, message/wait/read via herdr CLI, steer any pane. Use for Herdr multi-agent fleets. Don't use for tmux, screen, or non-Herdr terminals.
development
Generate or update docs to match the code, citing each claim to path:line and asking on ambiguity; runbook docs also get a check-only validation script. Don't use for API-reference autogen (JSDoc/Sphinx), landing pages, or CLAUDE.md/AGENTS.md.
testing
Generate a diagram and route to the right engine — draw.io XML (precise, editable, C4, swimlanes) or Excalidraw JSON (hand-drawn, sketch, wireframes). One entry for flowcharts, architecture, ER, sequence, mind maps. Don't use for Mermaid or slides.