How to Stop Claude Code Writing Comments (and Other Slop)
Put a comment rule in CLAUDE.md, then install a hook that scans every file Claude Code edits so it removes narrative comments in the same turn.
To stop Claude Code writing narrative comments, add a comment rule to CLAUDE.md
and install a hook that scans every file it edits, so Claude removes the comments in the same turn.
An optional gate and a cleanup for existing comments follow. The general case, for any agent, is in
stop letting your agent write comments.
Claude Code narrates what the code does
// Validate the user input before processing
// This ensures we only work with valid data
function processOrder(order: Order) {
// Check if the order has items
if (order.items.length === 0) {
// Return early if there are no items
return null;
}
// Updated to use the new pricing service for better accuracy
return pricing.total(order);
}None of these five comments says anything the code does not. The last is a changelog entry in the source: true for one commit, misleading after the next. The better version keeps one comment that says something the code cannot:
function processOrder(order: Order) {
if (order.items.length === 0) return null;
// Totals come from the pricing service so tax rules stay in one place.
return pricing.total(order);
}aislop calls these narrative comments and trivial comments.
Step 1: set the bar in CLAUDE.md
Claude Code reads CLAUDE.md at the start of a session. Put the
comment rule there, with examples rather than adjectives like “minimal”:
## Comments
- Default to no comment. Good names and small functions come first.
- Write a comment only for: why a choice was made, a non-obvious
constraint or workaround, or a public API contract.
- Never narrate what the next line does.
- Never describe the edit you just made ("Updated to...", "Now uses...").
That belongs in the commit message.
- Never leave commented-out code.A rule is guidance: Claude reads it once and weighs it against everything else in the context, so long sessions drift. The hook in step 2 is the enforcement. For a fuller standard covering errors, types and scope, see the copyable AI coding rules file.
Step 2: check every edit with a hook
npx aislop hook install --claudeThis adds a PostToolUse hook on Edit|Write|MultiEdit
to ~/.claude/settings.json and writes ~/.claude/AISLOP.md.
Every file Claude Code edits is then scanned before the turn ends, and Claude gets the score, the
findings with file and line, and next steps.
--projectinstalls into this repository’s.claude/instead of your user settings.--dry-runshows exactly what would be written.npx aislop hook statusshows what is installed;npx aislop hook uninstallremoves only aislop’s entries and leaves your hand edits alone.
The same scan catches swallowed exceptions, unsafe casts, unused imports and helpers left over from a first attempt. Details: agent hooks docs.
Step 3: block the turn if quality drops
npx aislop hook install --claude --quality-gateQuality-gate mode records your current score as a baseline. At the end of each turn aislop runs a
full scan, and if the score is below the baseline the Stop hook
blocks and tells Claude why, so it keeps working until the score is back. After an intentional drop, run npx aislop hook baseline to reset it.
Clean up comments Claude already wrote
npx aislop scan
npx aislop fix
npx aislop fix --claudeaislop fix handles the safe cleanup. aislop fix --claude
opens Claude Code with every remaining finding, file and line as its prompt. Then add the same check
to CI with the two-minute quality gate,
so a session without the hook still cannot merge slop.
Frequently asked questions
Why does Claude Code add so many comments?
Claude Code explains its work as it goes, and some of that explanation lands in the file as comments. They look helpful in the diff and become noise once merged.
How do I tell Claude Code not to write comments?
Add a CLAUDE.md rule that allows comments only for why, a non-obvious constraint or a public API contract. Back it with a hook so violations are caught on the edit that introduced them.
What does aislop hook install --claude do?
It adds a PostToolUse hook for Edit, Write and MultiEdit to ~/.claude/settings.json and writes ~/.claude/AISLOP.md, so aislop scans every file Claude Code edits and returns the findings in the same turn. Use --project to scope it to one repository or --dry-run to preview.
Can Claude Code be blocked from finishing if code quality drops?
Yes. npx aislop hook install --claude --quality-gate records your current score as a baseline and blocks Claude Code's Stop hook while the project score is below it.
Does this stop Claude Code writing useful comments?
No. The narrative-comment and trivial-comment rules do not flag WHY comments, license headers, doc comments on public APIs, or comments stating a non-obvious constraint.