code-comment-style
Skill4 starsChanged 19 days agoMITView on GitHub
Write and tighten code comments so they state the why or the invariant in 1-3 lines. Use when adding comments to code, or when pruning verbose comments in a diff or PR.
In this repository3 other files it gives its agents.
- pr-description-writingSkill
- pr-review-lensSkill
- pr-thread-repliesSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Max 2-3 lines per comment: If it needs more, it is explaining the wrong thing.
- Very specific: line 15
No session artifacts: No ticket IDs, PR numbers, reviewer names, dates, or plan step numbers in comments or test names.
- Very specific: line 16
No index or constraint-name recitals: when the column tuple says it shorter: (account, timestamp, quality) beats …
- Distinctive: line 37
Before (5 lines, plus a near-identical twin further down):
- Distinctive: line 55
Never let a comment trim change code.
- Very specific: line 57
If the repo has its own comment conventions (AGENTS.md, CONTRIBUTING.md, linters), they win.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Code comment style
A comment is for a reader who has only the repo: no ticket, no PR thread, no chat that produced the code. It earns its place by saying something the code cannot: why the obvious-looking version is wrong, which invariant must hold, or which constraint forced the shape.
Rules
- Max 2-3 lines per comment. If it needs more, it is explaining the wrong thing. Keep only the non-obvious invariant; cut narrative, chronology, and impact stories.
- One comment per concern, then "same treatment" for repeats. Two identical loops do not each get a 6-line essay; the second gets
// Same upsert treatment for summaries. - No session artifacts. No ticket IDs, PR numbers, reviewer names, dates, or plan step numbers in comments or test names.
describe('idempotent persist on recompute (PROJ-123)')becomesdescribe('idempotent persist on recompute'). The PR and the ticket tracker own those references. - No index or constraint-name recitals when the column tuple says it shorter:
(account, timestamp, quality)beatsreading_account_timestamp_quality_idx. - Explain why, not what. "create() on an id already in the identity map resets the change-tracking snapshot, so the UPDATE is silently skipped" beats "set the fields on the entity".
- File and module headers state purpose and the non-obvious decisions, not a changelog.
- Constants get a short note on what they control when the name alone does not say it.
Before and after
Before (5 lines):
// Flush the deletions before persisting: within a single flush the ORM runs
// INSERTs before DELETEs, so a recomputed row that lands on a slot
// (account_id, timestamp, quality) still held by a row with a different
// deterministic id would violate reading_account_timestamp_quality_idx and
// abort the whole flush, freezing the account's series (PROJ-123).After (2 lines):
// Flush deletions first: within one flush the ORM runs INSERTs before DELETEs, so
// a replacement row would collide on (account, timestamp, quality) and abort the flush.Before (5 lines, plus a near-identical twin further down):
// Upsert readings. For a reading that keeps its deterministic id, set the changed
// fields ... Only timestamp, value, quality and seqId are touched; id and account form
// the identity, and re-assigning the account relation would add the entity to ...
// For a summary that already exists, set the changed fields ... a second time.After (3 lines + 1):
// Upsert readings: create() on an id already in the identity map resets the change-
// tracking snapshot, so the UPDATE would be silently skipped - set the fields on the
// loaded entity instead.
...
// Same upsert treatment for summaries.When tightening existing comments
- Never let a comment trim change code. If the comment sits next to declarations, re-read the region after editing and confirm the code lines survived.
- Re-run the affected tests after touching comments near test titles.
- If the repo has its own comment conventions (
AGENTS.md,CONTRIBUTING.md, linters), they win.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

