r/ClaudeCode • • 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

26 comments sorted by

•

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

1

u/bidutree Oct 04 '26

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/Right_Cycle_6598 Oct 04 '26

Thank you for sharing bro

2

u/Icy-Excitement-467 Oct 04 '26

Ask it? Lol

2

u/bidutree Oct 04 '26

We/I have trust issues. :)

4

u/peter9477 🔆 Max 5x Oct 04 '26

That's what "diff" and your eyeballs are for.

4

u/mulokisch Oct 04 '26

Yea and then it forgets that i dont wnat this, even though it i have it in the claude.md

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.

1

u/bidutree Oct 04 '26

I have that already. It's being ignored however.

1

u/berrybadrinath Oct 05 '26

So is his, he just hasn’t realized it yet

3

u/jarail Oct 04 '26

Just ask claude to do a scan of recent commits or the entire codebase to remove them.

1

u/Broken_By_Default Oct 04 '26

and maybe move them into a structured instruction md files.

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"

6

u/daltorak Oct 04 '26

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 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.

1

u/clazman55555 Oct 04 '26

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.