Agent.md Improves LLM Code Quality
- •Fabien Sanglard says agent.md improved LLM coding output after failed mid-2025 and better January 2026 trials
- •His agent.md rules cover constants, enums, function names under 30 characters, comments, layering and commit messages
- •Sanglard still verifies LLM code because hallucinations remain, while context dilution requires shorter sessions and reloads
Fabien Sanglard wrote on Aug 21, 2026 that his use of LLMs for coding improved after he began loading an agent.md file into coding sessions to enforce code-quality preferences. He first tried an LLM in mid-2025 while working on libadbmdns, an mDNS implementation in Rust, and said the generated code would not compile. He tried again in January 2026, when the model wrote a complex indexed-binary heap class and found an obscure bug in the polling crate tied to the Windows IOCP implementation.
Sanglard said the January 2026 results were useful but not production-ready because the code had poor structure, no comments and what he called spaghetti code. In March 2026, he tested agentic IDEs including Antigravity and VS Code's Claude Code plugin, then reviewed staged code through repeated feedback such as avoiding magic numbers, adding short comments and using short function names. He said this iteration made output close to what he would write by hand, but the repeated corrections became tedious.
The agent.md approach puts standing instructions in a file loaded by the coding harness at the start of a session. Sanglard said placing agent.md at a project root should be enough, while gemini.md or claude.md can be symlinked to agent.md for broader use. His sample rules tell agents to write concise human-facing text, avoid praise, extract meaningful repeated values into constants or enums, reduce indentation through early returns, keep function names under 30 characters, use enums instead of boolean parameters, add spacing between logical code blocks and write brief comments explaining what a block does and why.
The file also tells agents to treat member visibility changes as breaking design shifts and ask for explicit approval before moving private fields or functions to internal or public. Other rules require abstraction layers for low-level mechanics such as raw hardware I/O, sector parsing and socket streams; minimal changes to unrelated code; strict communication only between neighboring layers; braces on every one-line if statement; and a 7-rule commit-message format covering a 50-character subject line, 72-character hard limit, imperative mood and body text explaining what and why rather than how.
Sanglard said the method improved generated code but did not remove the need to read and verify it, because LLMs still hallucinate and cannot be trusted. He said he still verifies and iterates often, but now usually spends that effort on architecture and design rather than code style. He also described context dilution, linked to the Lost in the Middle paper, where models pay less attention to instructions in the middle of long contexts. His two mitigations are keeping context short by starting a new session per feature and asking the harness to reload agent.md when quality drops.