code-docs-cleanup
Clause-by-clause procedure for shortening and cleaning up source-code comments without losing a guard, the comment that says why a non-obvious line must stay…
by ocx-sh★ 20 GitHub stars
Install code-docs-cleanup in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
code-docs-cleanup
Shorten the comments in a source file without losing a guard. A guard is any clause that names a constraint a plausible edit would break, with or without the consequence. It is how the next agent learns why a non-obvious line looks the way it does and whether it may change it.
The comment standards live in the installed code-docs rule, cited here by
ID: GRD (guards), RTE (routing), LNK (pointers and IDs), SRF (rendered
surfaces) and LEN (length and ratchet). The cleanup-safety rules, CLN, are this
skill's own: Cleanup rules. Three facts shape every step (as
of 2026-09):
- In agent-written code most comment lines are guards and contracts, not essays. Deleting by category or by length deletes guards.
- The shipped guard recogniser finds fewer than half of real guards (recall about 0.43). A block it does not flag is unclassified, never safe to cut.
- The editing agent's belief that the meaning survived is not evidence. The structural check and a cold re-check are.
Contents: When to run · Setup · Scope · Procedure · Never touch · Cleanup rules · Report · MUST rows · What agents get wrong · References
When to run
Run it when:
- A change already edits a file whose comments are over the length caps (LEN-01, LEN-02), carry bare process IDs (LNK-01), or hold an essay.
- The owner names files for a sweep, or asks to bring a package down before its ratchet baseline is recorded (LEN-03).
- A review flags an over-cap block, or a pointer left beside the essay it was meant to replace (RTE-09).
Do not run it when:
- The text renders to users:
--help, JSON Schema, MCP tool descriptions, argparse or commander help, or a published package's API docs. That is an interface change (SRF-01, SRF-02). It moves rationale into plain comments and may regenerate goldens, which this skill never does. - The file is a test, generated, vendored, a lock or manifest file, or a golden.
Bare IDs in test files and test regions (LNK-01's
bare-id-testkey) go in a separate test-only change: list them in the report. - Another branch has the file in flight (see Scope).
- The fix is code: a type that owns a guard (GRD-12), a lint to enable (GRD-09, GRD-10), a test to rename. Each is its own reviewable diff.
- The repo's own rules protect the comment kind, for example a local rule that keeps section dividers or phase markers. The local rule wins until it is amended. Leave those comments and report the conflict.
Setup
- Find the rule's checks, in the project first, then in the global client
directories:
find . "$HOME/.claude" "$HOME/.config" -path '*/code-docs-reference/checks/cleanup_check.py' -not -path '*/node_modules/*' 2>/dev/null | head -n 1.CHECKSbelow is the directory of that hit; any installed copy works. Read thecode-docs.mdindex in the rules directory beside theskills/directory holdingcode-docs-reference/. No hit means the rule is installed neither in the project nor globally: install it withgrim add ghcr.io/ocx-sh/lore/code-docs. Where the client tool cannot install it, copyrules/code-docs.mdinto the client's rules directory (such as.claude/rules/) andskills/code-docs-reference/into its skills directory (such as.claude/skills/) from the rule's source withrsync -a --exclude __pycache__orgit archive, so no stale.pycfile rides along, commit that on its own before the cleanup, and run the find again. python3 "$CHECKS/cleanup_check.py" --self-testandpython3 "$CHECKS/guard_recogniser.py" --self-testboth exit 0.git status --porcelainlists nothing untracked that the cleanup did not create.cleanup_check.pyreads every untracked file as an added path and fails it (CLN-05). An untracked file you did not create is the owner's: never delete or revert it. Run the cleanup from a clean worktree, or ask the owner to move the file.- Pick the mode and set
BASE=HEAD. The check fails any non-prose line that differs from the base, so the working tree holds only uncommitted cleanup: the touched files', or in a sweep one file's.
| Mode | When | Before each file |
|---|---|---|
| Touched files (default) | Cleaning files the current change already edits | Commit the change's code first |
| Sweep | The owner named files, or asked for a package sweep | Commit the previous file's cleanup, on a branch made for the sweep from the default branch |
- Declare every library-kind package in
.code-docs.jsonbefore ranking or cleaning anything:python3 "$CHECKS/comment_census.py" --root . --reportlists undeclared packages that look published. The caps, and so the scope of the sweep, depend on the declaration.
Caps are the rule's defaults: plain blocks 5 lines, doc
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- references/decision-list.md
- references/failure-modes.md
- references/reason-recheck.md
FAQ
What does the code-docs-cleanup skill do?
Clause-by-clause procedure for shortening and cleaning up source-code comments without losing a guard, the comment that says why a non-obvious line must stay as it is and what breaks if it changes. Use when someone asks to shorten, trim or clean up comments, says a file has too many or overly verbose comments or is over-commented, cut comment density or comment bloat, split an essay comment or an over-long doc comment or docstring, move design rationale out of code into a decision record, remove plan, work-package, review-round or decision IDs from comments, delete comments that restate the code, bring a file under the code-docs length caps, or prepare a file or package for the code-docs comment ratchet. Not for writing the comment standards, which the code-docs rule carries, not for --help, JSON Schema, MCP tool descriptions or other text that renders to users, and not for user-facing documentation pages, which the docs-quality rules cover.
How do I install the code-docs-cleanup skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the code-docs-cleanup skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…