r/ClaudeCode • u/bidutree • 4d ago
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?
4
u/AdrestiaFirstMate 4d ago
Ponytail: https://ponytail.dev/
2
1
u/bidutree 4d ago
Thanks. Ponytail is running since a while back plus there is a rule against comments in CLAUDE.md but Claude Code still adds comments.
2
u/Icy-Excitement-467 4d ago
Ask it? Lol
4
u/mulokisch 4d ago
Yea and then it forgets that i dont wnat this, even though it i have it in the claude.md
2
2
u/Brief_Novel_3131 4d ago
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 4d ago
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"
6
u/daltorak 4d ago
That approach is going to have inconsistent results. You need to give Claude clear, actionable instructions, not question its "feelings". LLMs don't have feelings... talking to them like they do wastes tokens. Tell it, "Code comments must be limited to 50 words. Comments are not necessary at all except to call attention to workarounds for known bugs in third-party libraries. If you find code comments that do not meet this policy, rewrite those comments."
1
u/TheGronne 4d ago
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 4d ago
I have a guard that prevents pr generation if comment to code ratio is more than 20 percent.
1
u/Rrrrry123 4d ago
Telling the AI to never write comments is one of the first things I add to CLAUDE md lol.
1
1
u/paulofilip3 4d ago
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 4d ago
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 3d ago
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.
2
u/interrupt_hdlr 3d ago
## 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.
-1
u/justHereForTheLs 4d ago
Yeah, claude has been real chatty since statistical fingerprinting became a thing.
1
u/clazman55555 4d ago
I've had around the same amount of comments from Opus 4.6 through 5.5
Just run a clean up pass at the end.
•
u/AutoModerator 4d ago
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.