cd /news/ai-agents/how-to-write-an-agents-md-that-codin… · home › topics › ai-agents › article
[ARTICLE · art-180579] src=clixad.io ↗ pub= topic=ai-agents verified=true sentiment=· neutral

How to write an AGENTS.md that coding agents follow

A repository's AGENTS.md file is sent with every model call a coding agent makes, so on Claude Sonnet 5.5 each 1,000 tokens of instructions adds about 3% to every task, according to the guide. Codex, Cursor and Clixad read AGENTS.md directly, while Claude Code reads it only when no CLAUDE.md exists in the working directory or above it, unless a setting enables both, and Gemini CLI reads it when its context.fileName setting names it. The guide recommends limiting the file to checkable rules an agent would otherwise get wrong, such as "Run npm test before committing" instead of "Test your changes.

recommendation

Trim AGENTS.md to build/test commands, layout and checkable conventions, and bridge it into CLAUDE.md with @AGENTS.md, since every token is billed on each model call.

more in playbook: Working with AI coding agents
by read9 min views2 publishedDec 2, 2026
How to write an AGENTS.md that coding agents follow
Image: Clixad (auto-discovered)

AGENTS.md is a Markdown file in your repository that coding agents read before they start: the build and test commands, the conventions and the layout, written for the agent. Codex, Cursor and Clixad read it directly, Gemini CLI and Claude Code with a setting or a one-line bridge.

        Keep it to what an agent would otherwise get wrong, in rules it can check. **It is sent with every model call**, so a line is paid for a dozen times in an ordinary task. On Claude Sonnet 5.5, 1,000 tokens of instructions add about 3% to every task.

What AGENTS.md is #

AGENTS.md is a plain Markdown file in a repository that coding agents read before they start work. The project that defines it puts it simply: "Think of AGENTS.md as a README for agents: a dedicated, predictable place to provide the context and instructions to help AI coding agents work on your project." There are no required fields. Its own FAQ says "AGENTS.md is just standard Markdown. Use any headings you like".

The reason it is worth writing is that an agent starts every session knowing nothing about your project. Without the file it spends model calls finding out how to build and test, and it guesses at conventions it cannot see. With the file, those answers arrive before the first call.

Which agents read it #

Which instruction files each agent reads, from each vendor's documentation, read 2 December 2026.
Agent Its own file Reads AGENTS.md?
--- --- ---
Codex AGENTS.md , orAGENTS.override.md in its place Yes
Claude Code CLAUDE.md Only when there is no CLAUDE.md , unless a setting says both
Gemini CLI GEMINI.md When its context.fileName setting names it
Cursor Rules in .cursor/rules Yes
GitHub Copilot .github/copilot-instructions.md On the surfaces that read agent instructions
Clixad CLIXAD.md Yes, in the directory it starts in
      Claude Code's documentation is precise about its rule: "By default, Claude reads AGENTS.md only when you have
      no CLAUDE.md in your working directory or above it." For a repository that already has a `CLAUDE.md`,
      it suggests a bridge: a `CLAUDE.md` that imports the shared file with `@AGENTS.md`, with
      anything specific to Claude below it. Gemini CLI's context files "use the default name GEMINI.md", and its
      `context.fileName` setting takes a list, so `AGENTS.md` can be one of the names. Cursor's
      documentation says "Cursor supports AGENTS.md in the project root and subdirectories."
    

      So one `AGENTS.md` can serve most agents a team uses, with a line of configuration or a one-line
      bridge file for the rest.

What to put in it #

The project's site lists popular sections: a project overview, build and test commands, code style guidelines, testing instructions and security considerations. Anthropic's advice for its own file is the most useful filter we have found: "Keep it to facts Claude should hold in every session: build commands, conventions, project layout". It also asks for instructions that can be checked: "Use 2-space indentation" rather than "Format code properly", "Run npm test before committing" rather than "Test your changes".

A short file that follows those rules:


## Commands
- Install: npm ci
- Test one file: npx vitest run path/to/file.test.ts
- Typecheck: npm run typecheck (must pass before a commit)

## Layout
- apps/api: the HTTP server. apps/web: the frontend. packages/db: migrations and queries.
- Never edit files under generated/; run npm run codegen instead.

## Conventions
- TypeScript strict mode. No default exports.
- Money is integer cents everywhere, never floats.
- New endpoints get a test in apps/api/test/ in the same commit.

Every line there is something an agent would otherwise get wrong or spend a call discovering. None of it is something it would find in one search.

What to leave out #

  • Secrets. The file is usually committed, and its contents are sent to the model provider with every call. Keys belong in the environment.
  • What one search finds. A list of every file, or a description of what each function does, is longer than the search that would answer it.
  • Long procedures. Anthropic's advice is that "If an entry is a multi-step procedure or only matters for one part of the codebase, move it to a skill or a path-scoped rule instead." In an agent without those, a short pointer to a document the agent can read when it needs it does the same.
  • Wishes. "Write clean code" changes nothing. A rule the agent can follow or break does.

How long it should be #

Anthropic's guidance for its own file is to "target under 200 lines per CLAUDE.md file. Longer files consume more context and reduce adherence." Codex stops adding instruction files "once the combined size reaches the limit defined by project_doc_max_bytes (32 KiB by default)." Clixad cuts each instruction file at 20,000 characters and tells the model the rest was left out. Those limits are ceilings. The useful length is shorter.

