inferwire
/
AI·3 min read

Fabien Sanglard's agent.md: Coding-Style Rules for LLM Agents

Fabien Sanglard published the agent.md file that considerably improved the code LLM agents write for them, plus two ways to keep long sessions from losing track of it.

TL;DR

  • Fabien Sanglard published the agent.md file they use to make coding agents follow their style: no magic numbers, early returns, test-first bug fixes [^1].
  • The file considerably improved the generated code but doesn't replace reading it, Sanglard writes, and in long sessions the model pays less attention to it [^1].

Background

Coding harnesses load an instruction file such as agent.md when a session starts and inject it into the prompt [^1]. Sanglard got there in stages. A first attempt in mid-2025, on an mDNS implementation in Rust, produced code that wouldn't even compile. By January 2026 a model could write a complex indexed binary heap and pinpoint an obscure bug in the polling crate caused by the Windows IOCP implementation, but the code was spaghetti with no comments and no structure [^1].

What happened

In March 2026, with agentic IDEs such as Antigravity and the Claude Code plugin for VS Code, Sanglard could iterate on the staged code, and quality improved dramatically. The catch was having to repeat the same review comments, such as "don't use magic numbers", in every new session [^1]. Each suggestion Sanglard kept repeating went into agent.md, and the resulting file is now public as a starting point [^1]. Placing it in a project's root should be enough, and gemini.md or claude.md can be symlinked to it [^1].

The style rules ask for as few words as possible in comments, commit messages and replies, and no superlatives or praise: "Stop telling me I am absolutely right." Comments should explain what and why [^1]. Code should replace magic numbers and strings with named constants or enums, use enums instead of booleans as function parameters, reduce indentation with early returns, keep function names under 30 characters and always use braces, even on a one-line if [^1].

Other rules are about design. Fields and functions stay private unless the design requires otherwise, and the agent has to ask before changing an access modifier. It must not touch code unrelated to the feature it implements, and each layer may only talk to the layer directly below it [^1]. Commit messages follow seven rules, including an imperative subject line of at most 50 characters. For a bug fix, the agent writes the test first, watches it fail, and only then writes the fix [^1].

Why it matters

An instruction file turns review comments into defaults: once a preference is written down, the agent applies it in every session instead of waiting for someone to repeat it [^1]. Sanglard is clear that this is not a magic bullet. "LLMs constantly hallucinate and cannot be trusted," and the code still has to be verified and iterated on, but the review now focuses on architecture and design rather than code style [^1].

The file also has a weak spot. Sanglard points to "context dilution", outlined in the Lost in the Middle paper: as the context grows, a model pays less attention to instructions in the middle than to those at the beginning and the end [^1]. The two countermeasures in the post are starting a new session for each feature and, when code quality drops, telling the harness to "Reload agent.md" [^1]. Adding a rule doesn't require an editor either; Sanglard simply asks the agent to update agent.md [^1].

Practical example

Say you keep telling your coding agent to use early returns and to leave alone code it didn't change. Instead of repeating yourself, you add both rules to an agent.md in the repository root and symlink claude.md to it [^1]. The next session follows them from the start. If, deep into a long session, the agent starts nesting if statements again, you tell it to reload agent.md, or you finish the feature and open a fresh session for the next one [^1].

Related gear

We recommend this book because it lays out the foundational software design principles, pragmatism, and engineering discipline required to set clear boundaries for automated coding tools.

AdvertisementAmazon

The Pragmatic Programmer: Your Journey To Mastery

Sources

  1. [1]Fabien Sanglard — My agent.md to improve LLM-assisted code quality
  2. [2]Hacker News — My agent.md to improve LLM-assisted code quality