clean-code

ratacat/claude-skills · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/ratacat/claude-skills --skill clean-code
0 commentsdiscussion
summary

Clean code reads like well-written prose. Every name reveals intent. Every function tells a story. Every class has a single purpose. The goal isn't just working code—it's code that others can understand quickly, modify safely, and extend confidently.

skill.md

Clean Code

Overview

Clean code reads like well-written prose. Every name reveals intent. Every function tells a story. Every class has a single purpose. The goal isn't just working code—it's code that others can understand quickly, modify safely, and extend confidently.

"Clean code always looks like it was written by someone who cares." — Michael Feathers

"You know you are working on clean code when each routine turns out to be pretty much what you expected." — Ward Cunningham

The Boy Scout Rule: Leave the code cleaner than you found it. Every commit should improve quality, even if just slightly. Small improvements compound.

Chapter References

This skill provides an overview with quick references. For detailed guidance with examples, see the chapter files:

  • chapters/names.md - Meaningful Names (intention-revealing, searchable, pronounceable)
  • chapters/functions.md - Functions (small, do one thing, few arguments)
  • chapters/comments.md - Comments (why to avoid, what's acceptable)
  • chapters/objects-and-data.md - Objects and Data Structures (Law of Demeter, DTOs)
  • chapters/error-handling.md - Error Handling (exceptions, null handling, Special Case Pattern)
  • chapters/tests.md - Unit Tests (TDD, F.I.R.S.T., clean tests)
  • chapters/classes.md - Classes (SRP, cohesion, OCP, DIP)
  • smells-and-heuristics.md - Complete code smells reference (66 smells with explanations)

Quick Reference: Names

Names should reveal intent and be searchable.

Rule Bad Good
Reveal intent d elapsedTimeInDays
Avoid disinformation accountList (not a List) accounts
Make distinctions a1, a2 source, destination
Pronounceable genymdhms generationTimestamp
Searchable 7 MAX_CLASSES_PER_STUDENT
Classes = nouns Process Customer, Account
Methods = verbs data postPayment(), save()

Avoid: Manager, Processor, Data, Info in class names—they hint at unclear responsibilities.

Key insight: If you need a comment to explain what a variable is, rename it instead.

Quick Reference: Functions

Size and Scope

  • Ideal: 4-10 lines, rarely over 20
  • Indent level: Never more than one or two
  • Do one thing — if you can extract another function with a non-restating name, it's doing too much

Arguments

Count Guidance
0 Best
1 Good
2 Acceptable
3+ Avoid—wrap in object

Flag arguments (booleans) are ugly. They proclaim the function does two things. Split it:

# Bad
def render(is_suite: bool): ...

# Good
def render_for_suite(): ...
def render_for_single_test(): ...

Key Rules

  • Command Query Separation: Do something OR answer something, not both
  • No side effects: If checkPassword() also initializes a session, it lies
  • Prefer exceptions to error codes: Separates happy path from error handling
  • Extract try/catch blocks: Error handling is one thing

Quick Reference: Comments

Comments are, at best, a necessary evil. The proper use of comments is to compensate for our failure to express ourselves in code.

Delete These Comments

  • Redundant — restating what code says
  • Journal/changelog — use git
  • Commented-out code — an abomination, git remembers
  • Noise// default constructor, // increment i
  • Closing brace} // end if means too much nesting

