/powertools:clean-codefrom powertools
Apply Robert C. Martin's Clean Code principles to write and review professional-grade code. Use this skill whenever someone asks about code quality, readability, or maintainability — or when reviewing code that has long functions, unclear names, deep nesting, magic numbers, error codes, null returns, flag arguments, mixed abstraction levels, or tangled tests. Also trigger when someone asks "how do I write cleaner code?", "is this function too long?", "should I add a comment here?", "how should I format this?", "what's wrong with this class?", or "how do I structure error handling?" This skill consolidates the core principles from Chapters 1–13 and the complete Smells & Heuristics catalog from Chapter 17 — the master diagnostic reference with 60+ coded heuristics for identifying and fixing code problems. Domain-agnostic: applies to any language or codebase.
Ships in powertools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill applies Robert C. Martin's Clean Code framework for writing and reviewing professional-quality code. It covers the full range of topics: naming, functions, comments, formatting, objects vs. data structures, error handling, boundaries, tests, and classes.
The master reference is the Smells & Heuristics catalog at the end — a coded, searchable index of every pattern covered in the book. When reviewing code, scan that catalog first.
The core insight: the ratio of time spent reading code to writing it is well over 10:1. Making code easier to read makes it easier to write. The biggest ROI is always readability.
The Boy Scout Rule: Leave the campground cleaner than you found it. Each time you touch code, leave it slightly better — one better name, one extracted function, one deleted comment. LeBlanc's Law warns: Later equals never.
Functions should be small — the ideal is 4–5 lines. Functions should hardly ever be 20 lines. The test: can you read the function in its entirety without scrolling?
A function does one thing if all its steps are one level of abstraction below the function's name. If you can meaningfully extract a section into a function whose name is not merely a restatement of its contents, the function is doing more than one thing.
Mixing levels of abstraction in a function is always confusing. The Stepdown Rule: code reads top to bottom. Each function is followed by the next level of abstraction. Reading a module should feel like reading a narrative.
Switch statements by nature do N things. When you must use one:
A function should either change the state of an object, or return information about it — never
both. if (set("username", "bob")) mixes a command with a query; split them.
Returning error codes forces callers to deal with errors immediately and leads to deeply nested structures. Exceptions allow error handling to be separated from the happy path. Extract try/catch bodies into their own functions. Error handling is one thing — a function that handles errors should do nothing else.
Duplication may be the root of all evil in software. Every time you see it, it represents a missed opportunity for abstraction.
(This skill covers naming at a principles level; see the naming-guidelines skill for the
complete ruleset with violations and corrections.)
accountList for a non-List container is misleading.getActiveAccount() vs getActiveAccounts() vs
getActiveAccountInfo() are indistinguishable to a caller.m_), interface prefixes (I) —
all are noise. Your IDE already knows the type.Customer, WikiPage, Account)postPayment, deletePage, save)fetch, retrieve, or get — not all threeComments are a failure to express in code. The proper use of comments is to compensate for our failure to express ourselves in code. Every comment represents a failure — but some failures are unavoidable.
// --- Actions --- banners are clutter} // end while — extract insteadCode formatting is about communication. The developer's first professional obligation.
a*a + b*b reads the
multiplication as tighter than the additionObjects hide data behind abstractions and expose functions that operate on that data. Adding getters and setters to every field is not encapsulation — it exposes implementation. Choose abstractions that let you manipulate the essence of data without knowing its implementation.
Both are useful. The choice depends on what you expect to change. Don't try to do both — hybrids (half object, half data structure) are the worst of both worlds.
A method f of class C should only call methods of:
C itselfffCTrain wrecks: ctxt.getOptions().getScratchDir().getAbsolutePath() — each call gets
an object returned by the previous call. Split into temporary variables, or restructure.
DTOs and Active Records: pure data structures with public fields are fine for database rows, socket messages, etc. Treat Active Records as data structures — don't add business logic to them; put that in separate objects.
Map (and similar generic containers) expose
far more than you need. Wrap them in a type that exposes only what your code needs.Dirty tests are worse than no tests. Tests enable change — without them, every change is a possible bug. If your tests are messy, your production code becomes rigid. Readability is even more important in tests than in production code.
Each test follows a clear pattern: build the test data, operate on it, check the results. Evolve a domain-specific testing language from the helpers you find yourself extracting.
Minimize asserts per test. One concept per test. When a test fails, you should know immediately what broke.
Public static constants → private static variables → private instance variables → public functions → private utilities called by the public functions above them.
Classes should be small — but measured in responsibilities, not lines. If you can't describe a class in ~25 words without using "if," "and," "or," or "but," it has too many responsibilities.
A class should have one, and only one, reason to change. Many small, focused classes are easier to understand than a few large ones. A system with many small classes has no more moving parts than a system with a few large classes; it just has different organization.
Classes should have a small number of instance variables. Each method should use as many of those variables as possible. When cohesion drops — methods use only a subset of variables — it's a signal to split the class.
Classes should be open for extension but closed for modification. Isolate behavior behind interfaces; add new behavior by adding new types, not by modifying existing code.
Classes should depend on abstractions, not on concrete implementations. This makes classes testable (you can inject test doubles) and loosely coupled.
This is the coded catalog from Chapter 17. When reviewing code, scan this list and note which codes apply. Each code can be cited in review comments.
| Code | Name | Diagnosis |
|---|---|---|
| C1 | Inappropriate Information | Metadata, change history, SPR numbers in comments — belongs in source control |
| C2 | Obsolete Comment | Comment that has grown old, irrelevant, or incorrect — update or delete |
| C3 | Redundant Comment | Comment says what the code already says — delete it |
| C4 | Poorly Written Comment | Unclear grammar, rambling, obvious — if worth writing, write it well |
| C5 | Commented-Out Code | Delete it. Source control has it. It rots. |
| Code | Name | Diagnosis |
|---|---|---|
| E1 | Build Requires More Than One Step | Should be one command to check out and build |
| E2 | Tests Require More Than One Step | Should be one command (or one button) to run all tests |
| Code | Name | Diagnosis |
|---|---|---|
| F1 | Too Many Arguments | More than three is very questionable; avoid with prejudice |
| F2 | Output Arguments | Counterintuitive; mutate the object the method is called on instead |
| F3 | Flag Arguments | Boolean params declare the function does more than one thing |
| F4 | Dead Function | Never called; delete it — source control remembers |
| Code | Name | Diagnosis |
|---|---|---|
| G1 | Multiple Languages in One Source File | Minimize extra languages in a source file |
| G2 | Obvious Behavior Is Unimplemented | Principle of Least Surprise; readers lose trust when expectations fail |
| G3 | Incorrect Behavior at Boundaries | Test every boundary condition — don't rely on intuition |
| G4 | Overridden Safeties | Turning off failing tests, suppressing compiler warnings — don't |
| G5 | Duplication | DRY; every duplicate is a missed abstraction; replace with polymorphism or Template Method |
| G6 | Code at Wrong Level of Abstraction | Lower-level concepts belong in derivatives, not in base classes |
| G7 | Base Classes Depending on Their Derivatives | Base classes should know nothing about their subclasses |
| G8 | Too Much Information | Small interfaces; fewer methods, fewer variables, fewer exposed internals |
| G9 | Dead Code | Code that is never executed; delete it |
| G10 | Vertical Separation | Variables and functions defined far from where they are used |
| G11 | Inconsistency | If you do something a certain way, do all similar things the same way |
| G12 | Clutter | Unused variables, never-called functions, meaningless comments — remove |
| G13 | Artificial Coupling | Don't place a function, constant, or variable in an inconvenient but lazy location |
| G14 | Feature Envy | Method more interested in another class's data than its own — move it |
| G15 | Selector Arguments | Flag/Boolean/enum params that select behavior — split into separate functions |
| G16 | Obscured Intent | Hungarian notation, magic numbers, run-on expressions — make intent visible |
| G17 | Misplaced Responsibility | Put code where the reader expects to find it (follow function names) |
| G18 | Inappropriate Static | If there's any chance the function should be polymorphic, don't make it static |
| G19 | Use Explanatory Variables | Break calculations into intermediate variables with meaningful names |
| G20 | Function Names Should Say What They Do | If you must read the implementation to know what it does, rename it |
| G21 | Understand the Algorithm | Don't leave it "working" with if-statements and flags — refactor until it's obvious |
| G22 | Make Logical Dependencies Physical | Don't assume — ask; dependent module should request what it needs |
| G23 | Prefer Polymorphism to If/Else or Switch/Case | ONE SWITCH rule: at most one switch per type selection |
| G24 | Follow Standard Conventions | Every team; code provides the examples; no separate document needed |
| G25 | Replace Magic Numbers with Named Constants | Any token whose value is not self-describing needs a name |
| G26 | Be Precise | Ambiguities and imprecision are laziness; lock down decisions precisely |
| G27 | Structure over Convention | Enforce decisions with structure (abstract methods) not naming conventions |
| G28 | Encapsulate Conditionals | if (shouldBeDeleted(timer)) not if (timer.hasExpired() && !timer.isRecurrent()) |
| G29 | Avoid Negative Conditionals | if (buffer.shouldCompact()) not if (!buffer.shouldNotCompact()) |
| G30 | Functions Should Do One Thing | Functions with multiple sections doing a series of operations violate this |
| G31 | Hidden Temporal Couplings | Use bucket brigade: each function returns a result the next needs |
| G32 | Don't Be Arbitrary | Have a reason for every structural decision; communicate it in the structure |
| G33 | Encapsulate Boundary Conditions | int nextLevel = level + 1; — don't let +1 and -1 scatter through code |
| G34 | Functions Should Descend Only One Level of Abstraction | Mixing abstraction levels in a function is always confusing |
| G35 | Keep Configurable Data at High Levels | Constants and defaults at the top; pass down rather than bury in low-level functions |
| G36 | Avoid Transitive Navigation | a.doSomething() not a.getB().getC().doSomething() (Law of Demeter / "Shy Code") |
| Code | Name | Diagnosis |
|---|---|---|
| N1 | Choose Descriptive Names | Names are 90% of readability; take the time; re-evaluate as code evolves |
| N2 | Names at Appropriate Abstraction Level | Don't encode implementation details in names; reflect the abstraction |
| N3 | Use Standard Nomenclature | Pattern names (Decorator, Factory), idioms, ubiquitous language |
| N4 | Unambiguous Names | Name should make the function's or variable's purpose unambiguous |
| N5 | Use Long Names for Long Scopes | Short names for tiny scopes; long precise names for long scopes |
| N6 | Avoid Encodings | No Hungarian notation, no m_ prefixes, no vis_ subsystem prefixes |
| N7 | Names Should Describe Side-Effects | Don't hide what a function does more than what its simple name implies |
| Code | Name | Diagnosis |
|---|---|---|
| T1 | Insufficient Tests | Test everything that could possibly break |
| T2 | Use a Coverage Tool | Find untested if and catch branches; coverage tools make gaps visible |
| T3 | Don't Skip Trivial Tests | Their documentary value exceeds the cost to write them |
| T4 | Ignored Test Is a Question about Ambiguity | Comment out or @Ignore with a note explaining the unresolved question |
| T5 | Test Boundary Conditions | We often get the middle of an algorithm right but misjudge the edges |
| T6 | Exhaustively Test Near Bugs | Bugs congregate; when you find one, test the whole function exhaustively |
| T7 | Patterns of Failure Are Revealing | Ordered, complete test cases expose patterns that point to root causes |
| T8 | Test Coverage Patterns Can Be Revealing | Uncovered code gives clues to why failing tests fail |
| T9 | Tests Should Be Fast | Slow tests don't get run; do what you must to keep them fast |
When reviewing any function or class, ask:
this)Based on Robert C. Martin's Clean Code: A Handbook of Agile Software Craftsmanship (2008). The Smells and Heuristics catalog (Chapter 17) consolidates patterns from Martin Fowler's Refactoring (1999), The Pragmatic Programmer (Hunt & Thomas, 2000), Design Patterns (Gamma et al., 1996), and Kent Beck's Smalltalk Best Practice Patterns (1997). The SOLID principles referenced here are from Martin's Agile Software Development: Principles, Patterns, and Practices (2002). Domain-driven design terms draw from Eric Evans' Domain-Driven Design (2003).
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub jordangaston/claude-plugins --plugin powertools79 skills in this plugin
/ai-camera-movementsLibrary of 46 camera movement prompt blocks for AI video generation (Seedance, Kling, Veo, Runway, Higgsfield). Use this skill EVERY time the user needs a camera move for a video prompt, asks "what camera movement should I use", wants a dolly/pan/orbit/zoom/crane/drone/tracking/handheld/whip-pan/FPV/snorricam/tilt-shift/earth-zoom prompt, asks to add camera motion to a shot, wants to compare camera moves for a scene, or says "Run Camera" / "camera move for this shot". Also trigger when building shot lists or video prompts with other skills (ai-filmmaking, seedance-prompt-structure, genhq-seedance-2-prompt-builder) and a camera instruction is needed — this skill supplies the camera block./ai-image-promptsTurn a seed idea into a polished AI image-generation prompt using a 6-part structure: [medium], [subject], [action/pose], [environment], [style/vibe], [technical specs]. Use this skill whenever the user wants a prompt for generating an image with any model — Midjourney, DALL-E, Imagen, Nano Banana, Flux, Stable Diffusion, Freepik, or unnamed — or asks to 'write an image prompt,' 'make a prompt for this idea,' 'improve my image prompt,' or gives a rough visual idea ('a red panda barista,' 'cyberpunk samurai in the rain') and wants it image-ready. Also trigger when the user asks why their image prompts produce weak or inconsistent results. Covers any visual medium: photorealistic, digital painting, 3D render, anime, illustration, pixel art, watercolor, concept art, and more.