lean-comments
它能做什么
这个工具可以帮助保持程序代码简洁易懂。它会检查代码中的注释是否真正必要,以及是否解释了事情背后的“为什么”,而不是仅仅重复代码已经表达的内容。
适用场景
- ✓在代码中添加新注释时。
- ✓检查已有注释,确保它们有用时。
- ✓代码难以理解、需要清楚的解释时。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/lean-comments/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“检查这段代码中的注释,确保它们是必要的,并且解释了“为什么”。”
每周 5 个新技能,1 分钟读完。
工作原理
工具会判断:如果去掉这条注释,一位有经验的程序员是否会丢失重要信息。它会优先删除那些只是重复代码内容或显而易见的注释。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Lean Comments
Goal
Keep the smallest amount of high-value commentary necessary to make a codebase easier and safer to understand and maintain.
The default is no comment.
A comment must preserve meaningful information that a competent maintainer cannot reasonably recover from the code, names, types, signatures, structure, tests, configuration, or nearby context.
Comments are not labels, narration, decoration, declaration summaries, change logs, or substitutes for clear code.
Reader model
Write for a competent maintainer reading the repository at HEAD months later, without access to the current conversation, prompt, diff, pull request, issue discussion, review discussion, or implementation process.
Document the durable state, contract, constraint, or rationale of the code as it exists. Do not assume the reader knows what changed, what came before, or what was discussed unless that context is deliberately preserved in a reliable project source.
Authority and evidence
Use this skill as the comment-policy authority when it is active.
Use language, framework, library, or infrastructure skills to determine whether a non-obvious constraint is real, not to override this skill's necessity test.
Honor explicit current repository requirements, public API documentation requirements, tooling contracts, and generated-source rules. Do not infer a documentation requirement merely from existing comment density or precedent.
Base retained or newly written rationale on evidence from the repository, tests, configuration, official API behavior, project documentation, issue tracker, ADRs, specifications, or another reliable source.
Never invent a security reason, performance reason, business rule, compatibility requirement, API constraint, historical reason, architectural rationale, or external limitation to justify commentary.
If no supported non-obvious reason exists, remove or omit it.
Core decision rule
Before retaining or adding ordinary commentary, mentally remove it and ask:
Would a competent maintainer lose meaningful, non-obvious information if this comment did not exist?
If no, remove or omit it.
If uncertain, prefer no comment unless repository evidence demonstrates that the information matters.
If yes, retain only the minimum information necessary.
Never preserve a comment merely because it is correct, harmless, already present, grammatically polished, written as a warning, related to security or validation, related to internal or public state, or attached to an exported declaration.
The information itself must justify the comment.
Decision order
Evaluate existing and proposed commentary in this order:
- Delete or omit if the information is already clear without it
- Express through code if a tiny behavior-preserving readability improvement removes the need for it
- Shorten if it is necessary but contains unnecessary information or words
- Rewrite if it is necessary but unclear, inaccurate, stale, awkward, or inconsistent
- Use declaration documentation if the information belongs to the declaration's contract, semantics, or intended usage
- Keep unchanged only if it is already necessary, minimal, accurate, durable, and correctly styled
Always decide necessity before wording.
Do not polish an unnecessary comment or convert one into documentation.
What deserves an implementation comment
Use an implementation comment when it preserves non-obvious information such as:
- Why intentionally surprising code exists
- An external constraint or compatibility requirement
- An important invariant or subtle edge case
- A meaningful tradeoff or required workaround
- Non-obvious coupling
- An ordering, timing, lifecycle, concurrency, performance, or security constraint
- A reason an apparently simpler implementation would be incorrect
Prefer comments that explain why something matters.
Comments that merely explain what the code does should normally be removed.
Remove low-value commentary
Remove comments that merely:
- Restate or translate the code into prose
- Narrate the next statement or obvious control flow
- Explain an obvious guard clause, return, assignment, or branch
- Describe an obvious fetch, validation, transformation, mapping, filtering, creation, update, or deletion
- Repeat a declaration name, property name, type, signature, parameter, or return type
- Label or summarize a declaration
…
常见问题
什么是“源代码”?
指程序员编写的、告诉计算机该做什么的文本。可以把它想象成一份蛋糕食谱。
代码中的“注释”是什么?
指代码中的说明文字,程序员用它来解释难懂的部分或某个决定的原因。计算机会忽略它们。
为什么好的注释很重要?
好的注释能帮助其他程序员(或将来的你自己)快速理解代码,使代码更容易维护和修复错误。
详情
作者的原始描述
Audits, writes, and refines maintained first-party source-code comments and declaration-level documentation across languages. Use when adding, editing, reviewing, cleaning up, or auditing comments, doc comments, docstrings, TODO, FIXME, NOTE, suppressions, or other source commentary, including while modifying code and deciding whether a comment is warranted at all. Defaults to no comment unless it
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7268
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。