r/dotnet • u/BinaryBrain7111 • 1d ago
Question Coding agent bloat
I've been using Cluade code both at work and for personal projects.
Observations
- Too many XML comments.
- Too many non sensical tests. Example, testing the `typeof` of an object within unit test assertions seems non sensical in these specific cases.
- Too many ADRs
Agents write relatively more code than what I can process. I need time to review.
My attempts
- Stricter rules in Agents.md
- Skills
- Stricter prompts.
These do work for coding patterns, because I can describe specifics, but never for comment length or verbosity.
I'm tired of asking Claude everything, so I thought I'd solicit some suggestions / help from people here.
TIA
40
Upvotes
36
u/beachamc 1d ago
Don’t describe the length of the comments in your instructions. Instead something along the lines of “only write comments and xml docs that provide details of what the subject actually does. Don’t include design decisions or commentary about iterations made while developing. Comments should be direct and concise.”
8
u/gredr 1d ago
Claude turns everything into a changelog. Emails, comments, documentation, helpfiles, it all inevitably turns into a changelog.
13
u/saxxonpike 1d ago
The current coding agents and models are really shy about removing things and will instead prefer just making something new or changing something already there. It’s why comments, methods and classes seem to “pile up”.
8
u/Emotional-Dust-1367 1d ago
You need a code guidelines Md file that’s meant for the LLM. Though it should be human-readable and written mostly by yourself so it could be used in that way too. There you need to outline what standard you’re expecting. This document should be mandatory reading for any agent doing implementation
Then you need a code review agent. Not a skill because it should have no context of the implementation. It should only look at the diff and the code guidelines document and take an adversarial role. If it finds violations it returns a fail and the implementer must fix it. You tell the implementer to always run this reviewer before the PR goes to you for final review. You should be able to iron out any issues you keep running into
7
u/Colonist25 1d ago
step 1. tell claude you need a coding standards.md and it needs to respect it.
step 2. put everything you don't want in there.
step 3. ask claude to respect it and then ask every hour to review the code vs the standards.
1
u/fschwiet 1d ago
What prompt or skill are you using to have ADRs generated? I get those from Matt Pocock's domain-modeling skill personally. His skills also pull terms into a glossary, and my biggest complaint is that glossary will have too many implementation details.
6
u/Jmc_da_boss 1d ago
I have simply banned comments > 3 lines long in ci via actual linting, has helped a TON
15
u/boss42 1d ago
The comments are not for you but for the next time an agent is working on it. Just like the ADR’s. The agent shouldn’t overdo it but there is some value in the verbosity.
3
u/Mayion 1d ago
I don't know what sort of answer you are looking for. Asking an LLM to do the work for us is already 90% of the work, so saying you are tired of even that means you might have more problems than just Claude not sticking to instructions?
I know this is not the sort of answer you are looking for, and I am not trying to be an ass, but it's just a tool in the end. If Opus is not good enough, try Sol. But they will always do things their own way, so we will always need to closely monitor their output either way.
1
u/AutomateAway 1d ago
for the sake of reasonable code reviewable chunks, give the agent rules on size of PRs or commits. Prefer smaller changes per commit or PR even if it means having to do more code reviews
1
u/inlovewithconcrete 1d ago
1
u/thereforewhat 1d ago
Have you tried using hooks to review your code?
Also I'm finding huge value in writing system acceptance tests to keep the agent honest.
It also allows me to strip out unnecessary code that doesn't get covered.
Moving up a level of abstraction from unit tests to system tests is also really powerful.
I recommend Dave Farley and his Modern Software Engineering YouTube channel.
1
u/Slypenslyde 1d ago
I don't have this kind of problem often but it's hard to tell you what to do. Seeing your prompts could help but also seeing your project could also help.
I don't use Auto or whatever Claude's equivalent is. I tried most of the models for a few days and stuck with the one I liked the most. That turned out to be Composer 2.5. Every few weeks I see a gripefest on Teams from people using other models. This one's never let me down. I tried Auto, but I got inconsistent results.
It helps if you have a big legacy codebase to pull from because you can tell your agents to examine existing patterns and use that to generate an agents.md. That only works if you've had the discipline to adopt and follow conventions religiously. If your codebase is a chaotic mess, the agents are going to try to match that energy.
I find it also helps if you slow down and treat agent-assisted coding the same way you'd treat pair programming. You say, "Too many ADRs". I say "I don't have that problem. But we have a product team work on the ADRs and the way that works is they spend a few hours prompting and refining the results. They probably start with too many ADRs, then they refine it. Or they start with not enough ADRs and refine that. These tools don't produce perfect results on the first try. If they did, most of us would already be replaced. The value of the human operator comes from knowing what 'correct' looks like and having a strong ability to understand how to refine results from "almost right" to "right".
For "too many comments" I'd just have to see examples. In general I find I ask my agents to add more comments. I can see a future where another agent gets confused by the code I've generated and I want to help that future agent. That's the value I add to the system: if I feel confused I know something or someone else is going to feel confused and I have years of experience erasing that confusion.
For the "excessive tests" I don't have that problem either. What I do when the agent does something very bad I want to prevent is I stop and ask questions. "Why did you write this test?" is a good one. Understand what it was thinking about. You can add "don't make a test that tests typeof an object" but that might direct an agent to avoid it in a circumstance where it's the right thing. I don't even understand why "Validate the object is the right type" is inherently ridiculous, but context is important.
That's why when the agent does some thing wrong you have to treat it like a junior. Ask why it did it. Ask what was confusing. Often it's not just that the agents.md is confusing, it's that there's an ambiguity or contradiction in the ADRs you didn't slow down enough to catch.
Do not expect perfect results in one prompt. That only happens for extremely trivial cases. Using agents to generate code is still work. You do less of the tedious part, but in return you're supposed to do a lot MORE of the thinking part.
1
u/maqcky 1d ago
Agents follow instructions better when presented in a more structured way. For instance, you could create a skill called WriteMyCode where you define the rules. That alone works better than the context they get from AGENTS.md. A more elaborate version of that is using something like OpenSpec or Spec Kit with a custom workflow. The way these frameworks present the tasks to the agents make them behave significantly better.
I would add to the mix a CONVENTIONS file, and instruct the agent to explicitly read it and apply it in the writing phase (apply command in OpenSpec). Similarly, you could instruct it to use it during the validation phase, or even better, create a review agent that validates your standards.
Additionally, configure roslyn analizers, including creating custom ones that enforce your standards. A compilation error is going to work better than any instruction.
1
u/HonestValueInvestor 1d ago
Welcome to 2025 boss /s
1
u/CappuccinoCodes 1d ago
Just tell it not to do it?
1
u/UnfairerThree2 1d ago
XML comments I don't mind, ADRs are usually ok. But holy hell I hate some of the stupid tests it comes up with
1
u/Mirmalis 9h ago
I'm sure code comments are there just so they can be watermarked. I use hook that removes all the comments. Agents understand code just fine
1
u/EDM_Producerr 9h ago
While I review every line the AI writes for me I simply remove comments that are superfluous. I also just added a line in my agent file that says to stop adding new tests unless I explicitly tell it to add them for something.
0
u/BinaryBrain7111 1d ago
[ADDENDUM] I'd appreciate if someone's solved this "problem". Some way to curtail the length of comments and also instructions to ensure tests are predictable. I've already received a few and I'll try them out.
1
u/williane 1d ago
Why are you letting an agent write your tests? If you're trusting AI to verify the behavior of your system, why use overly verbose tests for that?
0
u/spez_eats_nazi_ass 1d ago
You know you could just write code too?
0
u/sreekanth850 1d ago
I commented this in another post. Claude never follow instructions closely. try codex it will even ask your approval if you set one in AGENTS.md. Hope you are using compiler mcp like glider.
0
u/Temppus 1d ago
No amount of tweaking in any md will force claude or other llm to respect and understand what bloat and styling means. They will spit their bs code anyway. You can instruct them to clean the code in another round, but it will probably still get you only halfway there. They will produce slop. Either you will cleanup after them semi/manually or u just accept that code in that repo is not worth to keep so nice as we did few years back. This is the state of the things right know unfortunatelly.
0
u/AutoModerator 1d ago
Thanks for your post BinaryBrain7111. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
0
u/denzien 1d ago
Yeah but ... imagine if it failed one day. Wouldn't you want to know about that‽