writing-code-comments
Skill728 starsChanged 7 days agoMITView on GitHub
Gates whether a code comment should exist and forces the ones that stay to explain why, not what. Use ALWAYS before writing or editing a comment in any language (Python, TypeScript, Go, Rust, SQL), and when reviewing a diff that adds comments. Removes the comment types that clutter the codebase: narration that restates the code, change-history and chat-context notes ("previously did X", "per PR #123", "AI:"), perishable measurements and current-state stamps ("~20 min build", "currently", "today"), commented-out code, and redundant docstrings. Keeps the ones that earn their place: a non-obvious why, a warning about a non-local consequence, a pointer to context a future reader can't reconstruct. Not for user-facing copy (see `/writing-user-facing-copy`) or commit messages.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- ericmasiello/skillstheir own version, first seen Oct 20, 2026
- PostHog/posthogword for word, first seen Oct 20, 2026
- EdoMon93/claude-skillstheir own version, first seen Oct 17, 2026
- ViktorSoroka07/claude-delivery-skillstheir own version, first seen Sep 28, 2026
Other versions4 projects use a version of this.
Word for word · 1
- PostHog/posthog★ 40k100% same
Edited · 0
None found.
Wrote their own version · 3
- EdoMon93/claude-skills★ 0same name
- ericmasiello/skills★ 0same name
- ViktorSoroka07/claude-delivery-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository125 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- hog/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adding-today-highlightsSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- building-product-empty-statesSkill
- building-the-toolbarSkill
- clickhouse-migrationsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- extending-the-admin-consoleSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- formatting-slack-messagesSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- improving-drf-endpointsSkill
- improving-mcp-toolsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. 0 are common, 8 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
8
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Run this before adding or editing any comment.
- Distinctive: line 17
Before writing a comment, answer:
- Distinctive: line 21
If the answer is "it restates what the code does", delete it.
- Distinctive: line 37
If a block needs narration to be followed, the fix is smaller functions and better names, not a comment.
- Distinctive: line 41
Never record how the code got here.
- Distinctive: line 67
Delete it; the version history has it if it's needed again.
- Distinctive: line 86
Use mostly ASD-STE100 Simplified Technical English: Use active voice, simple tenses, one idea per sentence, and consistent terms.
- Distinctive: line 91
Match the surrounding density: Don't add a comment to every line of a file that had none.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing code comments
Run this before adding or editing any comment. The default is no comment. Good code with clear names carries most of its meaning on its own; a comment earns its place only when it tells a reader something the code cannot.
The gate: one question
Before writing a comment, answer:
What does this tell a future reader that the code itself doesn't?
If the answer is "it restates what the code does", delete it. Rename the variable or extract a function instead.
A comment worth keeping answers a why the code can't:
- ✅
# ATOMIC_REQUESTS is off, so wrap the two writes that must commit together - ✅
// Stripe sends the amount in cents; the rest of our system uses dollars - ✅
# Kept in sync with the enum in migrations/0042; update both
Delete these
Narration that restates the code
- ❌
# increment the counterabovecounter += 1 - ❌
// loop over usersabovefor user of users - ❌
# return the resultabovereturn result
If a block needs narration to be followed, the fix is smaller functions and better names, not a comment.
Change history and chat context
Never record how the code got here. That belongs in the commit message and PR description, where it's attached to the diff and searchable. In the source it's noise that goes stale immediately.
- ❌
# previously used a set here, switched to a list for ordering - ❌
// per PR #1234/# as discussed/# changed because the old way broke - ❌
# AI: generated this helper/// agent: refactored - ❌
# TODO(2024-01): remove after migrationleft in long after the migration
Perishable measurements and current-state stamps
Measured timings, counts, and rates rot silently: nothing forces them to update, and a rotted number misleads the next person sizing a timeout or shard count. The same goes for "currently" / "today" hedges, because the sentence states the same fact without them. State the durable relationship the number stood for.
- ❌
# skip the ~20 min buildwhen the durable fact is that the build is expensive - ❌
# ci-backend runs ~28m, so 60m ≈ one red resultinstead of "sized past a full run of the slowest workflow" - ❌
# no story currently opts into webkit snapshotswhere dropping "currently" states the same fact - ❌
# ~20 minutes in June, past 25 by Julybecause trend narration is change history
Numbers that stay:
- A dated snapshot:
# as of August 2024, Homebrew ships 4.13.2(the date makes staleness visible) - A restated adjacent code literal:
# runs that took >5 min (300 seconds)beside the300(it updates with the code) - A platform constant:
# GitHub's comment size limit (~64KB) - A target or budget:
# Target: ~15 min per shard(policy, not measurement) - Cited evidence:
# 30% peak memory observed on 16-core runs (#46853)(the link dates it)
Commented-out code
Delete it; the version history has it if it's needed again. Commented-out code is ambiguous to the next reader, who can't tell whether it's a note, a rollback plan, or an accident.
Redundant docstrings and type restatements
- ❌ A docstring that repeats the function name in prose:
"""Gets the user by id."""onget_user_by_id - ❌
# type: stringon an already-typed field - ❌ Python test doc comments (the repo convention is none; the test name says it)
Keep these
- A why that isn't obvious from the code: a workaround, a performance trade-off, a spec quirk, an ordering constraint.
- A warning about a consequence that lives elsewhere: "changing this breaks the cache key", "callers rely on this being sorted".
- A pointer to context a reader can't reconstruct from the repo: a link to the spec, ticket, or the reason a surprising value was chosen.
Style
Write comments the way you'd write technical documentation: explicit and precise. State the reasoning so the reader does not have to infer it. Length is not a target in either direction: don't clip a comment to look terse, and don't pad it to look thorough. Say what needs saying and stop.
- Be explicit and technical. State the cause and effect. Name the actual conditions, values, and consequences. A reader should not have to reconstruct your reasoning from a hint.
- Use mostly ASD-STE100 Simplified Technical English. Use active voice, simple tenses, one idea per sentence, and consistent terms.
- Let length follow the content. One line is fine when one line covers it; use more when the reasoning needs more. Neither brevity nor length is the goal.
- No em-dash. The tell to avoid is the clipped two-part phrase joined by a dash, like
# do the thing — it's faster. Use a real connective instead ("because", "so that", "which means", "to avoid"). - Explain why, not what. The what is in the code; the why usually is not.
- Preserve existing comments when moving or refactoring code, unless the change makes them wrong. Don't drop an existing why just because you're relocating the function.
- Match the surrounding density. Don't add a comment to every line of a file that had none; don't strip a well-commented module bare.
The fix for the em-dash is the connective, not more words. A short comment is fine once the dash is gone:
- ❌
# batch here — avoids N+1 - ✅
# batch here to avoid an N+1 against posthog_organizationmembership
When you're tempted to comment
Try, in order: (1) a better name, (2) a smaller function, (3) a type. Reach for a comment only when none of those can carry the meaning.
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.