What each line costs #

      An agent sends the instruction file with every model call, and an ordinary task is about a dozen calls. So a
      line is paid for once per call, not once per session. The table prices 1,000 tokens of instructions across the
      twelve-call agent task [our post on what free limits buy](https://clixad.io/blog/free-ai-coding-tier-limits/) works
      through, metered call by call the way our gateway meters it.
One twelve-call agent task, and what 1,000 more tokens of instructions on every call add to it, in Clixad credits and in US dollars of list value (100,000 credits are $1). List price, no prompt caching. Recomputed from packages/pricing by a test.
Model Task, credits 1,000 more tokens adds In dollars
--- --- --- ---
GPT-5 Nano 3,051 90 $0.0009
Claude Haiku 5.5 5,773 179 $0.0018
DeepSeek V4.1 Flash 8,496 270 $0.0027
Claude Sonnet 5.5 115,380 3,600 $0.0360
Claude Opus 5.5 230,760 7,200 $0.0720

packages/pricing by a test. On a frontier model, 1,000 tokens of instructions add about 3% to every task. On the cheapest models the same lines cost a fraction of a cent. Providers discount a repeated prefix when they cache it, and an instruction file at the start of every request is exactly that, so the real cost is often lower. The direction does not change: a line that earns nothing is paid for on every call.

Nested files and monorepos #

      The AGENTS.md site's rule is that "The closest AGENTS.md to the edited file wins; explicit user chat prompts
      override everything." Agents implement it in different ways. Codex walks from the project root down to your
      working directory, and "Codex concatenates files from the root down, joining them with blank lines", so the
      closer file comes later and wins where they disagree. Claude Code loads a subdirectory's file when it works in
      that subdirectory, and "All discovered files are concatenated into context rather than overriding each other."
      Clixad reads the one `AGENTS.md` in the directory you start it in, next to its own
      `CLIXAD.md`, so start it at the root of the repository.

For a monorepo, put what holds everywhere in the root file and what holds for one package in that package's file. Do not repeat the root file's rules below it, or two copies will drift apart.

Starting one #

      Claude Code's `/init` and Clixad's `/init` both have the agent look through the project and
      write a first version. Treat it as a draft: delete what an agent could find in one search, and add the rules you
      have had to correct the agent on. Then review the file in pull requests like any other code, because a stale
      instruction is followed as faithfully as a current one. [Our docs on
      instruction files](https://clixad.io/docs/context/#instructions) say exactly what Clixad reads and in what order.

FAQ #

### What is AGENTS.md? #

A Markdown file in a repository that coding agents read before they work: build and test commands, conventions and layout, written for the agent. The project behind it calls it a README for agents, and it has no required format.

### Does Claude Code read AGENTS.md? #

By default only when there is no CLAUDE.md in the working directory or above it. Anthropic suggests a CLAUDE.md that imports AGENTS.md with @AGENTS.md when a repository has both.

### How long should AGENTS.md be? #

As short as it can be while still covering what the agent would get wrong. Anthropic suggests under 200 lines for its own file, Codex stops reading instruction files at 32 KiB by default, and every line is sent with every model call.

### Where do I put AGENTS.md in a monorepo? #

One at the root for what holds everywhere, and one in a package for what holds only there. The closest file to the edited code takes precedence, and repeating the root file's rules lower down lets the copies drift apart.

### Which agents read AGENTS.md? #

Codex, Cursor and Clixad read it directly, Gemini CLI when its context.fileName setting names it, Claude Code when there is no CLAUDE.md, and GitHub Copilot on the surfaces that read agent instructions.

Sources #

  1. AGENTS.md, agents.md , for "Think of AGENTS.md as a README for agents", the popular sections, "AGENTS.md is just standard Markdown. Use any headings you like" and "The closest AGENTS.md to the edited file wins; explicit user chat prompts override everything." Read 2 December 2026.
  2. OpenAI, Custom instructions with AGENTS.md , for the override file, the 32 KiB default ofproject_doc_max_bytes and "Codex concatenates files from the root down, joining them with blank lines". Read 2 December 2026.
  3. Anthropic, How Claude remembers your project , for "Keep it to facts Claude should hold in every session", the examples of verifiable instructions, the multi-step advice, "target under 200 lines per CLAUDE.md file", the AGENTS.md rule, the@AGENTS.md bridge and "All discovered files are concatenated into context rather than overriding each other." Read 2 December 2026.
  4. Google, Provide context with GEMINI.md files , for the default name and thecontext.fileName setting. Read 2 December 2026.
  5. Cursor, Rules , for "Cursor supports AGENTS.md in the project root and subdirectories." GitHub,Adding repository custom instructions , for.github/copilot-instructions.md and agent instructions. Both read 2 December 2026.
  6. Credit figures: Clixad's pricing engine, packages/pricing , recomputed by the test beside this post, on the twelve-call task shape declared inthe tier-limits post . What Clixad reads and the 20,000-character cut: the command line tool's source atgithub.com/clixad/cli .
── more in #ai-agents 4 stories · sorted by recency
── more on @codex 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-to-write-an-agen…] indexed:0 read:9min 2026-12-02 · —