Live data from Hacker News

My agent.md to improve LLM-assisted code quality

fabiensanglard.net

131–140 of 200 posts

Re: My agent.md to improve LLM-assisted code quality

#131
post #38

A bunch of these should be enforce with linting, that way people who still hand-craft code get the same kind of feedback, e.g. Always use {}, even on a one-line "if" statement. & Keep function names short. Less than 30 characters. Then this one really is a pattern that creates a lot of churn: - Add a small, to the point, comment to explain what the block does and why . Use examples when possible. Propose ASCII drawin…

I forbid my agents from adding any comments. I review the code and add comments manually. If I can't understand something despite having the context then I throw away the code instead of having an LLM generate comments to explain what it did. This way the code stays readable/debuggable by humans.

> This way the code stays readable/debuggable by humans.

Please take the following as expressed with genuine curiosity: Do you not use an editor with syntax highlighting and collapsible comments?

At least on JetBrains you can configure the editor to collapse all comments on open and to have the comments displayed in a low-contrast color. This way, LLMs add a bunch of comments, but it doesn't affect your actual experience in trying to read the code. If you encounter code that seems inexplicable, then and only then would you expand the comment to see if that helps you understand.

Re: My agent.md to improve LLM-assisted code quality

#132
post #38

Earlier quoted context omitted.

I forbid my agents from adding any comments. I review the code and add comments manually. If I can't understand something despite having the context then I throw away the code instead of having an LLM generate comments to explain what it did. This way the code stays readable/debuggable by humans.

> This way the code stays readable/debuggable by humans. Please take the following as expressed with genuine curiosity: Do you not use an editor with syntax highlighting and collapsible comments? At least on JetBrains you can configure the editor to collapse all comments on open and to have the comments displayed in a low-contrast color. This way, LLMs add a bunch of comments, but it doesn't affect your actual experi…

LLM comments for code are almost unfailingly completely redundant or impenetrably verbose bordering on word salad.

Re: My agent.md to improve LLM-assisted code quality

#134
post #128

That's a lot of context for not much content. I ussually start with something like: - Prefer documentation as code - Comment why, not what - Document public APIs - Readability is paramount That usually gets me 80% there; rest is covered by the linter. I'm mostly just missing it explaining previous state too much, especially when making edits to plans, but I have not found good wording for that yet.

I'm also doing something similar, as for over-explaining state and momentary decisions, I have yet to find good wording for it too. I had a bit of success by running a reviewer at the end to look over comments and docstrings and judge if it is "evergreen", but feels a bit like a rain-dance.

Re: My agent.md to improve LLM-assisted code quality

#135

Earlier quoted context omitted.

How do you stop LLMs from making comments? In my experience, LLMs treat requirements for code output as suggestions

Add "Don't add any code comments anywhere" to your system prompt. If the model doesn't follow this, you want to start using a better model ASAP, because SOTA models for the last year or so, been able to following this without an issue.

I've come recently across arxiv 2604.20911

which claims "do" rules persist much better then "don't" rules.

Re: My agent.md to improve LLM-assisted code quality

#136
There is an annoying phenomenon with LLMs called "context dilution" or "attention dilution" that was outlined in the Lost in the Middle paper. As the context grows, a model starts paying less attention to instructions in the middle of the context in favor of what is at the beginning and the end.

So then what happens if the agents.md file is colossal and precise and all the required execution instructions are buried in the middle? Do the agents then just fail to execute?

Re: My agent.md to improve LLM-assisted code quality

#137

There is an annoying phenomenon with LLMs called "context dilution" or "attention dilution" that was outlined in the Lost in the Middle paper. As the context grows, a model starts paying less attention to instructions in the middle of the context in favor of what is at the beginning and the end. So then what happens if the agents.md file is colossal and precise and all the required execution instructions are buried i…

Yeah. That's why people these days avoid long descriptions and instead keep things as short as possible. in my experience, it seems like LLM can't recognize (or less attention value) unless it's structured in a deductive or inductive way

Re: My agent.md to improve LLM-assisted code quality

#138

Earlier quoted context omitted.

Add "Don't add any code comments anywhere" to your system prompt. If the model doesn't follow this, you want to start using a better model ASAP, because SOTA models for the last year or so, been able to following this without an issue.

I've come recently across arxiv 2604.20911 which claims "do" rules persist much better then "don't" rules.

Alright, what you'd put instead of "Don't add any code comments anywhere"?

I agree with the general guidance, but it's a general one and not applicable for everything. Some things cannot be expressed in a "do" way rather than "don't".

Re: My agent.md to improve LLM-assisted code quality

#139

A great piece. I esp liked: "- Don't touch blocks of code unrelated to the feature you implement. e.g. Don't add comments to a block of code if you did not create it or modify it. As much as possible try to minimize the number of changed lines when implementing a feature." The feature where you ask the LLM to fix one thing and it fixes three things. I kept noticing this in diffs.

I find too often that models do the opposite - they'll pile small targeted band-aids on code blocks based on new requirements, etc, when having them analyze whether a changed (broader) design would result in a far better overall design?

Re: My agent.md to improve LLM-assisted code quality

#140

Earlier quoted context omitted.

I've come recently across arxiv 2604.20911 which claims "do" rules persist much better then "don't" rules.

Alright, what you'd put instead of "Don't add any code comments anywhere"? I agree with the general guidance, but it's a general one and not applicable for everything. Some things cannot be expressed in a "do" way rather than "don't".

I don't know. I fully agree, and never did really try out this in depth yet.

I suspect rules with negations are not the same as don't rules, but unknown if really true, if so:

"when writing code do not add comments, code should not need it" may work

Post reply on HN