Codex AGENTS.md override rules: the instruction chain, file by file

By Christophe Paka · Facts checked on 23 October 2026

A post on r/codex warned: "Your AGENTS.md rules can be overridden by Codex's default model instructions." Others reply that the file is trash and only takes up context. You wrote a rule, and Codex walked past it.

A rule that stops working without a sound can cost you a payments change tested with the wrong command. Often the cause is not the model. It is which file Codex read, in what order, and whether it read it at all. The codex AGENTS.md override rules fit in one figure: the instruction chain.

The AGENTS.md instruction chain: a global file, the repo root AGENTS.md and a nested services/payments override pass a 32 KiB cap into one briefing where closer files win; your prompt overrides them all.
Figure 5.1: The instruction chain. Codex reads the files from your global one down to the folder you work in; the closer file wins, and your prompt outranks them all.
Use this diagram on your site

Free to share in your blog post, docs, course or slides, as long as the credit link stays. Paste the code below where the figure should go.

How to read this figure

  1. Box 1: the global file. Codex reads ~/.codex/AGENTS.md first, or AGENTS.override.md beside it if that exists. The ~ sign means your home folder. This file holds your habits and follows you into every repo. It is optional: beginners can skip it.

  2. Box 2: the repo root AGENTS.md. Next comes the project briefing in the repo's top folder, committed with the code. AGENTS.md is a plain text file that tells the agent your commands and rules. A repo is a project folder that git, the version tool, tracks.

  3. Box 3: the nested override. Codex walks from the root down to the folder you work in. Here that is services/payments, where an AGENTS.override.md holds rules for that one service. The override takes the place of an AGENTS.md in its own folder only. The files from the folders above still join the chain, so one service can keep its own rules without editing the shared root file.

  4. The side panel: one check per folder. In each folder, Codex looks for AGENTS.override.md first, else AGENTS.md, else the fallback filenames you list for other tools' conventions. Empty files are skipped.

  5. The 32 KiB cap valve. The joined briefing has a size cap, set by project_doc_max_bytes. By default it is 32 KiB: 32,768 bytes, and one byte holds one plain letter, so roughly 5,000 words. At the cap, Codex stops adding files, so the last file in the chain is the one left out: the nested file closest to your work. Codex does not warn you; a rule simply stops working.

  6. One briefing, and the prompt above it. The files join in order, and on a conflict closer files win. The dashed box says one thing beats them all: an explicit instruction in your prompt overrides every file in the chain. Codex rebuilds the chain at the start of every run.

Key takeaways

  • Put rules for one folder in an AGENTS.override.md there; it sits closest to the work, so it wins a conflict.
  • Keep the joined chain under 32 KiB, or Codex silently leaves out the nested file closest to your work.
  • When a rule must change for one task, say it in your prompt: the prompt beats every file in the chain.

Worked example: which test runs where, on one project

Follow the chain on tally, the book's sample project, with the docs' example files. The global file says to run npm test after changing JavaScript files. The root file says to run npm run lint, a style check, before a pull request. The payments override switches the test command.

  1. At the tally root, Codex reads the global file, then tally's AGENTS.md. It runs npm test.
  2. In services/payments, it reads the global file, the root file, then the payments override. It runs make test-payments.
  3. Your prompt says "skip the tests this time". Codex reads the same files, plus your prompt. No test runs: the prompt wins.
  4. The root file grows past 32 KiB. Codex reads the global and root files only, and the override is never added, with no warning. It runs npm test, the wrong one.
  5. The rule says "could you ask before adding dependencies". The polite wording reads as optional, so Codex may add one without asking.

Result: The last two cases are the failures. Trim the root file to fix case 4, the cap. Rewrite case 5 as a check: "Stop and ask before any change to the dependencies in package.json."

Questions readers ask

Can Codex's default instructions override my AGENTS.md rules?

AGENTS.md is advice the model weighs, not law it obeys. Concrete rules work; polite ones read as optional. A reply to that r/codex post named the cause: "'could you...' is the culprit". So make the rule spell out what counts as approval.

Is AGENTS.md worth it, or does it just take up context?

It is not trash. Every session starts with an agent that knows nothing about your project, and a short file fixes that. Write it by hand, cut every line the code already shows, and add a line each time Codex surprises you. On a team, commit the file, so every teammate's agent gets the same briefing and one person's correction helps everyone. See what a working AGENTS.md holds.

Why did my AGENTS.md override stop working?

Check the size first. Read each file's size in your file browser, or run wc -c on it in a terminal. If the joined files pass 32 KiB, Codex stops adding files, and the nested override is the one left out, with no warning. Keep it short anyway: the briefing takes room in every session, and that room costs usage. Split the guidance into nested files, one per service.

How do I know Codex read my AGENTS.md?

Ask it. In a session, ask which test command it uses and why; Codex should quote your rule. An edit counts from the next session, because Codex rebuilds the chain at the start of every run. If the old behavior returns, check that the chain is under 32 KiB and that the rule names a command or file instead of a wish.

Sources: AGENTS.md guide (OpenAI); Config reference (OpenAI); agents.md, the open standard.

This figure is from OpenAI Codex Made Crystal Clear, chapter 5.

The chapter builds the idea step by step, with recipes you can follow, a Try it to check yourself, and every source.

Get the book

All diagrams