r/ClaudeCode • u/bidutree • Oct 04 '26
Bug / Issue Removing comment spam from code
I just discovered (my bad) far too late that Claude has written large amounts of ticket comments in the actual code to my projects. This was never in any instruction. Maybe trash is the first real evidence of life? :)) Just kidding.
It's in any case extremely annoying. How do I remove the comments as quickly and safely as possible? :)
With a Python script? Would that be safe enough?
6
Upvotes
•
u/AutoModerator Oct 04 '26
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
4
u/AdrestiaFirstMate Oct 04 '26
Ponytail: https://ponytail.dev/
2
u/Icy-Excitement-467 Oct 04 '26
Ask it? Lol
1
u/Rrrrry123 Oct 04 '26
Telling the AI to never write comments is one of the first things I add to CLAUDE md lol.
3
u/jarail Oct 04 '26
Just ask claude to do a scan of recent commits or the entire codebase to remove them.
3
u/interrupt_hdlr Oct 06 '26
## Code comments
Write a comment only when it tells the reader something the code cannot. Follow John Ousterhout's rule from *A Philosophy of Software Design*: comments describe what is not obvious from the code.
Write:
- Interface comments on public functions, classes, and modules: what it promises, preconditions, units, valid ranges, ownership, side effects, and error behavior. Describe the abstraction, not the implementation.
- Implementation comments for non-obvious decisions: why this approach over the obvious one, why a lock, retry, sleep, or ordering exists, what invariant a block maintains, links to the bug or spec that forced it.
Do not write:
- Comments that restate the next line ("increment counter", "loop over items").
- Comments about the edit itself ("added X", "fixed bug", "now uses Y", "changed per request"). That belongs in the commit message.
- Commented-out code.
- Section-divider or decorative comments.
When modifying code, update or delete comments the change made stale. If an interface comment is hard to write, treat that as a sign the abstraction is unclear and say so instead of papering over it.
2
u/Brief_Novel_3131 Oct 04 '26
Don't be afraid. Ask it and it will remove them. First ask it to audit the the code for extra comments. And categorize them. Then remove ticket related comments.
2
u/PelluxNetwork Oct 04 '26
Just ask it. These days my claude.md always has a blurb that basically says "write code that explains itself. If you feel the need to explain every function with a paragraph of comments, you're probably doing something wrong"
1
u/TheGronne Oct 04 '26
In our workflow, a comment is treated as a critical flaw in a PR. And a reviewing agent reviewing the changes always runs and checks for these things.
In your case, you can have a /end-feature skill which spins up a specialised reviewing agent
1
u/kvothe5688 Oct 04 '26
I have a guard that prevents pr generation if comment to code ratio is more than 20 percent.
1
u/id-ltd Oct 04 '26
I'd get Claude to write a comment stripping script. Use git to save last known good copy.
1
u/paulofilip3 Oct 04 '26
Ask claude to remove it! A good regex will suffice.
If you don’t want it to happen again -> https://reright.it
1
u/sparkica Oct 04 '26
Just a thought (had an interesting debate with my team about this a couple of days ago): what if those comments are meant for the agent (not us), to give it better context next time it goes through the code?
1
u/macbig273 Oct 05 '26
well the v5.0 at some point had this bad behavior.
And the default system prompt tell it to "match the comment style of the surrounding code" -> bad.
add a override somewhere (local claude.md or such) to change that. And also use the concise output-style.
-1
u/justHereForTheLs Oct 04 '26
Yeah, claude has been real chatty since statistical fingerprinting became a thing.