/appropriate-comments-code:appropriate-comments-codefrom appropriate-comments-code
Guides writing, editing, and reviewing code comments that carry information the code does not, avoiding restatements, history narration, editor instructions, and misplaced documentation.
Ships in appropriate-comments-code. 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.
Read when SKILL.md points to them.
A comment earns its place by carrying information the code does not, about the code as it is now, in as few lines as that takes.
Four ways to fail it, and they are equally fatal:
The third and fourth are the ones people miss. A comment can be entirely accurate, entirely present-tense, free of every ticket number and iteration label, and still be wrong for the spot it occupies.
On first use in a session, before any other step, read every companion file in this skill's directory. The summaries in this file are reminders of text you have already read, never a substitute.
length-and-doc-comments.md — the full text of tenets 1, 2, 3, 4 and 6 and the sibling rule, with the worked examples: an eight-line "list of rules" and its two-line rewrite; a bulleted "decision table" that fails the row test and the body-match test next to one that passes; an editor-addressed "never do X" block turned into an assertion in the existing test plus one line; a comment that names its own body; the per-language table of what a long comment looks like in that language's own code; the doc-comment syntaxes and section conventions. Re-read it before keeping any comment over two lines, writing a doc comment on a public item, or writing the test behind an editor-addressed comment.ratio-and-ledger.md — the counting procedure for the ratio check and the format and fields of the long-comment ledger. Re-read it before finishing any change.reviewing-comments.md — the procedures for verifying what a comment claims, fixing code before commenting it, reviewing comments in a diff, and auditing in bulk. Re-read it before any review or sweep.A comment describes the code as it is now, for a reader who has none of your context: someone months from now who was not in this session, did not read the pull request, and cannot ask you. That reader is skimming for one function, and every line above it is a toll. Twenty accurate lines above a function is a worse comment than two, because nobody reads twenty.
The length of a comment tracks the reader's need, never your deliberation. The line you argued about for an hour, the field you just added, the log call a reviewer questioned — each feels like it deserves a paragraph because you thought hard about it. That is not a property of the line.
Decide the destination before you write. Anything past two lines has three homes, and you choose one on purpose:
The standing constraint stays in the file. The deliberation that led to it, the alternatives, and the argument for the change go to the handoff by default. Tell the user; do not leave it in the file for them to find.
A comment is the whole contiguous run of comment lines, from the first comment line to the line before the next non-comment line, blank comment lines included. A paragraph you add to a block is not a second comment: the block is one comment, its line count is the run's, and it is judged as one. Every comment of three or more lines in your change ends up in the ledger with a verdict, and the verdict is carried out in the file before you finish.
The language sets the norm, and the norm is short. Apply the skill with the comment syntax the project uses, and calibrate against what that language's own reference code looks like. Every mainstream language has exactly one long-form shape, and it is the documentation shape: Go's package doc and the doc comment on an exported identifier; Rust's //! module docs and /// with sections; Python's docstring; JSDoc on an export; the header comment in C. Outside that shape, Go and Rust code from the standard library or any widely read project runs to one or two lines per comment, and three is rare. A non-doc comment over three lines in Go or Rust is foreign to the language before any tenet is applied, so in those languages the four-line question is asked at three, and the burden is on the keep.
reviewing-comments.md firstWhen NOT to use: the user explicitly asked for annotated, tutorial, or teaching code, where narrating every line is the deliverable. Say that you are setting the skill aside and why.
By default, existing comments in test files are not rewritten or deleted under this skill, and bulk audits skip test files entirely. A test file is whatever the project treats as one: a test suffix or prefix in the filename, a spec file, or anything under a tests, testdata, or fixtures directory.
The reason is that the core tenet inverts in a test. A regression test exists because of an incident, so the incident is its subject: the date, what broke, what was tried, the runbook link, the odd fixture value. That is specification and history, and a reader uses it to learn what the test protects. "First delivery" / "same event, redelivered" above two identical-looking calls is the map that makes the test readable. Deleting any of it is a loss nothing fails on. It is also why the reasoning behind an editor-addressed rule goes above the assertion that enforces it: the test file is where it is allowed.
That is the default, and it covers sweeps and incidental edits. Two cases step outside it:
The relaxed rules for test files. Two tenets still hold: no session-scoped identifiers (tenet 5), and the cover test (tenet 3), so no restating the call or assertion below it. Everything else is off, including every length and count rule elsewhere in this skill: length and history are allowed when they explain the test's sequence, fixture, or reason to exist. Apply them to every comment you write in a test file; to existing comments only when the user asked for the review, and then to all of them in scope.
If you were asked to sweep a package and it contains test files, say that you left their comments alone and why; do not silently include them.
Full text of each in length-and-doc-comments.md. The rules that hold without it:
Above a declaration, one or two lines. Above a statement inside a body, one line, or two when it states a constraint or invariant; measure against the statement, not its line count. More than that is documentation and belongs where a reader finds it on purpose.
The one exemption is a decision table, a state machine, or a one-rule-per-line list, and bullets do not grant it. It is earned by two tests run on every row before it is claimed, with both counts in the ledger: the row test (a row is a condition and its outcome, then it ends; a dash, a "because", a second sentence after the outcome is a gloss, and one glossed row makes the block prose) and the body-match test (a row whose condition and outcome both sit in the body below is the body restated; a table whose every row matches is deleted whatever its shape, and each unmatched row is named with the schema, config, or function that carries it).
A rule is a caller obligation or a guarantee: a lock to take, an ordering to keep, what a return means on error. Rationale, precedent, a comparison with no neighbour in the file, the body restated, the signature restated, and adjectives are not rules; cut them first, and cutting them drops nothing. Rules that share a principle compress into the principle, stated once. Never drop a rule to hit the limit.
A prose comment still over four lines is a question, not a keep (three in Go and Rust): show the user the comment and a candidate home, leave one or two lines in the code, or move it to the handoff when nobody can be asked.
Doc comments on public items are documentation: a one- or two-line summary, then the sections the language convention defines (Errors, Panics, Args, Returns, Deprecated), each stating a contract. Prose past the summary is still prose under the four-line question, and every other tenet applies inside. The marker is not the exemption; the audience is: /// on a private function, a docstring on a private helper, a Go comment above an unexported identifier is a plain comment under the two-line limit. The test is whether the project's documentation generator publishes the item.
The code has one state: the one on disk. A comment that narrates the journey describes something the reader cannot see and cannot act on, and rots the instant anyone touches the code again.
// Bad — narrates the journey
// We used to buffer the whole response here but that blew up memory on
// large payloads, so now we stream it.
func (c *Client) Fetch(ctx context.Context, url string) (io.ReadCloser, error) {
// Good — the present, and the constraint that shaped it
// Fetch streams the response body: payloads are unbounded and a buffered read
// can exceed the container memory limit. The caller must Close the reader.
func (c *Client) Fetch(ctx context.Context, url string) (io.ReadCloser, error) {
A regression is documented by a test, not by a comment. "Don't remove this check, it caused a double-charge" is an honour-system guardrail. Write the test that fails without the fix, named after the invariant, not the incident: TestRefundIsNotAppliedTwice, not TestBugFix1234.
A comment enforces nothing: the editor test. Ask who the comment is addressed to. A caller obligation ("callers must hold mu", a unit, who owns the buffer) stays. An instruction to a future editor ("never send X", "always go through Y", "do not lower this to Debug", "keep both", "keep in step with Z", "needs review before changing") is a promise nothing checks, at ten lines or at two, present-tense or not, incident or none, and rewording it as a fact changes the sentence, not who can break the rule. The verdict is written in this pass, never noted as a follow-up:
A process ("needs privacy sign-off") cannot be tested and goes to CONTRIBUTING, CODEOWNERS, or a PR template; the comment drops it. A value kept in step with something else is enforced by sharing the value or by a test that reads both; only when neither is possible does one line name the other place, and the ledger says the coupling is unenforced.
The cover test: cover the comment with your hand and read the code. If you lost nothing, delete the comment.
# Bad
# Opens the DB connection
connection.open()
# Good — a fact the code cannot express
# Postgres closes idle connections after 5 minutes; open() lazily
# reconnects, so callers must not cache the underlying socket.
connection.open()
| Comment carries | Example |
|---|---|
| A constraint from outside the code, stated as a fact in one line | Rate limit, spec clause, protocol requirement, hardware quirk. If an editor could break it and nothing would fail, tenet 2's editor test applies first |
| An invariant or precondition | "Callers must hold mu." / "items is sorted by id; binary search depends on it." |
| Units, ranges, encoding, ownership | "Timeout in milliseconds." / "Caller owns and must free the buffer." |
| Why a non-obvious approach is required | "Sequential on purpose: the API rejects concurrent writes to one account." |
| Why wrong-looking code is correct | "min not max: we want the oldest start, so the age is the worst case." |
| A workaround for an external defect | The upstream issue link, plus what to check to know it can be removed |
| A value that must be kept in step with something else | Only after sharing the value or testing both was ruled out; the comment is the fallback, not the enforcement |
| What a caller needs without reading the body | Public API doc comments: behavior, errors, side effects |
Self-describing statements. A log call, metric, error message, assertion message, or panic already carries its prose. Cover the comment and read the message: if the message says it, the comment restates. First confirm the line should exist (a forgotten debug print is deleted, not explained); then the only comment it can earn is one line about a non-obvious choice in its shape (a level that looks wrong, a field omitted, a sampling rate) or one line naming the external requirement that mandates it. A comment arguing that the line should exist goes to the handoff. "Do not lower this to Debug" is an editor instruction: the level is asserted in the test that runs the line, and "Info, not Debug: empty ticks are the only record the scheduler was alive" is what stays.
A workaround points at something that outlives the session and states its own exit condition: the upstream link and "drop once Safari 18 is the minimum".
The subject test: name the thing the comment is about. If it is a route, a feature, a customer, a policy, or a decision, and the code below is a call, a wrapper, a branch, or a registration, the comment is on the wrong subject. Ask instead: what is non-obvious about how this line is built? Comment that, or nothing.
The most valuable answer is usually why this line differs from its neighbours, because the next reader will "fix" the difference back into line. That comment has three parts, in two lines total: that the difference is deliberate; the one mechanical difference, in the code's own terms; what breaks if it is normalized. Point at the actual neighbour in the file before writing it; a counterfactual ("unlike a naive version") is defending existence, not shape, and does not earn this form.
// Deliberately its own With chain: this route reports under its own handler
// label, not the router's shared one, or its metrics merge with the asset endpoints.
r.With(metrics.WithHandler(metrics.HandlerOnboardingSearch)).
Get("/onboardings", h.SearchOnboardings)
When a comment is bigger than the code, it is almost always about something other than the code.
Identifiers minted during a working session are meaningless to every reader except the person who was driving that session, and meaningless to them within a day. None of these belong in a comment: finding numbers (F7, "finding 3"), iteration labels ("pass 2", "v2 of this approach"), wave, batch, or task IDs, plan step numbers, project phase names ("in this stage", "until stage 3"), agent or run labels, checklist positions ("item 3").
// Bad — "Review F7" existed for one session and explains nothing
// A failed POST leaves the syncer and force timer armed so the next poll
// retries immediately. Review F7 found this issue after flipping the
// previous test to false.
// Good — the same mechanism, stated as how the code behaves now
// A failed POST leaves the syncer and the force timer armed, so the next
// poll retries immediately rather than waiting for the backoff window.
Project phase names look permanent and are not: "always X in this stage" becomes a lie the moment the next stage ships. Tracker IDs are a project convention, not a default: grep for the ticket prefix in existing comments; match the convention if it is there, ask before introducing one if not.
A count in a comment is a tally of something that lives elsewhere: "the 7 tests", "the 13 other integration tests", "the three callers", "both fields". True the day it is written and silently falsified by the next addition, because nothing recomputes it. The count test: could someone add one more of the thing, in another file, without touching this comment? Then the number goes, replaced by what it stood in for — a name, a location, a pattern, an invariant — which grows with the set: "the tests in this file", "the integration-tagged tests", "every credential field".
Where a number belongs: when it is a constraint this code enforces or depends on ("batch size must stay under 50; the API rejects larger"), and then as a named constant the comment explains, not a literal in prose beside a literal in code. A load-bearing count ("exactly two, the protocol sends a pair") is an invariant, enforced by an assertion or a test, then commented.
Every identifier in a comment is a coupling nothing checks: rename the field or helper and the comment stays, confidently wrong. The visibility test: for each identifier the comment names other than its own subject, does the body below use it? If it does, that part is the body restated. Say it in words ("the recheck budget", not s.recheckBudget) or drop it. Name only what the reader cannot see below: the lock a caller must hold, the neighbour a tenet 4 comment differs from, a constraint in another file, an external system.
Full procedure in ratio-and-ledger.md. After the tenets, count per file, in the region you added or changed, comment lines against code lines, ignoring blanks, test files, and directives; skip when fewer than five lines remain. At half or more, the region is a document with code in it, and a shorter comment is not the fix: stop and ask the user where the material goes (package doc, README, ADR, API reference, PR description), leaving one- or two-line pointers. Only when nobody can be asked, default to the handoff and say so. A table lifts the two-line limit and never the ratio question.
Format and fields in ratio-and-ledger.md. Before finishing, list every comment of three or more lines in the changed region, as whole contiguous runs including the ones you only appended to, one line each: location, line count, shape, both counts for any list or table, and the verdict (kept, rewritten to N lines, deleted, sent to the user with a candidate home, or "enforced by" naming the test the assertion went into). It goes in the final message only, never in a PR description or commit message; when nothing is over two lines, it is the one line "no comment over two lines in the change".
The verdict is an action. "Deleted" with the lines still in place, "enforced by" with the assertion left as a follow-up, or "send to the user" with the block still in the file is a failed pass, whatever the task's wording asked you to add. The pass never waits on a pending decision: a comment whose fate hangs on a product call or a review that has not happened leaves the file now, and the question goes to the handoff.
When you add one element to a list of peers (a field, an enum variant, a config key, a route, a switch case), it adopts the comment density and placement its siblings already have. Bare siblings, bare member; trailing one-liners, one trailing line if it passes the cover test; one description above the type, the new meaning goes there. Readers infer emphasis from asymmetry: the one commented field among twelve reads as the dangerous one. The day-one test: would this comment exist if the element had been here since the file was created? A real constraint on the new member goes into the name first (TimeoutMillis), then where it is enforced. Example in length-and-doc-comments.md.
Full text in reviewing-comments.md. The rules that hold without it:
// n is the retry count is a rename request; // convert to cents is a helper request. If you cannot say in two lines why a block exists, split or rename it rather than writing ten.TODO states the gap in the present tense and in the form the repo already uses.When you change a line, you own every comment describing it. Before finishing, re-read the comments above, inside, and immediately after the lines you touched, and update or delete each one that no longer matches. Watch especially for a comment that describes one of something when your change made it two. Adding to a comment is editing it: the whole run is yours, it goes in the ledger as one entry, and it is measured as a whole.
Read reviewing-comments.md before reviewing a diff or auditing in bulk. The rules that hold without it:
restates, narrates, documents, enforces, unverified, counts, or stale.enforces finding is closed by the assertion, not by a shorter promise. Relocate accurate documentation and say where it went.| Context | Its home |
|---|---|
| A bug that must never come back | A test named after the invariant it protects |
| What the code must never do, send, log, or expose | An assertion in the test that already runs the code; one line of fact in the code |
| Why that rule exists | A comment above the assertion in the test, or the ADR or package doc |
| A step an editor must take before changing something (a review, a sign-off) | CONTRIBUTING, CODEOWNERS, a PR template; never a comment |
| Why this approach over the one it replaced | The commit message / PR description |
| A finding from a review pass | The review thread on the change |
| Why a line should exist at all, argued against an imagined objection | The PR description, or your final message to the user |
| The history behind a regression test | The test file itself: this is where history is allowed |
| Planned follow-up work | The issue tracker |
| Alternatives considered and rejected | A design doc or ADR |
| How a subsystem fits together | A doc, a package-level comment, or a README |
| A standing constraint this code must respect | A comment — this is the case comments are for |
"This subsystem batches writes because the API is rate-limited" is orientation and goes in a package doc, once. "Batch size must stay under 50; the API rejects larger" is a constraint on this code and goes above the constant. CLAUDE.md and AGENTS.md are never the home: they instruct agents, and no reader of the code opens them.
| Rationalization | Reality |
|---|---|
| "The history explains why I changed it" | The reader sees today's code, not your diff. State the constraint in the present tense, or put the story in the commit message. |
| "A comment warns the next person not to undo the fix" | It warns nobody — nothing checks it. Write the test; it fails when someone undoes the fix. |
| "It explains what we withhold and why, and that is a real constraint" | It explains it to whoever reads it and stops nobody. The constraint is an assertion in the existing test; the why goes above that assertion; the code keeps one line of fact. |
| "No bug was fixed here, so the test rule does not trigger" | The trigger is the audience, not an incident. A comment addressed to a future editor is unenforced today; the assertion is written now. |
| "Writing a test is scope creep; the task was the comment pass" / "I'll flag the test as a follow-up" | The assertion is the verdict on that comment, the way "deleted" is a verdict. A comment pass that leaves the promise in place and a note in the report has not run. |
| "It asserts a different invariant, so it reads better as its own test function" | Same setup, same call, one more assertion. Count the steps: at 60% shared it goes into the existing test, whatever its name. Two tests that build the same fixture and call the same function are one test written twice. |
| "The existing test builds a different fixture, so the setup is different" | A different value is not a different step. Build the scheduler, call Tick: those are the steps, and they are shared whether the job list is empty, three, or one that errors. Add the case to the existing test. |
| "It's a distinct unit with no existing test to extend" | Then say so in the ledger with the count, and name the new test after the invariant. Check the function the assertion needs, not the feature: the builder the handler calls usually has a test already. |
| "It's a forward-looking gate, not history, so tenet 2 does not apply" | A gate nothing closes is a comment. A process step goes to CONTRIBUTING or a PR template; a code rule goes to a test. |
| "I reworded it as a fact, so it is no longer addressed to an editor" | Rewording changes the audience of the sentence, not who can break the rule. If an editor could change the level, the field, or the value and nothing fails, the assertion is still owed. |
| "Two lines is short enough for a 'never do X'" | Length was never the problem with a promise. The line that stays is a fact about the code, and the test is what says never. |
| "If they decide the other way these need deleting, not shortening, so I'll wait" | Either outcome removes the lines. Carry out the verdict now and put the open question in the handoff; waiting ships the comment. |
| "The finding ID keeps it traceable" | Traceable to a session that no longer exists, by a reader who never saw it. |
| "It's all true and relevant; detail beats vagueness" | True and relevant is the bar for documentation. The bar for a comment is and it fits in two lines, barring tenet 1's exemptions. Twenty lines of signal still goes unread. |
| "The comment documents what the function does" | If it restates the name and the body, it documents nothing. Document what the caller cannot see: errors, side effects, preconditions. |
| "This code is subtle enough to deserve the space" | Subtle code deserves a precise comment, which is usually shorter. If it truly needs paragraphs, it needs a doc — and possibly simpler code. |
| "I'll note the ticket number just in case" | Only if the project already does it. Otherwise ask first. |
| "I'll leave the old approach in a comment in case we need it" | That is what version control is for. Commented-out code and eulogies for deleted code both get deleted. |
| "The comment is slightly stale but still mostly right" | Mostly-right comments are how people get misled with confidence. Fix it or remove it. |
| "I shortened it, so it's better" / "I'll just tighten it" | Only if every rule survived, and only if the subject was right. A tidy comment missing a precondition is a downgrade; a shorter comment on the wrong subject is still on the wrong subject. |
| "It explains what this endpoint / feature is" / "it's context the reader needs" | Documentation for the feature, filed above a line that is not the feature. Comment the mechanism in the line; put the feature description in the package doc, once. |
"A comment will explain what n means" / "it's too complicated to explain briefly" | Rename n. Split or rename until two lines suffice; a long comment is a symptom, not a treatment. |
| "The count is accurate" / "it's a small number, it won't change" | Accurate today; nothing re-checks it when the eighth test lands. Small sets are the ones that grow: "both" becomes three more often than 40 becomes 41. Name the set. |
| "The reviewer asked me to make the intent unmistakable" | Unmistakable is two precise lines plus a test, not a paragraph. Put the argument in the PR description. |
| "The log line looks like leftover debugging without an explanation" | First decide whether it is: leftover debugging gets deleted. If it stays, explain the one choice in its shape, in one line. |
| "This field is new, so it needs explaining" / "I thought hard about this line" | New to you. The reader sees a field among fields. Match the siblings; put a real constraint where it is enforced. How long you deliberated is not a property of the line. |
| "It's a test comment, and it narrates history" / "the sweep covers tests too" | Tests are where history lives. Leave existing test comments alone; sweeps skip test files and say so. |
| "Every one of these reasons has to sit next to its check" / "I'll shorten each so the ratio drops" | Write it the skill's way first. If the change is still half comments, it is a document; ask where the reasons go. Trimming to pass the count hides the signal. |
| "It has bullets, so it is a decision table" / "the rows are clean now" | Bullets are markup. Run the row test and the body-match test and put both counts in the ledger; clean rows that the body carries one by one are the body restated, and the table goes. |
| "One row is only partially in the body, so the table earns the exemption" | Partially is matched. Name the schema, config, or other function that carries the row instead; if there is none, the count is full. |
| "The table was already there; I only added the paragraph" / "the user asked me to add a note, not rewrite" | You touched the comment, so all of it is yours and all of it is in the ledger. The ask sets what you add; the skill sets what the comment you touched may keep. |
| "I ran the tests and reported the verdict; the rewrite is the user's call" | The verdict describes the file you leave behind. Delete, or move the material to the handoff with the question; either way the lines go. |
| "Each sentence is a separate rule the caller depends on" / "never drop a rule, so it stays this long" | Most are reasons, precedents, or the body restated. Underline the caller obligations; what is left is the comment. The rule against dropping protects obligations, not prose. |
| "It can go in CLAUDE.md" | CLAUDE.md instructs agents; a reader of the code never looks there. Package doc, API doc, README, or ADR. |
| "It's a doc comment, so the length rules don't apply" | Only on an item the doc generator publishes, and only as a summary plus sections. Three slashes on a private function is a comment. |
Any of these means stop and rewrite:
if and a return below; an "unmatched" row with no schema, config, or function named for itF7TODO with no stated gap or in a form the repo does not use; copied code with no source linkreviewing-comments.md before any review or audit, length-and-doc-comments.md before keeping a comment over two lines, writing a public doc comment, or writing an enforcing test, ratio-and-ledger.md before finishingTODO states the gap in the repo's form; any tracker ID matches a convention already in the repoWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
code-comments, documentation, code-review, comment-etiquette
npx claudepluginhub patrickdappollonio/claude-plugins --plugin appropriate-comments-codeOther plugins' skills for the same job