skills/code-clarity-and-docs/SKILL.md
--- name: code-clarity-and-docs description: Use when reviewing code clarity, writing comments, checking documentation accuracy, or auditing AI-facing docs. Triggers on: naming, comments, documentation, README, CLAUDE.md. --- # 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, f
npx skillsauth add ryanthedev/code-foundations skills/code-clarity-and-docsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
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:).
| 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 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 |
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 |
| 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 |
| 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 |
For each variable, answer in the comment:
Goal: Comment should be complete enough that readers never need to examine all usage sites.
| 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 |
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?
| 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 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 |
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 |
| 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 |
| After | Next | |-------|------| | Comments/naming done | code-clarity-and-docs (CHECKER) | | Docs verified | Done (pre-commit gate) |
testing
Standard/Full planning pipeline for plan command. Steps: discover, classify, explore, detail, save, check, confirm, handoff. Use when dispatched from plan command for Medium/Complex tasks. Triggers on 'planning pipeline', 'standard track', 'full track'.
development
Generate or update docs/code-standards.md by scanning codebase conventions. Produces example-rich standards that help LLMs write consistent code. Use when starting a planning or build task. Triggers on 'code standards', 'codebase scan', 'scan conventions'.
development
--- name: performance-optimization description: 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. --- # Skill: performance-optimization ## STOP - Measure First (MANDATORY GATE) **Do not optimize based on intuition -- profile first.** - **Correctness before speed** -- make it work, then make it fast - **<4% of code causes >50% of runtime**
testing
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.