Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

comment-code

FreeNo executable scriptsNot checked

Write clear, useful in-code comments and documentation that capture what the code cannot say for itself. Use this skill whenever writing or revising comments…

jd-solankiby jd-solanki★ 162 GitHub stars

About this skill

Writing Good Code Comments

Comments exist to capture information that was in the writer's mind but cannot be expressed in the code itself. Code states what happens mechanically; comments supply intent, contracts, rationale, units, invariants, and the higher-level picture. Good comments make a system understandable to someone reading it for the first time and let abstractions hide complexity. The cost is small — typically a fraction of development time — and it pays back every time someone (including the original author, weeks later) needs to read or change the code.

The one rule that governs everything

Comment things that aren't obvious from the code. Before keeping any comment, ask: Could someone who has never seen this code reconstruct this comment just by reading the code next to it? If yes, the comment adds nothing — delete it or replace it with something that does add information. "Obvious" means obvious to a first-time reader, not to you.

This single test eliminates most bad comments and motivates most good ones.

Don't repeat the code

The most common worthless comment simply restates the line below it, at the same level of detail.

i = i + 1          # increment i              ← adds nothing
count = len(items) # get the number of items  ← adds nothing

A close cousin is the comment that just recycles the words already in the name:

// Obtain a normalized resource name from the request.
String[] getNormalizedResourceName(Request req) { ... }

The only word here not already in the signature is "from." This tells the reader nothing they couldn't read off the declaration. The fix is to use different words than the name, words that explain the meaning the name only hints at: What is a normalized resource name? What are the elements of the returned array? When in doubt, the giveaway is one-comment-per-line at the same granularity as the code.

Comments work at a different level of detail than the code

A comment at the same level as the code repeats it. Useful comments go either lower (more precise) or higher (more abstract) than the code.

Lower-level comments add precision

Most valuable on declarations — fields, arguments, return values — where a name and type leave real questions open. Fill in what the type can't say:

  • Units — pixels? milliseconds? bytes?
  • Boundaries — is the range inclusive or exclusive of the endpoints?
  • Nulls — is null allowed, and what does it mean?
  • Ownership — for a resource that must be freed/closed, who is responsible?
  • Invariants — properties always true, e.g. "always contains at least one entry."
// Vague:
uint32_t offset;  // current offset in buffer

// Precise:
// Position in this buffer of the first byte that has not yet
// been returned to the client.
uint32_t offset;

When documenting a variable, think nouns, not verbs: describe what it represents, not how various pieces of code modify it. A comment that narrates "set to true here, reset to false there" mirrors the code structure and grows stale; a comment stating the meaning ("true means a heartbeat has arrived since the timer was last reset") is shorter, more stable, and lets the reader infer the manipulation.

Higher-level comments enhance intuition

These omit detail to convey overall intent — what the code is for and how it fits the surrounding method. Common for blocks inside methods, loops, and interface comments.

// Too low-level — partly repeats the conditions below:
// If there is a LOADING rpc with the same session whose last
// hash is smaller than the current one, use that rpc.

// Higher-level — states the purpose:
// Try to append this key hash to an existing, not-yet-sent RPC
// bound for the right server.

With the high-level version a reader can predict almost everything the loop does and can judge whether the code is correct — something a detail-echoing comment never enables. Higher-level comments are harder to write because they require stepping back from detail. Ask: What is this code trying to do? What is the simplest thing that explains all of it? What is the most important thing about it?

A specially useful higher-level form is "how we get here" — the conditions under which a block or method runs, especially for code that only executes in unusual situations.

Comment categories — and which matter most

Category Where Priority
Interface Block immediately before a class/method/function declaration; defines the abstraction Highest
Data-structure member Next to a field/variable declaration Highest
Implementation Inside a method body Often unnecessary
Cross-module Describes dependencies spanning module boundaries Rare but critical

Every class should have an interface comment, every class variable a comment, and every method an interface comment. The occasional declaration is so self-evident (a trivia

Full SKILL.md on GitHub

Install comment-code in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the comment-code skill do?

Write clear, useful in-code comments and documentation that capture what the code cannot say for itself. Use this skill whenever writing or revising comments, docstrings, interface/API documentation, function or class headers, or inline explanations — and whenever reviewing code for comment quality or being asked to "document," "add comments," "explain in comments," or improve existing comments. Apply it even when the request only mentions writing the code, since fresh code is the moment to document it well.

How do I install the comment-code skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the comment-code skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare comment-code with