ayamotokohei/dotfiles/writing-code-comments

Claude Code and agent skill by ayamotokohei/dotfiles

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when adding or editing code comments or JSDoc during implementation, fixes, or refactors — when tempted to explain a fix, a regression, or why a change is correct. Enforces Why-not-only comments (one line), test-name-no-duplication, and red-flag removal; move change narrative to commit messages.

Install

npx vskill@latest install ayamotokohei/dotfiles/writing-code-comments

SKILL.md

The same SKILL.md was published earlier as ayamotokohei/dotfiles/writing-code-comments.

Code comment discipline

Comments are Why-not constraints for the next reader only. Change history and fix justification belong in commit messages.

Literal compliance without intent is also a violation (e.g. relabeling change narrative as "background explanation").

Japanese version: SKILL-jp.md in this directory.

Terminology

TermMeaning
Why notOne-line note: why the naive/obvious approach was avoided. Without it, someone may "simplify" the code and reintroduce a bug.
JustificationExplaining why this change is correct to a reviewer. Do not put in code.
Change narrativeTimeline of what changed ("when we switched from X to Y"). Do not put in code.
Fix declarationPhrasing like "prevents …", "fixes …", "addresses …". Do not put in code.

Decision criteria

Before writing, ask: "Does a post-merge reader of this code need this, or is it justification for the reviewer?"

  • Why not (keep · one line): Why the straightforward approach was avoided. Only what would cause a regression if removed.
  • Justification (do not write): Change narrative, fix declarations, correctness arguments, plans to fix other files.
  • Tests: The test name states what is tested. Do not repeat it in prose comments.

Wording rules

Apply these to every comment and JSDoc block you add:

  • Own-repo contract terms only. State the constraint in this repository's terms or the API contract (spec, types). Another repository's function names, file names, line numbers, and copied logic go stale silently when that side changes. Exception: a type's JSDoc may cite the API schema file it mirrors.
  • One statement per fact. The summary line, @param, and @returns each add what the others and the identifier name do not. A function's contract (return values, behavior on unset or invalid input, an input/output example) belongs in JSDoc; restating the name does not.
  • One plain declarative sentence. Write "X is avoided because Y" rather than a Why not X: label, and leave out emotive words and requests to the reader ("silently", "have them fix it").
  • Settled wording stays. Wording the user has confirmed is final; a hook notice or review feedback is not a reason to rewrite it.

Anti-pattern → Preferred examples

When refactoring a comment, choose compress or delete. When unsure, delete; rewording is not a third option.

  • Compress (pattern 1–3): A one-line Why-not constraint remains after removing narrative.
  • Delete (pattern 4): Nothing worth keeping for a post-merge reader — only the change story or test-name duplication remains.
1. Compress change narrative into a Why-not constraint
❌ {/*
Center the badge with flex. Line-box centering drifts with inherited line-height
from the parent, and misaligned after we changed the click target from button to anchor
*/}
✅ {/* Line-box centering drifts when parent line-height is inherited; use flex instead */}
2. Drop symptom dumps; keep only why-not-use-X

Applies when a library flag or API looks usable but is not in some state (e.g. query client isLoading stays false until the query key is ready).

❌ // isLoading stays false while the query key is null (session unresolved), so using it
// for loading state flashes the error screen on hard reload before data arrives
✅ // isLoading stays false until the query key is ready, so it cannot represent in-flight fetch

Test — delete prose that repeats the test name:

❌ # Retry on connection reset because we saw flaky tests last week; this test checks POST is skipped
✅ (no comment — test name carries what)
3. Keep only why odd-looking code exists
❌ // Required by the type, but when version skew sends a response without this field,
// normalize to an empty slice at the fetch boundary so the page does not throw TypeError
✅ // Required by the type, but omitted by legacy API responses — guard against page crash

Go:

❌ // We added this nil check after prod incident #4521 when old clients omitted the field
✅ // Legacy clients may omit this field despite the struct tag — avoid panic on nil deref

SQL migration — keep why a seemingly redundant constraint exists:

❌ -- Added NOT VALID after #892 rollback; we couldn't afford full table scan in prod last Tuesday
✅ -- Legacy rows predate the column; validate in a follow-up migration after backfill
4. Delete when only the change story remains
❌ {/*
Make the whole card a single anchor. Nested button > a traps focus on the button,
breaking keyboard navigation and dead click areas on card padding
*/}
✅ Delete — no comment. Rationale belongs in the commit message.

Test:

❌ def test_retry_excludes_non_idempotent_methods():
# POST must not be retried because duplicates create records — this test verifies retry skips POST
✅ def test_retry_excludes_non_idempotent_methods():
(no comment — test name states what)

Rationalization table

ExcuseReality
"It helps reviewers understand"That is the PR description and commit log. Post-merge code should not carry review noise.
"I want to record why we regressed"git blame and commit history record that permanently.
"More detail is kinder"Post-merge readers have no "before" state. Explanations that assume it are unkind.
"This is a Why not"If it cannot compress to one line, it is not a Why not.
"This is background, not history"Past tense or timeline wording makes it change narrative. Delete it.

Red flags — delete before finishing

  • References to past state or timeline ("when we changed to …", "fixed because it was …")
  • Fix declarations ("prevents …", "fixes …", "addresses …")
  • Test prose that repeats the test name
  • Block comments of three or more lines (Why-not fits in one line)
  • Another repository's function names, file names, or line numbers
  • JSDoc lines that restate another line or the identifier name
  • Why not X: labels and emotive wording

If any flag matches: delete the comment and move needed information to the commit message.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ayamotokohei/dotfiles/writing-code-comments/badge)](https://verified-skill.com/skills/ayamotokohei/dotfiles/writing-code-comments)

Something wrong with this skill or its page? Tell us.