code-clarity-and-docs

Use when reviewing code clarity, writing comments, checking documentation accuracy, or auditing AI-facing docs. Triggers on: naming, comments, documentation, README, CLAUDE.md.

211 stars

Best use case

code-clarity-and-docs is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Use when reviewing code clarity, writing comments, checking documentation accuracy, or auditing AI-facing docs. Triggers on: naming, comments, documentation, README, CLAUDE.md.

Teams using code-clarity-and-docs should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/code-clarity-and-docs/SKILL.md --create-dirs "https://raw.githubusercontent.com/ryanthedev/code-foundations/main/skills/code-clarity-and-docs/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/code-clarity-and-docs/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How code-clarity-and-docs Compares

Feature / Agentcode-clarity-and-docsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Use when reviewing code clarity, writing comments, checking documentation accuracy, or auditing AI-facing docs. Triggers on: naming, comments, documentation, README, CLAUDE.md.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Code Clarity and Documentation

## STOP - The Obviousness Rule

**If a code reviewer says your code is not obvious, it is not obvious** -- regardless of how clear it seems to you.

**For new code:** Write comments BEFORE implementation. If the comment is hard to write, fix the design, not the comment.

---

## Comments-First Workflow

For new classes/methods, write comments BEFORE implementation:

```
1. Write class interface comment (what abstraction it provides)
2. Write interface comments for public methods (signatures + comments, empty bodies)
3. Iterate on comments until structure feels right
4. Write instance variable declarations with comments
5. Fill in method bodies, adding implementation comments as needed
6. New methods discovered during implementation: comment before body
7. New variables: comment at same time as declaration
```

**Applies to:** writing from scratch, copy-paste-modify, extending functions (>5 lines), interface-changing refactors, prototype-to-production, test methods, non-trivial lambdas.

**Exempt (but document why):** one-liner utilities with precise names, trivial getters/setters, character-level bug fixes, temp debug code (mark `// TEMP:`).

---

## Comment Types and When to Use Them

| Type | Where | Purpose |
|------|-------|---------|
| **Interface** | Declarations | Define abstraction, usage info -- required for every public entity |
| **Implementation** | Inside methods | Help understand what code does -- optional for simple methods |
| **Cross-Module** | Dependencies | Describe cross-boundary relationships |

### Interface vs Implementation Comments

| Interface Comment | Implementation Comment |
|-------------------|------------------------|
| Describes externally visible behavior | Describes internal workings |
| Defines the abstraction | Helps understand how code works |
| What user needs to use it | What maintainer needs to modify it |
| **Never include implementation details** | Can reference interface concepts |

---

## The "Different Words" Test

**If your comment restates the code, it adds zero value.** Comments must use different words than the entity they describe.

| Bad | Good |
|-----|------|
| `# Gets user` for `getUser()` | `# Fetches user from cache, falling back to DB` |
| `# Process data` | `# Processes data in chunks to stay under memory limit` |
| `i++ // increment i` | Don't comment this at all |

### Comment Anti-Patterns

| Anti-Pattern | Example | Problem |
|--------------|---------|---------|
| Repeat the code | `i++ // increment i` | Zero value |
| State the obvious | `// loop through users` | Noise |
| Stale comment | Comment says X, code does Y | Dangerous |
| TODO forever | `// TODO: fix this` from 2019 | Clutter |
| Commented-out code | Dead code as comment | Confusion |

### Patterns That Add Value

| Pattern | Example |
|---------|---------|
| Explain rationale | `// Use insertion sort: n < 10 always` |
| Warn about non-obvious | `// Must call before X, else crash` |
| Summarize algorithm | `// Binary search on sorted timestamps` |
| Document edge case | `// Empty list returns -1, not null` |
| Reference external | `// Per RFC 7231 section 6.5.4` |

---

## Variable Comment Checklist

For each variable, answer in the comment:

- [ ] What are the units? (seconds? milliseconds? bytes?)
- [ ] Are boundaries inclusive or exclusive?
- [ ] What does null mean, if permitted?
- [ ] Who owns the resource (responsible for freeing/closing)?
- [ ] What invariants always hold?

**Goal:** Comment should be complete enough that readers never need to examine all usage sites.

---

## Naming Principles

### Two Required Properties

| Property | Requirement | Test |
|----------|-------------|------|
| **Precision** | Name clearly conveys what entity refers to | "Can someone seeing this name in isolation guess what it refers to?" |
| **Consistency** | (1) Always use this name for this purpose (2) Never use it for other purposes (3) All instances have same behavior | Check all usages |

### Naming Procedure

```
1. Name Evaluation Test:
   "If someone sees this name without declaration or context,
   how closely can they guess what it refers to?"

2. Precision Check:
   - Could this name refer to multiple things? -> Too vague
   - Does this name imply narrower usage than actual? -> Too specific
   - Target: name matches actual scope exactly

3. Consistency Check:
   - Is this name used everywhere for this purpose?
   - Is this name used ONLY for this purpose?
   - Do all variables with this name behave identically?
```

### Common Naming Mistakes

| Mistake | Example | Fix |
|---------|---------|-----|
| Vague status words | `blinkStatus` | `cursorVisible` |
| Too generic | `getCount()` | `numActiveIndexlets` |
| Too specific | `delete(Range selection)` | `delete(Range range)` if it works on any range |
| Similar names, different things | `socket` vs `sock` | Distinct, descriptive names |
| Type in name | `strName` | Just `name` |
| Class repeated in variable | `File.fileBlock` | `File.block` |

---

## Red Flags (Code Clarity)

