home / skills / ahonn / dotfiles / comment-guidelines

comment-guidelines skill

/.claude/skills/comment-guidelines

This skill enforces clear WHY-focused comments and removes redundant ones to reduce cognitive load when editing code.

npx playbooks add skill ahonn/dotfiles --skill comment-guidelines

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.2 KB
---
name: comment-guidelines
description: "Code comment guidelines. Remove redundant comments, add strategic ones explaining WHY not WHAT. Applied automatically when modifying code."
user-invocable: false
---

# Comment Guidelines

These guidelines should be automatically applied whenever writing or modifying code.

## Core Principles

1. **Self-documenting code first** - Use clear naming and structure; comments are last resort
2. **WHY over WHAT** - Comments explain intent and reasoning, not mechanics
3. **Reduce cognitive load** - Make non-obvious knowledge explicit
4. **Zero redundancy** - Never duplicate what code already expresses

## When to Add Comments

**DO comment:**
- Design decisions and trade-offs
- Non-obvious behavior or edge cases
- Interface contracts (public APIs, function signatures)
- Important context that isn't evident from code
- Gotchas and subtle behaviors
- Cross-module dependencies

**DON'T comment:**
- What the code literally does (self-evident)
- Well-named variables/functions
- Standard patterns and idioms
- Implementation details visible in code

## Application Rules

When modifying code:

1. **Remove** any comments that restate what code does
2. **Keep** comments that explain WHY something is done
3. **Add** comments only for non-obvious behavior or design decisions
4. **Update** existing comments if code changes make them stale
5. **Never** add comments just to fill space or appear thorough

## Examples

```typescript
// BAD: Restates the obvious
// Set user name to the input value
user.name = input.value;

// GOOD: Explains non-obvious behavior
// Normalize to lowercase for case-insensitive matching in search
user.searchKey = user.name.toLowerCase();

// BAD: Documents what is self-evident
// Loop through all items
for (const item of items) { ... }

// GOOD: Explains WHY this approach
// Process in reverse to allow safe removal during iteration
for (let i = items.length - 1; i >= 0; i--) { ... }
```

## Automatic Application

This skill does NOT need to be explicitly invoked. Claude should:
- Apply these principles whenever editing code
- Proactively clean up redundant comments encountered
- Add strategic comments only where they reduce cognitive load

Overview

This skill enforces concise, high-value code comments across configuration and dotfiles. It removes redundant WHAT comments and adds targeted WHY comments when modifying code to reduce cognitive load and surface important design intent.

How this skill works

Whenever code is edited, the skill inspects nearby comments and the changed code. It deletes comments that merely restate code, preserves and updates comments that explain intent or trade-offs, and inserts brief strategic comments for non-obvious behavior, edge cases, or interface contracts.

When to use it

  • Automatically on any commit or edit that changes configuration code (Lua, shell, Nix, etc.)
  • When reviewing code to reduce confusing or stale comments
  • While adding features that introduce edge cases or trade-offs
  • When documenting public functions, plugins, or cross-module interactions
  • During refactors to remove redundant commentary

Best practices

  • Prefer self-documenting names and structure; add comments only for intent and rationale
  • Remove comments that repeat code; update comments when behavior changes
  • Explain WHY, not WHAT — focus on decisions, constraints, and gotchas
  • Keep comments short, specific, and colocated with the relevant code
  • Use comments for interface contracts, edge cases, and cross-module assumptions

Example use cases

  • Normalize a user input field and add comment explaining case-insensitive matching requirement
  • Refactor a plugin setup and remove redundant line-by-line comments that restate configuration keys
  • Add a note explaining a workaround for a Neovim API bug in a specific version
  • Document why a loop iterates in reverse to allow safe removal during iteration
  • Annotate a public helper function with its expected input shapes and error semantics

FAQ

Will the skill ever remove useful comments?

It preserves comments that explain intent, trade-offs, edge cases, and interface contracts; it only removes comments that duplicate what the code already clearly expresses.

Does it add comments automatically everywhere?

No. It inserts comments only when a non-obvious behavior, design decision, or dependency would reduce cognitive load for future readers.