Acceptable Comments

  • Legal notices
  • Explanation of intent (why, not what)
  • Warning of consequences (// takes 30 minutes)
  • TODO (but clean them up)
  • Clarifying external library behavior

The Rule: When you feel the urge to comment, first try to refactor the code so the comment would be unnecessary.

Quick Reference: Error Handling

Error handling is important, but if it obscures logic, it's wrong.

Rule Details
Use exceptions over return codes Separates algorithm from error handling
Provide context Include operation that failed and type of failure
Wrap third-party APIs Minimizes dependencies, enables mocking
Use Special Case Pattern Return object that handles special case (empty list, default values)
Don't return null Creates work, invites NullPointerException
Don't pass null Worse than returning null—forbid it by default
# Bad - null checks everywhere
if employees is not None:
    for e in employees:
        total += e.pay

# Good - return empty collection instead of null
for e in get_employees():  # Returns [] if none
    total += e.pay

Quick Reference: Classes

Single Responsibility Principle (SRP)

A class should have one, and only one, reason to change.

Tests:

  • Can you derive a concise name? (Avoid Manager, Processor, Super)
  • Can you describe it in 25 words without "if," "and," "or," "but"?

Cohesion

Methods should use the class's instance variables. When methods cluster around certain variables but not others, the class should be split.

Open-Closed Principle (OCP)

Classes should be open for extension but closed for modification. Add new behavior via subclassing, not modifying existing code.

Dependency Inversion Principle (DIP)

Depend on abstractions, not concrete details. Inject dependencies for testability.

# Bad - can't test without network
class Portfolio:
    def __init__(self):
        self.exchange = TokyoStockExchange()

# Good - injectable, testable
class Portfolio:
    def __init__(self, exchange: StockExchange):
        self.exchange = exchange

Quick Reference: Tests

The Three Laws of TDD

  1. Don't write production code until you have a failing test
  2. Don't write more test than sufficient to fail
  3. Don't write more production code than sufficient to pass

F.I.R.S.T. Principles

  • Fast — Run quickly so you run them often
  • Independent — Don't depend on each other
  • Repeatable — Same result in any environment
  • Self-Validating — Boolean output (pass/fail)
  • Timely — Written just before production code

Clean Tests

  • Readability is paramount
  • Use BUILD-OPERATE-CHECK pattern
  • Create domain-specific testing language
  • One concept per test (not necessarily one assert)

Warning: Test code is just as important as production code. If you let tests rot, your code will rot too.

Objects vs Data Structures

Concept Hides Exposes Easy to add...
Objects Data Functions New types
Data Structures Nothing Data New functions

The idea that everything is an object is a myth. Sometimes you want simple data structures with procedures operating on them.

Law of Demeter

A method should only call methods of:

  • The class itself
  • Objects it creates
  • Objects passed as arguments
  • Objects held in instance variables

Don't call methods on objects returned by allowed functions (train wrecks):

# Bad
output_dir = ctxt.get_options().get_scratch_dir().get_absolute_path()

# Good - tell the object to do the work
bos = ctxt.create_scratch_file_stream(class_file_name)

The Most Critical Smells

From Chapter 17's comprehensive list, these are the most important:

G5: Duplication

The root of all evil in software. Every duplication is a missed abstraction opportunity:

  • Identical code → extract to function
  • Repeated switch/if-else → polymorphism
  • Similar algorithms → Template Method or Strategy pattern

G30: Functions Should Do One Thing

If you can extract another function from it, the original was doing more than one thing.

N1: Choose Descriptive Names

Names are 90% of what makes code readable. Take time to choose wisely.

F1: Too Many Arguments

Zero is best, then one, two, three. More requires justification.

F3: Flag Arguments

Boolean parameters mean the function does two things. Split it.

G9: Dead Code

Code that isn't executed. Delete it—version control remembers.

G11: Inconsistency

If you do something one way, do all similar things the same way.

C5: Commented-Out Code

An abomination. Delete it immediately.

The Craft

"Writing clean code requires the disciplined use of a myriad little techniques applied through a painstakingly acquired sense of 'cleanliness.' The code-sense is the key."

Clean code isn't written by following rules mechanically. It comes from values that drive disciplines—caring about craft, respecting readers of your code, and taking pride in professional work.

How do you write clean code? First drafts are clumsy—long functions, nested loops, arbitrary names, duplication. You refine: break out functions, change names, eliminate duplication, shrink methods. Nobody writes clean code from the start.

Getting software to work and making it clean are different activities. Most of us have limited room in our heads, so we focus on getting code to work first. The problem is that too many of us think we are done once the program works. We fail to switch to organization and cleanliness. We move on to the next problem rather than going back and breaking overstuffed classes into decoupled units.

Don't. Go back. Clean it up. Leave it better than you found it.

how to use clean-code

How to use clean-code on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add clean-code
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/ratacat/claude-skills --skill clean-code

The skills CLI fetches clean-code from GitHub repository ratacat/claude-skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/clean-code

Reload or restart Cursor to activate clean-code. Access the skill through slash commands (e.g., /clean-code) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

User Story & Requirements Generation

Create detailed user stories, acceptance criteria, and feature specs

Example

Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios

Reduce spec writing time by 50%, ensure comprehensive coverage

Competitive Analysis

Research competitors, compare features, identify gaps

Example

Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities

Complete competitive research in 2 hours instead of 2 days

Roadmap Prioritization

Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs

Example

Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale

Make data-driven prioritization decisions faster

Stakeholder Communication

Draft PRDs, status updates, and stakeholder presentations

Example

Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement

Save 3-5 hours/week on communication overhead

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client
  • Access to product documentation and roadmap tools (Jira, Notion, etc.)
  • Understanding of product management frameworks (RICE, Jobs-to-be-Done, etc.)
  • Stakeholder contact information and communication channels

Time Estimate

30-60 minutes to see productivity improvements

Installation Steps

  1. 1.Install product management skill
  2. 2.Start with user story generation for known feature
  3. 3.Progress to competitive analysis: research 2-3 competitors
  4. 4.Use for roadmap prioritization: apply RICE/ICE scoring
  5. 5.Draft stakeholder communications and refine based on feedback
  6. 6.Build template library for recurring PM tasks
  7. 7.Share effective prompts with product team

Common Pitfalls

  • Not validating competitive research—verify facts before sharing
  • Accepting user stories without involving engineering team
  • Over-relying on frameworks without qualitative judgment
  • Not customizing outputs to company culture and communication style
  • Skipping stakeholder validation of generated requirements

Best Practices

✓ Do

  • +Validate research and competitive analysis with real data
  • +Collaborate with engineering when generating technical requirements
  • +Customize frameworks and templates to your company context
  • +Use skill for first drafts, refine with stakeholder input
  • +Document successful prompt patterns for PM tasks
  • +Combine AI efficiency with human judgment and intuition

✗ Don't

  • Don't publish competitive analysis without fact-checking
  • Don't finalize user stories without engineering review
  • Don't make prioritization decisions solely on AI scoring
  • Don't skip customer validation of generated requirements
  • Don't ignore company-specific context and culture

💡 Pro Tips

  • Provide context: company goals, constraints, customer feedback
  • Ask for alternatives: 'Show 3 ways to prioritize this roadmap'
  • Request stakeholder-specific formatting: 'Executive summary vs. engineering spec'
  • Use skill for 70% generation + 30% customization to company needs

When to Use This

✓ Use When

Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work.

✗ Avoid When

Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed.

Learning Path

  1. 1Basic: user stories, feature specs, status updates
  2. 2Intermediate: competitive analysis, prioritization frameworks, PRDs
  3. 3Advanced: product strategy, go-to-market planning, OKR setting
  4. 4Expert: product vision, market positioning, business model innovation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.734 reviews
  • Ira Robinson· Dec 24, 2024

    I recommend clean-code for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Chaitanya Patil· Dec 20, 2024

    clean-code fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Luis Gonzalez· Dec 20, 2024

    Registry listing for clean-code matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Alexander Rahman· Dec 16, 2024

    clean-code fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Min Sanchez· Nov 15, 2024

    clean-code has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Ren Li· Nov 15, 2024

    clean-code reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Piyush G· Nov 11, 2024

    clean-code is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Min Ramirez· Nov 11, 2024

    Useful defaults in clean-code — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Alexander Bhatia· Nov 7, 2024

    clean-code is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Ava Abebe· Oct 26, 2024

    Keeps context tight: clean-code is the kind of skill you can hand to a new teammate without a long onboarding doc.

showing 1-10 of 34

1 / 4