clean-code
Skill42 starsChanged 6 months agoMITView on GitHub
Clean Code (Robert C. Martin) guide to produce and challenge code that is readable, durable, simple, and consistent. Covers naming, functions, comments, smells, and refactor heuristics. Complements `/solid` (SOLID principles) and `/anti-overengineering` (YAGNI/KISS). Activate during the REFACTOR phase of the TDD cycle and during implementation self-review.
108 other projects use a version of this.
Adopted by
Most recently taken up by
- sbluemin/fleet-harnesstheir own version, first seen Nov 8, 2026
- nohemi20231/design-skillstheir own version, first seen Nov 8, 2026
- MammadovEshgin/clean-code-skilltheir own version, first seen Nov 8, 2026
- Mahesh-Bishnoi/skillstheir own version, first seen Nov 8, 2026
- Bruno-Cunha-Souza/ValarMindSkillstheir own version, first seen Nov 8, 2026
- kana-consultant/kana-best-practice-engineeringtheir own version, first seen Nov 8, 2026
Used with
Projects with it also use intelligent-routing, nextjs-react-expert and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
SKB3002Skillintelligent-routing
Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.
Also in 5 projects that use this
SKB3002Skillnextjs-react-expert
React and Next.js performance optimization from Vercel Engineering. Use when building React components, optimizing performance, eliminating waterfalls, reducing bundle size, reviewing code for performance issues, or implementing server/client-side optimizations.
Also in 3 projects that use this
xfstudioSkillbash-pro
Master of defensive Bash scripting for production automation, CI/CD
Also in 4 projects that use this
xfstudioSkillcode-refactoring-tech-debt
You are a technical debt expert specializing in identifying, quantifying, and prioritizing technical debt in software projects. Analyze the codebase to uncover debt, assess its impact, and create acti
Also in 4 projects that use this
flying-diceSkillclean-code-review
Multi-agent clean code audit — each principle gets its own agent
Also in 3 projects that use this
goca-seSkillbatch-operations
Apply a change safely across many files — refactors touching more than 5 files, library or API migrations, project-wide renames of symbols/imports/paths, or adding boilerplate to many files. Use when "do it all at once" risks context overflow or silent failures.
Also in 3 projects that use this
- +4 more from xfstudio
Other versions108 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 108
- superplanehq/superplane★ 9.1ksame name
- vudovn/ag-kit★ 8.2ksame name
- vudovn/antigravity-kit★ 8.2ksame name
- Openpanel-dev/openpanel★ 7.3ksame name
- ciembor/agent-rules-books★ 2.8ksame name
- wondelai/skills★ 2.6ksame name
- decebals/claude-code-java★ 763same name
- operately/operately★ 618same name
- liza-mas/liza★ 418same name
- Mindrally/skills★ 275same name
98 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository30 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- agent-creatorSkill
- anti-overengineeringSkill
- audit-docsSkill
- auto-reviewSkill
- architectureSkill
- commitSkill
- create-docSkill
- dddSkill
- discoverySkill
- docs-indexSkill
- e2eSkill
- event-stormingSkill
- implement-featureSkill
- product-managerSkill
- refactor-featureSkill
- refactoring-mikado-stranglerSkill
- review-backSkill
- review-docSkill
- review-followupSkill
- review-frontSkill
- review-fullstackSkill
- securitySkill
- shipSkill
- skill-creatorSkill
- solidSkill
- dashboard-stylingSkill
- tddSkill
- update-docsSkill
- worktreeSkill
The file
We split this skill into the rules it gives an agent
12 rules. 0 are common, 6 are distinctive, and 6 are very specific to this project.
0
Common
Most of the 101 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 60
No encoding: no Hungarian notation (strName, bIsActive), no I prefix for interfaces.
- Distinctive: line 67
Do one thing: if you can extract a sub-function with a name that is not a simple rephrasing of the parent function, the original was doing …
- Distinctive: line 68
One level of abstraction per function: don't mix business orchestration and string manipulation in the same function.
- Distinctive: line 94
Variables close to their usage: no grouped declarations at the top of a function.
- Distinctive: line 123
No dead code: if a function is no longer called, delete it.
- Very specific: line 124
No speculative abstraction (AbstractBaseFactoryProvider) for a single use case.
- Very specific: line 128
One convention per context: if the module uses entitiesById: Record<id, Entity>, the neighbor should too.
- Very specific: line 131
Use case = class implementing UseCase<Input, Output> interface
- Distinctive: line 146
After each GREEN of the Detroit cycle, BEFORE moving to the next RED:
- Very specific: line 194
Cross-module direct import: no direct import from another module's interface-adapters/ or usecases/.
- Very specific: line 196
Magic strings for IDs: prefer branded types (type SessionId = string & { __brand: 'SessionId' }) over raw string.
- Distinctive: line 197
Comment explaining a TODO without ticket: every TODO must point to a spec slug, GitHub issue, or be deleted.
“Common” is measured: kept by at least 6 in 10 of the 101 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clean Code — Refactor & Challenge
Source: Clean Code (Robert C. Martin, 2008) + Clean Coder (2011).
When to activate
- REFACTOR phase of the TDD cycle (after GREEN, before the next RED)
- Implementation self-review (end of
feature-implementerworkflow) - Code review of a PR/MR
- Explicit request for simplification, readability, "challenge this code"
Scope vs neighboring skills
This skill NEVER duplicates the content of /solid or /anti-overengineering. It complements them.
| Concern | Skill to use |
| Responsibility architecture (SRP, OCP, LSP, ISP, DIP) | /solid |
| Should I add a pattern? (YAGNI, KISS, pragmatic architecture) | /anti-overengineering |
| Readability, naming, functions, smells, refactor heuristics | /clean-code (here) |
Once the pattern is decided (/anti-overengineering) and responsibilities are placed (/solid), /clean-code makes intent self-evident.
The 5 pillars
1. SOLID Design — delegated to /solid
Activate /solid for SRP, OCP, LSP, ISP, DIP. Mentioned here only as a structuring reminder: clean code rests on well-placed responsibilities.
2. Readability first
"The ratio of time spent reading to writing code is well over 10:1. We are constantly reading old code as part of the effort to write new code." — Robert C. Martin
Naming (chap. 2)
- Intention-revealing: the name should be enough to understand. If you write a comment to explain, the name is broken.
- OK
daysSinceLastReview— KOd,days,elapsed - OK
filterMergedPullRequests(prs)— KOprocessPrs(prs, true)
- OK
- No disinformation:
accountListmust be aList, otherwiseaccounts. - Perceptible distinction:
getActiveAccount()vsgetActiveAccounts()is a time bomb. PrefergetCurrentAccount()vsgetAllActiveAccounts(). - Searchable: short names only for short scopes (loop index =
indexin a 3-line loop — notieven though short). - No encoding: no Hungarian notation (
strName,bIsActive), noIprefix for interfaces. - Class names = nouns (
ReviewContext,ThreadFetchGateway), method names = verbs (save,fetchByCriteria). - Full words only (project rule,
coding-standards.md): noex,i,ctx,gw. Alwaysexisting,index,context,gateway.
Functions (chap. 3)
- Small: < 20 lines. Ideally < 10. If you have to scroll to read the function, it's too long.
- Do one thing: if you can extract a sub-function with a name that is not a simple rephrasing of the parent function, the original was doing too much.
- One level of abstraction per function: don't mix business orchestration and string manipulation in the same function.
- Few arguments: 0-2 ideal, 3 = challenge it, 4+ = mandatory refactor (parameter object).
- No flag arguments:
render(isPublic: true)→renderPublic()+renderPrivate(). - No hidden side effects: a function named
checkPassword(user, password)that ALSO resets the session is a trap. - Command-Query Separation: either the function modifies state, or it returns info. Not both.
- Prefer exceptions to error codes: for invariants, throw a typed
BusinessRuleViolation. Noreturn nullorreturn { error: ... }smuggled as control flow. Use discriminated unions ({ status: 'success' | 'failed' }) for expected outcomes (cf.coding-standards.md§ Error Typing).
Comments (chap. 4)
"The proper use of comments is to compensate for our failure to express ourself in code." — Martin
- Project rule (
CLAUDE.md): zero comments except if vital. Self-documenting code first. - Acceptable:
- Documented workaround (ticket link, upstream bug link)
- Non-obvious invariant that cannot be encoded in the type system
- Warning about a non-local consequence (e.g. "Modifying here impacts X")
- JSDoc on public APIs (not considered a comment)
- Forbidden:
- Modification journal (
// 2026-03-12: added X) - Closing comments (
} // end if) - Commented-out dead code (
git logis the history) - Positional comments (
// ============ SECTION ============) - Code rephrased in prose (
// fetch the useraboveconst user = ...)
- Modification journal (
Formatting (chap. 5)
- Variables close to their usage: no grouped declarations at the top of a function.
- Newspaper metaphor: top of the file = overview (main exports), bottom = details (private helpers).
- Top-down readability: calling functions above called functions.
3. Sustainable quality
"Leave the campground cleaner than you found it." — Boy Scout Rule
- Boy Scout Rule: each touched file should be slightly cleaner. Renaming a confusing variable adjacent to the diff scope = OK. Out-of-scope structural refactor = NO (cf.
scope-discipline.md). - TDD as quality guard rail: refactor ONLY with green tests. If no tests cover the touched area, write a characterization test before.
- Code smells (Martin, chap. 17) — refactor checklist:
| Smell | Description | Refactor |
| G5 Duplication | Same logic 3+ times | Extract a named function |
| G14 Feature Envy | Method manipulates more attributes of another class than its own | Move the method |
| G15 Selector Arguments | Booleans/enums that choose a behavior | Split into multiple functions |
| G20 Function Names Should Say What They Do | Must read the body to know | Rename |
| G23 Prefer Polymorphism to If/Else Chains | Switch on a type | Polymorphism or mapping object |
| G28 Encapsulate Conditionals | if (a && !b && c.isExpired()) | Extract as if (shouldRemove(x)) |
| G30 One Thing | "This function does X and Y" | Split |
| G34 One Level of Abstraction | Mix orchestration + detail | Extract the detail |
| G35 Magic Numbers | if (count > 7) | Named constant MAX_RETRIES |
4. Simplicity
- Delegated to
/anti-overengineering: YAGNI, KISS, do not anticipate hypothetical business. - Clean Code side-effects:
- No "just in case" parameters. A function has only the parameters it needs now.
- No dead code: if a function is no longer called, delete it.
git logis the history. - No speculative abstraction (
AbstractBaseFactoryProvider) for a single use case.
5. Consistency
- One convention per context: if the module uses
entitiesById: Record<id, Entity>, the neighbor should too. No mixingMap<id, Entity>in the same Bounded Context. - Project patterns to respect (cf.
coding-standards.md):- Gateway = interface (port) in
entities/+ impl (adapter) ininterface-adapters/gateways/ - Use case = class implementing
UseCase<Input, Output>interface - Controller = transforms inbound events into use case calls, no business logic
- Presenter = pure function
(domainData) => viewModel - View = Humble Object (zero logic, render only)
- Gateway = interface (port) in
- Factory usage: factories in
src/tests/factories/are mandatory for test data. Never hardcoded. - Naming patterns (project):
- Suffixes:
.usecase.ts,.gateway.ts,.presenter.ts,.factory.ts,.stub.ts,.guard.ts,.schema.ts,.valueObject.ts - Gateway impls:
<domain>.<platform>.<transport?>.gateway.ts(e.g.threadFetch.gitlab.gateway.ts) - Stubs:
<gateway>.stub.ts(test doubles), located insrc/tests/stubs/ - Imports:
@/alias +.jsextension MANDATORY (no relative paths, no barrelindex.ts)
- Suffixes:
Application workflow — REFACTOR phase (TDD cycle)
After each GREEN of the Detroit cycle, BEFORE moving to the next RED:
- Re-read the diff (not the full file, just what was just written).
- Pass 1 — Naming: does each new identifier reveal intent?
- Pass 2 — Functions: size, arguments, abstraction level.
- Pass 3 — Smells G5/G14/G15/G23: duplication, feature envy, flag args, switch.
- Pass 4 — Consistency: style aligned with the neighboring module?
- Re-run tests: a refactor without green tests is a future bug, not a refactor.
Self-review checklist
- Naming: zero abbreviation, intention-revealing, distinguishable, no
Iprefix - Functions: < 20 lines, 0-2 args, do one thing, no boolean flag
- Comments: none, except workaround/non-obvious invariant
- Format: declarations near usage, top-down readability
- Smells: no duplication 3+, no switch on type, no selector arg
- Consistency: project patterns (gateway/usecase/presenter/view) respected
- Tests: still green after each refactor pass
- Boy scout: the diff leaves the file at least as clean
- Imports:
@/alias +.jsextension, no relative paths, no barrels
How to challenge a PR or a proposal
Questions to ask the author (or yourself):
| Question | If the answer is… | Action |
| "What does this function do?" | contains "and" | Split |
| "Why this name?" | "because it contains X" | Rename to X |
| "Why this boolean parameter?" | "it changes what it does" | Split into 2 functions |
| "What is this comment for?" | "explain what the code does" | Delete + rename |
| "Could you delete it?" | "yes but maybe later…" | Delete now |
| "Why 3 abstraction levels here?" | "in case we extend" | YAGNI → activate /anti-overengineering |
ReviewFlow-specific heuristics
Recurring smells observed in this codebase, to challenge during refactor:
- God Use Case: a use case > 80 lines or with 5+ dependencies → split into sub-use-cases or extract collaborators (cf.
clean-architecture). - Floating Promise: any async call must be
await-ed,return-ed, or explicitlyvoid. Pino logger ignores rejections silently. - Business logic in Controllers: the controller transforms only. Any branching on domain state → move to a use case.
- Type assertions: zero
as,as unknown as T,!non-null assertion. If needed, the upstream typing is broken — fix it with a Zod guard or type narrowing. - Cross-module direct import: no direct import from another module's
interface-adapters/orusecases/. Cross only throughentities/contracts. - Undefined leakage:
undefinedis banned in domain types. Usenullfor intentional absence. Catch at module boundaries with Zod. - Magic strings for IDs: prefer branded types (
type SessionId = string & { __brand: 'SessionId' }) over rawstring. - Comment explaining a TODO without ticket: every TODO must point to a spec slug, GitHub issue, or be deleted.
<!-- ENRICH: add recurring smells observed during reviews. Format: "Short name — symptom — refactor". -->References
- Clean Code — Robert C. Martin (2008), chap. 2 (Naming), 3 (Functions), 4 (Comments), 5 (Formatting), 17 (Smells).
- Clean Coder — Robert C. Martin (2011), chap. on TDD discipline and the courage to refactor.
- Refactoring (2nd ed.) — Martin Fowler (2018), catalog of named refactorings.
- Neighboring skills:
/solid,/anti-overengineering,/refactoring,/tdd,/clean-architecture. - Project rules:
.claude/rules/coding-standards.md,.claude/rules/scope-discipline.md,.claude/rules/anti-hallucination.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

