From clean-code-skills
Use when writing, editing, reviewing, testing, or refactoring code in any language or framework where readability, maintainability, naming, functions, tests, boundaries, error handling, concurrency, security, or code-smell prevention matter.
How this skill is triggered — by the user, by Claude, or both
Slash command
/clean-code-skills:clean-codeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Clean code is code that makes its intent, behavior, boundaries, and failure modes easy for the next maintainer to understand and safely change.
Clean code is code that makes its intent, behavior, boundaries, and failure modes easy for the next maintainer to understand and safely change.
This skill is language-agnostic. It does not mean "write Java everywhere" or "add object-oriented patterns everywhere." It means adapt clean-code principles to the project's language, framework, runtime, and local style.
For chapter-by-chapter depth, use references/chapter-map.md. It maps the full 17-chapter clean-code structure, concurrency appendix, legacy refactoring appendix, and heuristic cross-references into agent checklists.
Use this skill for:
Use a lighter version for trivial edits, but still avoid unrelated changes.
Before editing, identify:
Ask a question only when ambiguity changes the implementation. Otherwise state the assumption and proceed.
Inspect the nearby code before changing it:
Local consistency beats generic preference.
Every changed line should trace to the request or to cleanup caused by the request.
Do:
Do not:
Match verification to risk:
If verification cannot be run, say what was not run and why.
Before completion, scan for:
These principles summarize the working core. When a task needs deeper coverage, cross-check the matching chapter in references/chapter-map.md.
Names should reveal intent without requiring mental decoding.
Use:
Avoid:
data, manager, helper, util, info, or result when a domain name existsA function should have one reason to change and one level of abstraction.
Prefer:
Avoid:
Good comments explain why the code must be this way.
Keep comments for:
Remove or avoid comments that:
Formatting is part of communication.
Choose the shape that makes invariants clear.
Errors are part of the design, not a cleanup afterthought.
Do:
Do not:
Boundaries are where bugs multiply: external APIs, databases, file systems, clocks, queues, UI events, network calls, subprocesses, and generated code.
Tests should make behavior easy to understand and safe to change.
Prefer tests that:
Avoid:
Concurrent code must make ownership and ordering visible.
Check:
Prefer immutability, message passing, transactions, actor-like isolation, or language-native concurrency guarantees when idiomatic.
Security-sensitive code should be readable enough to audit.
Clean code is not slow code; it is code whose cost is understandable.
When you see a smell, decide whether it is in scope.
Fix now only if it blocks the requested change, creates immediate risk, or was introduced by your work. Otherwise mention it separately.
Common smells:
| Smell | Look For | Usual Response |
|---|---|---|
| Long function | mixed abstraction levels, many branches | extract named steps if touching the area |
| Duplicate knowledge | same rule in multiple places | centralize the rule when behavior is changing |
| Primitive obsession | repeated loose strings, numbers, maps | introduce a type only when it protects a real invariant |
| Boolean flag argument | one function doing two jobs | split functions or name modes clearly |
| Shotgun surgery | one concept changed in many files | find the missing boundary |
| Feature envy | code reaching into another module's internals | move behavior or expose a clearer API |
| Hidden temporal coupling | calls must happen in secret order | make state transitions explicit |
| Global mutable state | tests order-dependent, hidden inputs | inject dependencies or isolate state |
| Broad catch | failures disappear | handle, wrap, or propagate with context |
| Magic values | unexplained numbers or strings | name constants when they express domain meaning |
Before applying a rule, adapt it to the ecosystem. Read references/framework-map.md when working in an unfamiliar language or stack.
Examples:
Stop and reassess when you think:
| Rationalization | Reality |
|---|---|
| "I will clean this up while I am here." | That is unrelated work unless the task needs it. |
| "A framework will make this cleaner." | A dependency is a cost; prove the need. |
| "This abstraction will help later." | Later requirements can pay for later abstraction. |
| "The code is bad, so a rewrite is cleaner." | Rewrites need explicit scope, tests, and migration risk control. |
| "There are no tests, so verification is impossible." | Use the best available check and report remaining risk. |
| "Comments make it understandable." | Prefer clearer names and structure; comment only the why. |
| "Clean code means following this skill over local style." | Local, idiomatic style wins unless it is unsafe or broken. |
Before saying the work is complete, confirm:
For reviews, use references/review-checklist.md for a finding-first checklist.
Provides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub btseee/clean-code-skills --plugin clean-code-skills