ayamotokohei/dotfiles/writing-code-comments
Claude Code and agent skill by ayamotokohei/dotfiles
- community
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-commentsSKILL.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
| Term | Meaning | |
|---|---|---|
| Why not | One-line note: why the naive/obvious approach was avoided. Without it, someone may "simplify" the code and reintroduce a bug. | |
| Justification | Explaining why this change is correct to a reviewer. Do not put in code. | |
| Change narrative | Timeline of what changed ("when we switched from X to Y"). Do not put in code. | |
| Fix declaration | Phrasing 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@returnseach 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
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).
Test — delete prose that repeats the test name:
3. Keep only why odd-looking code exists
Go:
SQL migration — keep why a seemingly redundant constraint exists:
4. Delete when only the change story remains
Test:
Rationalization table
| Excuse | Reality | |
|---|---|---|
| "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
- SKILL.md in the repositoryCheckingskills/custom/writing-code-comments/SKILL.md
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
[](https://verified-skill.com/skills/ayamotokohei/dotfiles/writing-code-comments)