Improving LLM-Assisted Code Quality with agent.md

Using an agent.md file allows developers to inject persistent style preferences and architectural constraints directly into an LLM's prompt, shifting the human's role from correcting basic code style to focusing on high-level design. This approach reduces the tedious repetition of manual feedback during AI-assisted coding sessions.

The agent.md Framework

An agent.md file is a project-root configuration file that is automatically loaded by agentic IDEs and coding harnesses to fine-tune the behavior of the LLM. Instead of repeating the same stylistic corrections in every new session, developers can codify these requirements into a single source of truth.

Core Coding Standards

To ensure production-level code quality, the following rules are recommended for the agent.md file:

  • Conciseness: Use as few words as possible in comments, commit messages, and prompt replies. Avoid superlatives and praise.
  • Clean Code Practices:
    • Extract recurring or meaningful values into descriptive constants or enums to avoid "magic numbers."
    • Reduce indentation by leveraging early returns and continue statements to avoid the "Arrow Anti-Pattern."
    • Visibility: Keep all fields and functions private by default; request explicit approval before changing access modifiers to internal or public.
  • Architecture and Abstraction:
    • Encapsulate low-level mechanics (e.g., raw hardware I/O, socket streams) in dedicated driver layers.
    • Adhere to a strict layered boundary hierarchy where each layer only communicates with the immediate neighbor below it.
  • Documentation: Add brief comments explaining what a block does and why, using examples or ASCII drawings for complex systems.
  • Testing: When fixing a bug, the LLM must first write a failing test, observe the failure, then write the fix and verify it passes.

Commit Message Standards

To maintain a clean Git history, the agent.md file can enforce a 7-rule system for commit messages:

  1. Separate the subject line from the body with a blank line.
  2. Limit the subject line to 50 characters (hard limit of 72).
  3. Capitalize the first letter of the subject line.
  4. Do not end the subject line with a period.
  5. Use the imperative mood (e.g., "Fix bug" instead of "Fixed bug").
  6. Wrap the body text manually at 72 characters.
  7. Use the body to explain the what and why rather than the how.

Managing Context and Dilution

As the context window grows, LLMs suffer from "context dilution" (or "attention dilution"), where the model pays less attention to instructions located in the middle of the prompt. This phenomenon is documented in the "Lost in the Middle" research paper.

To mitigate this, developers should:

  1. Limit Session Length: Start a new session for each individual feature to keep the context short.
  2. Force Reloads: Explicitly command the agent to "Reload agent.md" when code quality begins to degrade.
  3. Automate Updates: Ask the AI agent itself to update the agent.md file when new rules are discovered during a session.

Community Perspectives and Critiques

While the agent.md approach is effective for some, the developer community has raised several counterpoints regarding its implementation:

"A bunch of these should be enforce with linting... The what is the code."

Critics argue that many of the rules—such as using curly braces for one-line if statements or limiting function name lengths—are better handled by automated linters rather than prompt instructions. Other developers suggest that overly bloated agent.md files can actually increase context consumption and degrade performance.

Additional suggestions from the community include:

  • Separation of Concerns: Moving coding standards to a CODING_STANDARDS.md file and keeping agent.md for interaction preferences.
  • Convergence Rules: Some developers implement a "Convergence rule" where every task must end in one of three states: Success, Meaningful Progression, or an Honest Stop, to prevent the AI from producing endless, brittle patches.
  • Simplified Technical English: Using instructions to follow "ASD-STE100 Simplified Technical English" to further reduce AI verbosity.

Sources

Related

  • Project
  • Dispatch
  • Dispatch
  • Dispatch
  • Project