Lean Comments

Lean Comments

Guides an AI coding agent to audit, write and trim source-code comments and doc comments, defaulting to no comment unless it holds non-obvious, durable information.

Skill files1 file
SKILL.md471 lines
1
---
2
name: lean-comments
3
description: '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 preserves meaningful, non-obvious information that cannot reasonably be recovered from the code or nearby repository context.'
4
---
5
6
# Lean Comments
7
8
## Goal
9
10
Keep the smallest amount of high-value commentary necessary to make a codebase easier and safer to understand and maintain.
11
12
The default is **no comment**.
13
14
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.
15
16
Comments are not labels, narration, decoration, declaration summaries, change logs, or substitutes for clear code.
17
18
## Reader model
19
20
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.
21
22
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.
23
24
## Authority and evidence
25
26
Use this skill as the comment-policy authority when it is active.
27
28
Use language, framework, library, or infrastructure skills to determine whether a non-obvious constraint is real, not to override this skill's necessity test.
29
30
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.
31
32
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.
33
34
Never invent a security reason, performance reason, business rule, compatibility requirement, API constraint, historical reason, architectural rationale, or external limitation to justify commentary.
35
36
If no supported non-obvious reason exists, remove or omit it.
37
38
## Core decision rule
39
40
Before retaining or adding ordinary commentary, mentally remove it and ask:
41
42
> Would a competent maintainer lose meaningful, non-obvious information if this comment did not exist?
43
44
If no, remove or omit it.
45
46
If uncertain, prefer no comment unless repository evidence demonstrates that the information matters.
47
48
If yes, retain only the minimum information necessary.
49
50
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.
51
52
The information itself must justify the comment.
53
54
## Decision order
55
56
Evaluate existing and proposed commentary in this order:
57
58
1. **Delete or omit** if the information is already clear without it
59
2. **Express through code** if a tiny behavior-preserving readability improvement removes the need for it
60
3. **Shorten** if it is necessary but contains unnecessary information or words
61
4. **Rewrite** if it is necessary but unclear, inaccurate, stale, awkward, or inconsistent
62
5. **Use declaration documentation** if the information belongs to the declaration's contract, semantics, or intended usage
63
6. **Keep unchanged** only if it is already necessary, minimal, accurate, durable, and correctly styled
64
65
Always decide necessity before wording.
66
67
Do not polish an unnecessary comment or convert one into documentation.
68
69
## What deserves an implementation comment
70
71
Use an implementation comment when it preserves non-obvious information such as:
72
73
- Why intentionally surprising code exists
74
- An external constraint or compatibility requirement
75
- An important invariant or subtle edge case
76
- A meaningful tradeoff or required workaround
77
- Non-obvious coupling
78
- An ordering, timing, lifecycle, concurrency, performance, or security constraint
79
- A reason an apparently simpler implementation would be incorrect
80
81
Prefer comments that explain **why** something matters.
82
83
Comments that merely explain **what** the code does should normally be removed.
84
85
## Remove low-value commentary
86
87
Remove comments that merely:
88
89
- Restate or translate the code into prose
90
- Narrate the next statement or obvious control flow
91
- Explain an obvious guard clause, return, assignment, or branch
92
- Describe an obvious fetch, validation, transformation, mapping, filtering, creation, update, or deletion
93
- Repeat a declaration name, property name, type, signature, parameter, or return type
94
- Label or summarize a declaration
95
- Repeat information already represented clearly by tests or configuration
96
- Add generic context that is immediately inferable
97
- Act as unnecessary section headings or visual separators
98
- Preserve obsolete change history
99
- Address the reviewer or justify the current change
100
- State a bare rule or prohibition without useful non-obvious context
101
- Add rhetorical emphasis without information
102
103
Words such as `Never`, `Always`, `Important`, `Security`, `Internal`, `Public`, or `Required` do not make a comment valuable.
104
105
Judge the information, not how serious the wording sounds.
106
107
## Prefer self-explanatory code
108
109
When a comment compensates for unnecessarily confusing code, consider a tiny local behavior-preserving improvement such as improving a local name, extracting a clearly named boolean, simplifying local control flow, or removing redundant local structure.
110
111
Keep such changes minimal and directly related to clarity.
112
113
Do not turn comment cleanup into a general refactor or change behavior, architecture, public APIs, dependencies, or unrelated code merely to eliminate comments.
114
115
## Comment and documentation forms
116
117
Apply the same necessity test across languages and syntaxes.
118
119
Relevant forms may include:
120
121
- Line and block comments such as `//`, `#`, `--`, and `/* ... */`
122
- JSDoc, TSDoc, JavaDoc, KDoc, Rust doc comments, Go doc comments, C# XML documentation, and equivalent declaration documentation
123
- Module, package, and file documentation
124
- Python docstrings and other declaration documentation represented as runtime-visible strings
125
- TODO, FIXME, NOTE, HACK, XXX, and similar markers
126
- Tooling, compiler, formatter, coverage, build, framework, generator, and machine-consumed directives
127
128
Do not treat comment-like text inside string literals, regular expressions, URLs, snapshots, fixtures, templates, or test data as source comments merely because it contains comment syntax.
129
130
### Implementation comments
131
132
Use the language's normal implementation-comment form for brief rationale, constraints, invariants, workarounds, or other non-obvious local context.
133
134
Prefer one concise line when one line is sufficient.
135
136
### Declaration documentation
137
138
Use the language's declaration-documentation form only when the information belongs to the declaration itself and forms part of its contract, semantics, or intended usage.
139
140
For TypeScript, use TSDoc-compatible documentation when warranted. For JavaScript, follow intentional repository JSDoc conventions. For other languages, follow the language and repository's real documentation conventions without creating coverage for its own sake.
141
142
### Module and file documentation
143
144
Add module, package, or file-level documentation only for a durable architectural concept, boundary, invariant, terminology, lifecycle rule, or design rationale that is not apparent from the contents.
145
146
Do not add file headers that merely summarize exports or describe an obvious file purpose.
147
148
### Runtime-visible documentation
149
150
Some documentation forms, especially Python docstrings, can be observable at runtime through introspection or tooling.
151
152
Before removing or materially changing runtime-visible documentation, verify that doing so does not change a supported runtime contract, generated documentation surface, or external API expectation.
153
154
## Declaration documentation rules
155
156
This is not a documentation coverage exercise.
157
158
Do not document declarations merely because they are exported or public, and do not assume every language-level export in application code is an intentionally supported external API.
159
160
Use declaration documentation when consumers or maintainers need non-obvious information about:
161
162
- Behavioral contracts, parameter constraints, return semantics, or special values
163
- Error behavior, side effects, preconditions, or postconditions
164
- Ordering, timing, lifecycle, concurrency, or caching behavior
165
- Security, runtime, server, client, SSR, or environment constraints
166
- Compatibility requirements or upstream API behavior
167
- Business rules or invariants
168
- Units, formats, ranges, encodings, or cross-field relationships
169
- Deprecation, extension points, or important usage restrictions
170
- Non-obvious usage that materially benefits from an example
171
172
Apply a stronger documentation bias to published libraries, SDKs, packages, plugins, extension APIs, and intentionally external interfaces.
173
174
Apply a stronger no-documentation bias to internal helpers, simple CRUD methods, straightforward adapters, composables, plain data shapes, DTOs, and internal utilities.
175
176
### Do not repeat the type system
177
178
Do not add documentation that merely restates names, types, signatures, obvious values, or structure already expressed by the language.
179
180
Do not mechanically add tags such as `@param`, `@returns`, `@throws`, `@example`, `@remarks`, or `@see`. Use a tag only when it contributes information beyond the declaration and type system.
181
182
Plain interfaces, records, DTOs, structs, types, and obvious data shapes normally require no documentation unless they contain non-obvious semantics, invariants, formats, units, relationships, external constraints, or compatibility requirements.
183
184
## Style
185
186
### Single-line prose implementation comments
187
188
For a necessary single-line prose implementation comment, regardless of comment delimiter:
189
190
- Keep it as short as possible without making it cryptic
191
- Start normal prose with an uppercase letter unless technically required casing dictates otherwise
192
- Do not end it with `.`, `!`, `?`, or other terminal sentence punctuation
193
- Do not use em dashes or en dashes
194
- Do not use dash-based sentence punctuation
195
- Do not use semicolons as sentence punctuation
196
- Prefer a concise clause over unnecessarily complete prose
197
- Preserve exact casing and punctuation in identifiers, code, commands, URLs, paths, package names, versions, API values, and other technical literals
198
199
Example:
200
201
```ts
202
// Preserve source order for positional matching
203
```
204
205
Not:
206
207
```ts
208
// Preserve source order for positional matching.
209
```
210
211
These prose rules do not apply to machine-consumed syntax, technically significant punctuation, or genuine multi-line declaration documentation.
212
213
### Declaration documentation
214
215
Use normal sentence punctuation for genuine multi-sentence declaration documentation.
216
217
Keep it concise and focused on meaningful contract or semantic information. Do not add prose, tags, examples, or sections merely to make documentation appear complete.
218
219
## High-value examples
220
221
<examples>
222
223
<example>
224
Delete:
225
226
```ts
227
// A watchlist row
228
export interface FlickWatchlistItem {
229
media: FlickMedia;
230
added_at: string;
231
}
232
```
233
234
Correct:
235
236
```ts
237
export interface FlickWatchlistItem {
238
media: FlickMedia;
239
added_at: string;
240
}
241
```
242
243
The declaration already communicates the concept. Do not shorten the comment or convert it into declaration documentation.
244
</example>
245
246
<example>
247
Usually delete:
248
249
```ts
250
// Never copy a raw internal message into the public response
251
```
252
253
Do not preserve this merely because it contains `Never` or concerns a public boundary.
254
255
If repository evidence establishes a genuinely non-obvious reason, retain only that supported reason:
256
257
```ts
258
// Keep provider errors private because messages may contain credentials
259
```
260
261
Never invent such rationale to save the original comment.
262
</example>
263
264
<example>
265
Delete:
266
267
```ts
268
// Return the normalized result
269
return normalize(result);
270
```
271
272
The code already communicates the action.
273
</example>
274
275
<example>
276
Keep when supported by the implementation or external contract:
277
278
```ts
279
// Preserve source order because the upstream API matches items by position
280
```
281
282
The comment communicates a non-obvious positional constraint.
283
</example>
284
285
<example>
286
Useful declaration documentation:
287
288
```ts
289
/**
290
* Returns `null` for private profiles instead of propagating the upstream authorization error.
291
*/
292
export async function getProfile(): Promise<Profile | null> {
293
// ...
294
}
295
```
296
297
The documentation explains caller-visible behavior that the type alone cannot communicate.
298
</example>
299
300
</examples>
301
302
## TODO, FIXME, NOTE, and similar markers
303
304
Treat TODO, FIXME, NOTE, HACK, XXX, and equivalent markers as comments, not exceptions.
305
306
Verify that each one is still relevant, technically accurate, useful, and actionable when appropriate. Follow repository conventions for issue references or ownership when such conventions actually exist.
307
308
Remove stale, completed, meaningless, or superseded markers.
309
310
Do not add a marker prefix merely to make an ordinary comment appear important.
311
312
Do not implement unrelated work solely to remove a valid marker.
313
314
## Commented-out code
315
316
Commented-out executable code is normally dead code.
317
318
Delete it when version control already preserves the history and there is no current reason for the disabled code to remain.
319
320
Retain it only when the disabled form serves a current supported purpose, such as a deliberate copyable example, a semantically significant fixture, a documented compatibility fallback that maintainers are expected to re-enable under a known condition, or tooling/framework syntax that must remain disabled in source form.
321
322
Do not preserve commented-out code merely because it might be useful later.
323
324
Do not uncomment or execute old code solely to justify keeping it.
325
326
## Technically significant directives and headers
327
328
Preserve constructs whose presence, position, or exact syntax has technical, tooling, generation, runtime, or legal significance, including applicable:
329
330
- Shebangs
331
- Lint and formatter directives
332
- Compiler and type-checker directives
333
- Coverage directives
334
- Build tags and pragmas
335
- Framework directives
336
- Bundler or optimizer annotations
337
- Source-map and sourceURL directives
338
- Generated markers
339
- Required annotations
340
- Encoding declarations
341
- Licensing and copyright headers
342
- Other machine-consumed comments
343
344
These are not ordinary prose comments. Do not apply prose formatting rules to their syntax, and preserve technically required punctuation exactly.
345
346
### Stale directives
347
348
Technically significant directives are protected only while they remain necessary.
349
350
When practical, verify whether suppressions and other tooling directives are still required. Remove a directive when repository evidence or the relevant tooling proves it obsolete.
351
352
Do not remove or rewrite an unfamiliar directive merely because its purpose is unclear. Verify it first.
353
354
Do not broaden a suppression. Only narrow or remove one when the change is clearly safe, directly related to the audit, and does not require unrelated refactoring.
355
356
Treat legal headers more conservatively than tooling directives. Do not remove or alter licensing or copyright text without clear project authority.
357
358
## Durable references and links
359
360
A bare issue, pull request, specification, or documentation URL is not automatically useful commentary.
361
362
Retain or add a reference only when it materially preserves non-obvious context that cannot be expressed clearly enough in the code alone.
363
364
Prefer concise durable context plus a stable reference when the external source contains important details that would be unreasonable to duplicate.
365
366
Do not rely on transient conversation context or an inaccessible review thread as the only explanation for surprising code.
367
368
## Editing existing code
369
370
Treat existing comments as untrusted. Surviving previous cleanup passes does not make a comment correct or necessary.
371
372
When code changes make commentary inaccurate or redundant, update or remove it in the same change.
373
374
Do not narrate change history with phrases such as `now`, `previously`, `new approach`, `old behavior`, or `no longer`.
375
376
Document the durable state instead.
377
378
Do not address the reviewer or refer to the current conversation, prompt, diff, pull request, or implementation process.
379
380
## Interaction with prose-refinement skills
381
382
When a prose-refinement skill such as `unslop` is available, `lean-comments` remains authoritative.
383
384
Use prose refinement only after determining that the commentary deserves to exist.
385
386
The order is:
387
388
1. Determine necessity
389
2. Delete if unnecessary
390
3. Determine the correct comment form
391
4. Minimize the information
392
5. Refine the wording
393
394
Refinement may improve clarity, naturalness, and readability, but must not introduce personality or voice for its own sake, rhetorical flourish, humor, conversational filler, additional rationale, additional examples, additional claims, increased verbosity, or information that was not already justified.
395
396
Prefer the shortest natural wording that preserves the necessary technical meaning.
397
398
Do not allow a prose-refinement skill to weaken this skill's requirements for necessity, minimalism, accuracy, durability, or style.
399
400
A polished unnecessary comment is still unnecessary.
401
402
## Normal implementation work
403
404
When adding or modifying code:
405
406
- Do not add comments by default
407
- Add one only when it passes the necessity test
408
- Apply this skill to commentary directly affected by the implementation
409
- Remove commentary made obsolete by the change
410
- Do not perform an unrelated repository-wide comment cleanup unless requested
411
412
## Repository-wide audits
413
414
When explicitly asked to audit commentary throughout a repository:
415
416
1. Inspect enough of the repository to understand its terminology, architecture, languages, tooling, external constraints, and documentation conventions
417
2. Identify maintained first-party scope and exclude generated, vendored, dependency, third-party, and externally maintained content
418
3. Search systematically for all relevant comment, documentation, marker, directive, and commented-out-code forms used by the repository's languages
419
4. Review comments untouched by previous cleanup passes
420
5. Apply the necessity test before making wording changes
421
6. Review declaration documentation as critically as ordinary comments
422
7. Review commentary immediately preceding declarations for redundant labels or summaries
423
8. Review TODO, FIXME, NOTE, HACK, XXX, tooling directives, suppressions, and commented-out code
424
9. Inspect the final diff for accidental behavior, formatting, or unrelated changes
425
10. Search again for likely missed violations
426
11. Run relevant repository validation when source files or directives changed
427
428
For single-line prose comments, specifically inspect remaining comments ending in `.`, `!`, or `?`.
429
430
Do not blindly modify matches. Exclude technically significant syntax and comment-like text that is actually data.
431
432
For directives and suppressions, use the relevant tool when practical to distinguish required controls from stale ones.
433
434
## Scope boundaries
435
436
Apply this skill to maintained first-party source content.
437
438
Do not modify generated, vendored, dependency, third-party, externally maintained, or machine-generated content unless synchronization with an intentional source change requires it.
439
440
Do not introduce unrelated functional, architectural, behavioral, dependency, broad-formatting, or refactoring changes.
441
442
Keep the resulting diff focused.
443
444
## Final acceptance check
445
446
Before completing a repository-wide audit, verify that:
447
448
- Every remaining ordinary comment contributes meaningful non-obvious information
449
- Obvious comments were deleted rather than polished
450
- Label comments, code narration, and bare warnings are gone
451
- Comments are as concise as possible without becoming cryptic
452
- Single-line prose comments follow the style rules above
453
- Declaration documentation adds genuine contract or semantic information
454
- Plain data declarations are not decorated with useless documentation
455
- Types and signatures are not repeated unnecessarily
456
- No rationale or history was invented
457
- Stale TODO, FIXME, NOTE, HACK, XXX, and equivalent markers are gone
458
- Unjustified commented-out code is gone
459
- Required machine-significant constructs remain intact
460
- Proven-stale tooling directives and suppressions are gone
461
- Runtime-visible documentation was not removed without checking its contract
462
- Comment-like data was not mistaken for source commentary
463
- No unrelated changes were introduced
464
- Relevant validation passes
465
466
If a repository-wide cleanup still consists mainly of wording or punctuation changes while almost all original comments survive, re-evaluate necessity.
467
468
Do not optimize for a target number or percentage of comments.
469
470
Stop when further deletion or shortening would remove genuinely useful information rather than merely reduce comment count.
471

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…