| Red Flag | What It Signals |
|----------|-----------------|
| Comment repeats code | Rewrite with different words |
| Hard to describe | Design problem -- fix the design |
| Hard to pick name | Design smell -- entity lacks clean design |
| Vague name (`status`, `flag`, `data`) | Conveys little information |
| Interface describes implementation | Shallow abstraction |
| Implementation contaminates interface | Violates separation of concerns |

---

## README Accuracy Checklist

- [ ] Does README describe current behavior?
- [ ] Are setup instructions still valid?
- [ ] Do examples still work?
- [ ] Are dependencies current with package manifests?
- [ ] Is the feature list accurate?

---

## Changelog Update Checklist

- [ ] Breaking changes documented with migration instructions?
- [ ] New features listed with usage examples?
- [ ] Bug fixes noted with issue references?
- [ ] Version number bumped if needed?

---

## AI Documentation Audit

Check all AI config files that exist in the project:

| File | Tool |
|------|------|
| `CLAUDE.md` | Claude Code |
| `.cursorrules` / `.cursorignore` | Cursor |
| `.github/copilot-instructions.md` | GitHub Copilot |
| `AGENTS.md` | Copilot Workspace |
| `.windsurfrules` | Windsurf |
| `.aider.conf.yml` | Aider |
| `.continue/config.json` | Continue.dev |
| `.clinerules` | Cline |
| `.roomodes` | Roo Code |
| `CONVENTIONS.md` | Various |

- [ ] AI docs reflect current architecture?
- [ ] Agent/skill descriptions accurate?
- [ ] File structure documentation up to date?
- [ ] All AI config files consistent with each other?
- [ ] Version numbers synchronized across docs and manifests?

---

## Severity Guide

| Finding | Severity |
|---------|----------|
| README contradicts actual behavior | CRITICAL |
| API doc says wrong return type | CRITICAL |
| Stale comment causes bug risk | CRITICAL |
| CLAUDE.md describes deleted/renamed files | CRITICAL |
| New public API undocumented | IMPORTANT |
| Breaking change not in changelog | IMPORTANT |
| CLAUDE.md missing new features/agents | IMPORTANT |
| AI doc version mismatch | IMPORTANT |
| Stale TODO from distant past | SUGGESTION |
| Could add clarifying comment | SUGGESTION |
| Minor README improvement | SUGGESTION |

---

## Chain

| After | Next |
|-------|------|
| Comments/naming done | code-clarity-and-docs (CHECKER) |
| Docs verified | Done (pre-commit gate) |

Related Skills

whiteboarding-planning

211
from ryanthedev/code-foundations

Standard/Full planning pipeline for whiteboarding. Steps: discover, classify, explore, detail, save, check, confirm, handoff. Use when dispatched from whiteboarding command for Medium/Complex tasks. Triggers on 'planning pipeline', 'standard track', 'full track'.

welc-legacy-code

211
from ryanthedev/code-foundations

Use when facing untested legacy code, test harness problems, dependency issues, or time pressure. Triggers on: legacy code, no tests, can't test, afraid to change, need to modify untested code.

performance-optimization

211
from ryanthedev/code-foundations

Use when code is too slow, has performance issues, timeouts, OOM errors, high CPU/memory, or doesn't scale. Triggers on: profiler hot spots, latency complaints, needs optimization, critical path analysis.

clarify

211
from ryanthedev/code-foundations

Decompose user intent through structured brainstorming. Detects underspecification, ambiguity, and false premises through hypothesis-driven questioning. Use when a request is unclear, could have multiple valid interpretations, or critical details are missing.

cc-routine-and-class-design

211
from ryanthedev/code-foundations

Use when designing routines or classes, reviewing class interfaces, choosing between inheritance and containment, or evaluating routine cohesion. Also trigger when inheritance is used without LSP verification, or when design issues are present despite passing tests

cc-refactoring-guidance

211
from ryanthedev/code-foundations

Use when modifying existing code, improving structure without changing behavior, or deciding between refactor, rewrite, or fix-first.

cc-quality-practices

211
from ryanthedev/code-foundations

Use when planning QA, choosing review methods, designing tests, or debugging fails. Triggers on: defects found late, tests pass but production bugs, coverage disputes, review ineffective, spending excessive time debugging.

cc-pseudocode-programming

211
from ryanthedev/code-foundations

Use when designing routines, stuck on where to start coding, caught in compile-debug loops, or code works but you don't understand why. Triggers on: starting a new coding task

cc-defensive-programming

211
from ryanthedev/code-foundations

Use when auditing defensive code, designing barricades, choosing assertion vs error handling, or deciding correctness vs robustness strategy. Triggers on: empty catch blocks, missing input validation, assertions with side effects, wrong exception abstraction level, garbage in garbage out mentality, deadline pressure to skip validation, trusted source rationalization.

cc-control-flow-quality

211
from ryanthedev/code-foundations

Use when code has deep nesting (3+ levels), complex conditionals, loop design questions, high cyclomatic complexity (McCabe >10), or callback hell. Symptoms: arrow-shaped code, repeated conditions, confusing loop exits, lengthy if-else chains

ca-architecture-boundaries

211
from ryanthedev/code-foundations

Use when designing system architecture, drawing boundaries between business logic and infrastructure, or when changes touch many unrelated files. Triggers on: architecture design, dependency direction, separating business rules from database/UI/frameworks.

aposd-verifying-correctness

211
from ryanthedev/code-foundations

Use after implementing code. Triggers on: is it done, ready to commit, verify correctness, did I miss anything, pre-commit check.