clean-code
Skill44 starsChanged 7 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.
63 other projects use a version of this.
Adopted by
Most recently taken up by
- superplanehq/superplanetheir own version, first seen Oct 5, 2026
- JeffreyFerreiras/ai-skillstheir own version, first seen Oct 5, 2026
- sbluemin/fleet-harnesstheir own version, first seen Oct 4, 2026
- jd-solanki/krutrimboxtheir own version, first seen Sep 27, 2026
- samirpatil2000/skillstheir own version, first seen Sep 26, 2026
- btseee/clean-code-skillstheir own version, first seen Sep 25, 2026
Used with
Projects with it also use 2d-games, 3d-games 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.
tiendatworkSkill2d-games
2D game development principles. Sprites, tilemaps, physics, camera.
Also in 3 projects that use this
tiendatworkSkill3d-games
3D game development principles. Rendering, shaders, physics, cameras.
Also in 3 projects that use this
MindrallySkillclean-architecture
Guidelines for implementing Clean Architecture patterns in Flutter and Go applications, with emphasis on separation of concerns, dependency rules, and testability.
Also in 7 projects that use this
ratacatSkilldesign-patterns
Use when designing software architecture, refactoring code structure, solving recurring design problems, or when code exhibits symptoms like tight coupling, rigid hierarchies, scattered responsibilities, or difficult-to-test components. Also use when choosing between architectural approaches or reviewing code for structural improvements.
Also in 5 projects that use this
kayamanSkillsolid-principles
Enforces SOLID principles (SRP, OCP, LSP, ISP, DIP) in object-oriented and multi-paradigm code. Use when designing classes and interfaces, evaluating responsibility assignment, reviewing code for coupling issues, applying dependency inversion, refactoring fat interfaces, or checking that subtypes are truly substitutable.
Also in 3 projects that use this
DIL8654Skilllogging-patterns
Keep logs structured, correlated, low-noise, and safe for production support. Use when adding operational logging, reviewing observability, or improving diagnostics in .NET services.
Also in 3 projects that use this
- +6 more from tiendatwork
Other versions63 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 63
- superplanehq/superplane★ 7.7ksame name
- ciembor/agent-rules-books★ 2.9ksame name
- wondelai/skills★ 2.3ksame name
- decebals/claude-code-java★ 747same name
- Mindrally/skills★ 266same name
- xenitV1/claude-code-maestro★ 229same name
- techygarg/lattice★ 197same name
- ratacat/claude-skills★ 56same name
- kumaran-is/claude-code-onboarding★ 36same name
- VoDaiLocz/kilo-kit-mcp★ 27same name
53 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 59 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 59 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.

