Coding techniques for the age of AI agents: 'Organize coding rules in AGENTS.md' and 'If quality deteriorates, instruct the system to reread AGENTS.md.'



Engineer

Fabian Sanglart introduces coding techniques for the age of AI agents.

My agent.md to improve LLM-assisted code quality
https://fabiensanglard.net/agent.md/index.html



Sangraar, who began working with Large-Scale Language Models (LLMs) for coding around mid-2025, notes that he 'wasn't impressed (by the effects of AI) at the time.' However, he reports that when he re-examined the LLM he was using in January 2026, he was not only able to generate complex indexed binary heap classes, but also succeeded in identifying a subtle bug in the polling crate caused by the Windows IOCP implementation.

Even so, the code quality was terrible, 'it was spaghetti code with no comments or structure,' Sangraar said. Looking back on that time, he wrote, 'Using LLM was certainly appealing, but once we cleaned up the code to meet production-level standards, the speed-up benefits were almost completely wasted. In other words, it wasn't practical.'

In March 2026, Sanglart reportedly tried using agent-based integrated development environments (IDEs) such as Google Antigravity , VS Code , and Claude Code . Sanglart stated that using agent-based IDEs allowed him to iterate through staged code.

As a result, the level of code generated by the AI agent improved to that of 'code written by a patient third-year computer science student.' The quality of the automatically generated code improved dramatically, reaching a level almost equivalent to that created manually. However, Sangraar described it as 'extremely tedious,' as it involved repeating the same process over and over again in each new session.



Therefore, Mr. Sangraar created his own README file , ' AGENTS.md ,' for the AI coding agent. AGENTS.md can be placed in the project's root directory, or a symbolic link from gemini.md/claude.md to AGENTS.md can be created to enable AGENTS.md from anywhere.

You can check out AGENTS.md, which was created by Mr. Sangraar, at the following link.

fabiensanglard.net/agent.md/agent.md
https://fabiensanglard.net/agent.md/agent.md



The AGENTS.md file created by Mr. Sangraar has the following rules set:

When writing text intended for human reading (comments, commit messages, replies to prompts), use as few words as possible. Choose every word carefully and keep the quantity strictly to a minimum. Get to the point. The fewer the better.
Please avoid superlatives and praise. Also, please stop saying that I am absolutely right. Tell me the cold, hard truth.
Extract frequently occurring or meaningful values into descriptive constants (const) or enumerations to avoid magic numbers and magic strings . Store self-explanatory, one-time values inline to avoid complexity. Use constants when values are obtained from specifications (e.g., HTTP 200 OK).
Reduce code indentation. Avoid the arrow anti-pattern . Utilize early returns and continuations.
Function names should be short; less than 30 characters.
Please use enumeration types instead of boolean values for function parameters.
Give your code readers a break. Add blank lines between logical code blocks.
Please add a concise and to-the-point comment explaining what each block does and why. If possible, use examples and suggest an ASCII diagram to illustrate the entire system.
Changes to member visibility are treated as breaking design changes. All fields and functions are made private unless external access is strictly required by design. Users are required to explicitly approve changes to access modifiers from private to internal or public.
• Program according to the level of abstraction. Low-level mechanisms (e.g., raw hardware I/O, sector analysis, direct socket streams) should be encapsulated in dedicated driver/abstraction layers. Expose clean, high-level APIs to the rest of your application so that calling code operates on domain concepts rather than raw implementation details.
Do not modify code blocks that are not related to the functionality you are implementing. For example, do not add comments to code blocks that you have not created or modified. When implementing functionality, minimize the number of lines you change as much as possible.
• Strictly adhere to hierarchical boundary layers. Each layer can only communicate with its immediate neighboring layer. Never 'punch holes' in layers. (e.g., controllers and UI components should not directly call database queries, hardware drivers, or low-level network clients; always route through an intermediate service/abstract layer.)
When creating a commit message, please follow these rules:
Rule 1: Separate the subject line and the body of the email with a blank line.
Rule 2: The subject line is limited to 50 characters.
Rule 3: Capitalize the first letter of the subject line.
Rule 4: Do not end the subject line with a period.
Rule 5: Use the imperative mood in the subject line.
Rule 6: To prevent Git formatting issues, manually wrap the text at 72 characters per line.
Rule 7: Use the body text to explain the 'what' and 'why,' not just the 'how.' Assume the code explains the 'how,' and the message should explain the context and reasoning.
If the prompt indicates that a bug is being fixed, do not write the fix immediately. First, write the test, confirm that it fails, then write the fix and confirm that the test passes.

Sangraar explains that 'creating our own AGENTS.md has significantly improved the quality of our code,' but it's not a magic solution that eliminates the need to read the code. He writes, 'Because LLMs always operate on misinformation, verification and iteration are still necessary, but we've shifted our focus from code style to architecture and design.'

Furthermore, LLMs have a troublesome phenomenon called 'context dilution.' This is when, as the context expands, the model pays less attention to instructions in the middle of the context and prioritizes the first and last instructions. The reason why context dilution occurs is not clear at the time of writing this article, but only two ways have been found to minimize its effects.

1. Keep the context concise. In other words, start a new session for each function.
2. Explicitly instruct the harness to reload AGENTS.md. If the code quality is poor, simply typing 'Reload AGENTS.md' should suffice.

Furthermore, by instructing agents to update AGENTS.md each time a new rule is added, you eliminate the need to manually update AGENTS.md.

in AI, Posted by logu_ii