/dmi-superpowers:writing-code-commentsfrom dmi-superpowers
Use when writing or editing code and adding a comment, note, TODO, or docstring — including when the change comes from a ticket, PR, or review thread whose ID could leak into the note.
Ships in dmi-superpowers. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A code comment is a developer note — a line for whoever reads this code next. The code already shows how it works, so a comment earns its place only by answering one of two things the code can't:
Core principle: A note is self-contained — it carries the whole reason itself, readable by someone with only this file. Traceability to tickets lives in commit messages and PR bodies, not in the code.
Length follows what the note guards, not a fixed cap:
❌ Too long, restates the mechanics:
# Loop over every item in the orders list. For each order, check if its
# status field equals "pending". If it does, append that order to the
# pending_orders list so the batch job can process them later.
for order in orders:
if order.status == "pending":
pending_orders.append(order)
✅ One sentence, states the why:
# Batch job reprocesses only orders the payment webhook hasn't confirmed yet.
pending_orders = [o for o in orders if o.status == "pending"]
❌ Outsources the reason to a tracker the reader may not have:
# Retry limit is 3 per CRM-430; see PR #78 discussion.
def sync_contact(contact, attempts=3):
✅ Self-contained — the reason travels with the code:
# Three attempts stays inside the CRM rate-limiter budget.
def sync_contact(contact, attempts=3):
Before you write a note, check it for a count or a position word. "these three", "two columns", "the chain", "the reader below", a bare "it", "the non-creating lookup" — each is a referent you owe the reader, and each costs a lookup they will skip. Replace it with the thing itself. This is the most common comment defect measured: five of seven found in one audit, and four of five agents reproduced it unprompted against guidance that did not name it.
| ❌ points | ✅ names |
|---|---|
# Only these three count as a person. | # The Change IMEI screen, a device's own edit page, and a bulk edit from the list. |
# Two columns are the same thing to a reader. | # device_model_alias and device_model_id are both just "device model". |
# the model the chain settled on | # the model the merges above settled on |
# Uses the non-creating lookup: | # Reads device_model_mapping, not device_model_mapping! |
# so it only runs where… | # so #newer? only runs where… |
# the reader below used to be handed the record | # A reader inside device_attributes once said @mdm |
Two identifiers that read alike must both appear as literal values. Not a style
preference — a correctness one. Prose paraphrasing 'Bulk Import' and 'Bulk Update'
as "the bulk import" destroys the only distinction the reader needed, and the note
then reads as contradicting its own code. Five of five agents made exactly this
mistake against guidance that did not forbid it. If your note mentions a thing the
list excludes, quote the string.
Never partially restate another unit's contract. Either point at it and stop, or say nothing:
❌ # ...or none when it is not the fresher source. (one of the callee's three reasons)
✅ # MdmInfoDecorator#device_model_attributes decides which, and lists the reasons.
A partial restatement is correct on the day you write it and wrong the first time the callee's own note improves.
Before writing "See X", read X. If X already says it, the pointer is a duplicate — delete it. A note governing two methods belongs at the level that owns both, once.
Readers reason about consequences from the destination.
❌ # The request leaves through a queue that no rollback reaches.
✅ # A person at the carrier reads the email and acts on it.
# Nothing in this app can recall it, so a transaction would not help.
The first describes plumbing; the second tells you the effect happens in another company and is irreversible — which is what makes the surrounding care look proportionate rather than fussy.
One sentence per line, never a break mid-sentence. This makes each sentence's
budget LineLength − comment prefix, and the prefix changes with indentation — a
private method four levels in has ~8 fewer characters than a module-level note.
Measure, don't eyeball: a sentence that doesn't fit is usually two ideas, and
splitting it to fit generally splits it along the real seam.
Plainness costs lines, and that is the trade. "A report is only as fresh as the last time that handset phoned home" is longer than "a payload can be days old" and means the same thing to more people. Jargon is compression that only works for a reader who already decompresses it for free. Keep the jargon that carries a distinction plain words can't — but only that.
Comments have no compiler and no test, so the check has to be yours. Run it on the lines you just added, not on the file around them:
git diff -U0 | grep '^+' | grep -inE '\b(above|below|here|these|those)\b'
Every hit is a referent you owe the reader. Name the thing instead.
| A good comment... | A bad comment... |
|---|---|
| Says what the code is for, or why it's this way | Narrates how, line by line |
| Names the things it refers to | Points at them by count or position |
| Scales to the rule it guards | Pads an inline note past three sentences |
| Carries the full reason itself | Points to a Jira key, PR number, ADR, plan doc, or review thread |
| Is absent when the code is self-evident | Is added out of habit |
# increment the counter above count += 1. Delete it.# KP-60: dedupe warnings tells a future developer nothing once the tracker is gone (and it will be). Write the reason the ticket contained: # Warn once per distinct key per bill, not per line. Ticket IDs belong in the commit message and PR, where history tooling preserves them.# try to find the mapping above
find_or_create_by grants false confidence that the line is safe to reorder or
skip. Worse than no comment.# def newer? checks whether…
goes stale on rename, and in many repos # def foo already means commented-out
code. Check what the convention is by counting, not by taste.# Ruby returns nil for an unset ivar instead of raising, so nothing failed.= and
one ||= side by side reads as an oversight someone should tidy. Name the
asymmetry so the next reader knows it is real; don't guess the intent.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub hundredbillion/dmi_superpowers --plugin dmi-superpowers30 skills in this plugin
/brainstormingYou MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation./codebase-designShared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary./creating-a-pull-requestUse when opening, creating, or writing a pull request, pushing a branch for review, or running gh pr create - covers the PR title, body, and evidence so the description reads for both a non-developer and a developer.