Code Comments
Guidelines and audit workflows for writing concise, high-signal code comments.
Code should speak for itself. High quality code relies on expressive naming, clean modularization, and type signatures to communicate intent. Comments are reserved strictly for non-obvious context that the code cannot express on its own.
When to Use This Skill
- Writing new code or editing existing files (automated model behavioral guide).
- Reviewing diffs or PRs for comment hygiene and verbosity.
- Explicitly requested via
/code-comments or /code-comments <path> to audit and prune bloated, redundant, or noisy comments.
Core Rules
1. Why, Not What
Comments must explain intent, constraints, invariants, or edge-case rationale - never restate the syntax or mechanics of what the code is doing.
Bad: Restating what is already visible in syntax.
// Loop through items and push active items to the array
for (const item of items) {
if (item.isActive) {
activeItems.push(item)
}
}
Good: Code is self-explanatory; no comment needed.
const activeItems = items.filter((item) => item.isActive)
Good: Comment explains a non-obvious workaround, external constraint, or invariant.
// Upstream API truncates payloads at 64KB without returning an error code
const CHUNK_SIZE_BYTES = 64 * 1024
2. Refactor Over Comment
If code requires a paragraph to explain its mechanics, refactor the code instead of adding comments:
- Rename cryptic variables and parameters to descriptive names.
- Extract complex boolean conditions into well-named helper booleans or functions.
- Break long, multi-purpose functions into small, single-purpose units.
3. Brevity Over Verbosity
- No essays: Keep comments strictly to 1 or 2 concise lines. Never write multi-paragraph dissertations for a few lines of implementation.
- No decorative banners or headers: Avoid ASCII art, dividing lines (
// ====================), and redundant section headers.
- No redundant docstrings: Do not duplicate type signatures in JSDoc or docstrings (e.g.
@param {string} name The name parameter). Use docstrings only on public APIs where consumer-facing behavior is non-obvious.
4. Zero Tolerance for Stale Comments & AI Tells
- No commented-out code: Delete unused or dead code; version control tracks history.
- No changelogs / authorship in code: Do not add "Modified by AI on date" or inline changelog notes.
- Never use em-dashes: Do not use Unicode U+2014 em-dashes in comments. Use standard hyphens (
-), colons, commas, or parentheses.
Comment Decision Matrix
When writing or reviewing comments, classify each comment into one of four actions:
| Category |
Indicator |
Action |
| Redundant / Obvious |
Restates function name, variable assignment, loop, or type |
Delete immediately |
| Bloated Essay |
Multi-sentence explanation of straightforward logic |
Trim to 1 concise line focusing on the "why" |
| Cryptic Code Smell |
Long comment explaining convoluted logic |
Refactor code (rename, extract helper) and remove comment |
| Legitimate Invariant |
Explains upstream bugs, mathematical formulas, hardware quirks, or security reasons |
Keep as a brief, single-line note |
Interactive Audit Workflow (/code-comments)
When the user runs /code-comments or requests a comment audit:
Target Discovery:
- If a file or path is specified (e.g.
/code-comments src/auth.ts), scan that file.
- If no target is given, inspect the current working changes (
git diff or modified files).
Audit & Classify:
- Scan all comments in the target scope.
- Categorize each comment using the Comment Decision Matrix (Delete / Trim / Refactor / Keep).
Present Summary & Plan:
- Show a concise table of findings:
- File path and line numbers
- Current comment text
- Proposed action (Delete, Trim to single line, or Refactor)
- Rationale
Surgical Execution:
- Apply edits cleanly without touching unrelated formatting or logic.
- Verify code compiles and passes tests before finishing.
1---2name: code-comments3description: Write concise, high-signal code comments and prune comment bloat. Use when writing new code, editing existing files, or auditing code comments via /code-comments to keep comments minimal, explain non-obvious intent ("why, not what"), and avoid restating self-explanatory code.4---56# Code Comments78Guidelines and audit workflows for writing concise, high-signal code comments.910Code should speak for itself. High quality code relies on expressive naming, clean modularization, and type signatures to communicate intent. Comments are reserved strictly for non-obvious context that the code cannot express on its own.1112## When to Use This Skill1314- Writing new code or editing existing files (automated model behavioral guide).15- Reviewing diffs or PRs for comment hygiene and verbosity.16- Explicitly requested via `/code-comments` or `/code-comments <path>` to audit and prune bloated, redundant, or noisy comments.1718## Core Rules1920### 1. Why, Not What2122Comments must explain **intent, constraints, invariants, or edge-case rationale** - never restate the syntax or mechanics of what the code is doing.2324- **Bad:** Restating what is already visible in syntax.2526 ```typescript27 // Loop through items and push active items to the array28 for (const item of items) {29 if (item.isActive) {30 activeItems.push(item)31 }32 }33 ```3435- **Good:** Code is self-explanatory; no comment needed.3637 ```typescript38 const activeItems = items.filter((item) => item.isActive)39 ```4041- **Good:** Comment explains a non-obvious workaround, external constraint, or invariant.4243 ```typescript44 // Upstream API truncates payloads at 64KB without returning an error code45 const CHUNK_SIZE_BYTES = 64 * 102446 ```4748### 2. Refactor Over Comment4950If code requires a paragraph to explain its mechanics, refactor the code instead of adding comments:5152- Rename cryptic variables and parameters to descriptive names.53- Extract complex boolean conditions into well-named helper booleans or functions.54- Break long, multi-purpose functions into small, single-purpose units.5556### 3. Brevity Over Verbosity5758- **No essays:** Keep comments strictly to 1 or 2 concise lines. Never write multi-paragraph dissertations for a few lines of implementation.59- **No decorative banners or headers:** Avoid ASCII art, dividing lines (`// ====================`), and redundant section headers.60- **No redundant docstrings:** Do not duplicate type signatures in JSDoc or docstrings (e.g. `@param {string} name The name parameter`). Use docstrings only on public APIs where consumer-facing behavior is non-obvious.6162### 4. Zero Tolerance for Stale Comments & AI Tells6364- **No commented-out code:** Delete unused or dead code; version control tracks history.65- **No changelogs / authorship in code:** Do not add "Modified by AI on date" or inline changelog notes.66- **Never use em-dashes:** Do not use Unicode U+2014 em-dashes in comments. Use standard hyphens (`-`), colons, commas, or parentheses.6768---6970## Comment Decision Matrix7172When writing or reviewing comments, classify each comment into one of four actions:7374| Category | Indicator | Action |75| :----------------------- | :---------------------------------------------------------------------------------- | :------------------------------------------------------------ |76| **Redundant / Obvious** | Restates function name, variable assignment, loop, or type | **Delete immediately** |77| **Bloated Essay** | Multi-sentence explanation of straightforward logic | **Trim to 1 concise line** focusing on the "why" |78| **Cryptic Code Smell** | Long comment explaining convoluted logic | **Refactor code** (rename, extract helper) and remove comment |79| **Legitimate Invariant** | Explains upstream bugs, mathematical formulas, hardware quirks, or security reasons | **Keep** as a brief, single-line note |8081---8283## Interactive Audit Workflow (`/code-comments`)8485When the user runs `/code-comments` or requests a comment audit:86871. **Target Discovery:**88 - If a file or path is specified (e.g. `/code-comments src/auth.ts`), scan that file.89 - If no target is given, inspect the current working changes (`git diff` or modified files).90912. **Audit & Classify:**92 - Scan all comments in the target scope.93 - Categorize each comment using the Comment Decision Matrix (Delete / Trim / Refactor / Keep).94953. **Present Summary & Plan:**96 - Show a concise table of findings:97 - File path and line numbers98 - Current comment text99 - Proposed action (Delete, Trim to single line, or Refactor)100 - Rationale1011024. **Surgical Execution:**103 - Apply edits cleanly without touching unrelated formatting or logic.104 - Verify code compiles and passes tests before finishing.