Delete Comment
Comments are a second source of truth that nothing checks. A stale or excuse comment steers a coding agent toward the wrong code, so the default is: the code says what, a few marked comments say why, and the count only goes down.
Run from the target repository root. scripts/comment_ratchet.py (beside this file) needs cloc (brew install cloc / apt install cloc).
Workflow
-
Scope. Take the path the user named, else the whole repo. Exclude vendored, generated and lockfile paths up front (for example
--exclude '^vendor/' --exclude '\.gen\.' --exclude '_pb2\.py$'); never edit those. -
Measure.
python3 <skill>/scripts/comment_ratchet.py report --top 30 [paths] [--exclude ...]. RecordcommentLines,allowedLines,countedLines.countedLinesis the upper bound of lines shed, not the estimate: in a well-kept repo most counted lines are decision records or code-coupled docs. Trailing comments on a code line are not counted (cloctreats them as code); say so. -
Classify. Read the comments together with the adjacent code and tests in the top files (for more than ~40 files, fan out one read-only subagent per directory, each returning a table). Put every comment in exactly one class:
Class Test Action Tautology Restates what the next line already says Delete Stale Contradicts the adjacent code/tests, or names code, behavior, tickets or history that no longer exist Delete Excuse Admits a shortcut ( TODO,FIXME,hack,temporary,for now,should be)Record an issue, then delete, or keep as HACK(<issue>)with the removal conditionDecision record Explains a non-obvious why that the code cannot show Short: keep, prefix WHY:. Long or cross-file: move into an ADR, leaveADR-<n>at the siteDirective Tool instruction or legal text ( eslint-disable,@ts-expect-error,noqa,type: ignore,pragma: no cover, license headers)Keep untouched When unsure between Tautology and Decision record, ask: would deleting it make someone reintroduce a bug? Yes means Decision record.
Looks like noise, keep it (do not count these as deletable; note them as kept exceptions in the report so they are not confused with linter directives or noise):
- A comment that is the only content of an empty block (
catch {}orexcept: pass): linters or tests may require it, and it marks the swallow as deliberate. - Exported JSDoc (
/** ... */) and runtime-consumed docstrings (e.g., Python__doc__read byargparse/CLI/OpenAPI, ordoctest):cloccounts them as comments, and schema generators, tests, or IDE hovers may depend on them. Check codegen and tests before touching them. - Section headers in long files that carry a spec, RFC, or ADR pointer: they are navigation, not restatement (only flag as Stale if the referenced target is actually wrong or removed).
- A comment that is the only content of an empty block (
-
Stop for the report. Unless the user already said to apply changes, deliver the report (template below) and stop without editing or creating any repo files. Deletion is easy to undo in Git, but the class decisions are the user's call the first time.
-
Apply. Edit only the scoped files.
- Excuses: record them before deleting so the file, original line/symbol, what is wrong, and removal condition stay accurate. Use the repo's external tracker only with the user's go-ahead for external posting; otherwise append one line each to
docs/comment-debt.md. - ADRs: follow the repo's existing ADR directory and numbering (for example
docs/adr/0002-...mdif0001-...mdexists); if thedomain-modelingskill is installed, use it rather than inventing a format. Never edit another skill to make this work.
- Excuses: record them before deleting so the file, original line/symbol, what is wrong, and removal condition stay accurate. Use the repo's external tracker only with the user's go-ahead for external posting; otherwise append one line each to
-
Ratchet. Copy
scripts/comment_ratchet.pyinto the repo (for examplescripts/comment-ratchet.py), runsnapshotwith the same scope and excludes, and wirecheckinto the repo's existing gate: apackage.jsonscript,pre-commit,lefthookor CI step, whichever the repo already uses. Do not add a new hook framework.- Exclude the ratchet script on repo-wide scopes:
comment_ratchet.pyscansgit ls-filesand contains its own Python docstrings (~14 counted lines). If the script lives inside the snapshotted scope (e.g., repo-wide snapshot with no path limit), pass--exclude '^scripts/comment-ratchet\.py$'(matching its path) tosnapshotsocheckwill not fail after the user runsgit add, and do notgit addfiles or include the ratchet script itself in.comment-baseline.json. - CI dependency: if
checkwill run in CI (directly or via an existing script such asnpm run lintinvoked by CI), ensure the CI job installscloc(for exampleapt-get install -y cloconubuntu-latest) so CI does not fail withcloc not found. - Ratchet rules:
checkfails when the repo's total counted lines exceed the baseline total and lists regressed files as pointers; renames and moves pass, andchecktakes no paths because scope and excludes come from.comment-baseline.json. A contiguous comment block is exempt when any line in it carriesWHY:,HACK(,ADR-<n>, a built-in tool directive, or a regex listed inconfig.extraMarkers(optional for repo-specific kept tags; otherwise kept JSDoc/docstrings/headers simply remain in the baseline).check --tightenrewrites the baseline after a drop; nobody raises it by hand.
- Exclude the ratchet script on repo-wide scopes:
-
Verify. Rerun
reportand give before/aftercommentLines,allowedLines, andcountedLines; run the repo's tests or build for edited files (deleting a comment can break codegen, empty-catch lint, or docstring tests); runcheckonce clean (exit 0), then add a throwaway comment to an already-tracked in-scope file (untracked files are ignored bygit ls-files) to provecheckfails (exit 1), then revert the throwaway and reruncheck(exit 0).
Leave changes unstaged in the working tree (do not git add, commit, push, or open a PR unless asked).
Report template
## Comment audit: <repo or path>
- Comment lines: <commentLines> (allowed markers <allowedLines>, counted <countedLines>)
- Estimate of lines deleted (Tautology + Stale + Excuse): about <n> lines (sample: <k>/<m> files, <x>/<y> counted lines)
| Class | Count (blocks / lines) | Examples (file:line, quoted) |
| Tautology | | |
| Stale | | |
| Excuse | | |
| Decision record | | |
| Directive | | |
| Kept exceptions (JSDoc / docstrings / headers / empty catch) | | |
- Proposed ADRs: <titles>
- Proposed issues: <one line each>
- Ratchet: <where check would run, including CI cloc note if applicable>
- Not covered: <excluded paths, trailing comments, languages cloc does not know>
Base the deletion estimate on comment lines (not block count) classified as Tautology, Stale, or Excuse in the read sample, scaled to countedLines. Keep raw deleted lines separate from any additional countedLines drop from adding WHY: or ADR-<n> markers. State clearly that it is an estimate and give the sample size.
