Repo rules Codex reads before work, and which file wins
After this, you'll be able to write AGENTS.md guidance with commands, boundaries, and proof, place each rule in the right layer, and say which file wins when two disagree.
Complete Write a task brief Codex can finish first.
AGENTS.md is the repo memory Codex reads before it starts. It's a plain text file with that exact name, kept in the project's top folder.
Skip the company-handbook tone. Keep only the rules Codex needs on almost every run.
| Ready | Needs work |
|---|---|
| Job fit | |
| The file names concrete commands | The task is still vague |
| Proof | |
| The file names risky areas | The result is assumed |
| Risk | |
| Low | Breaks when the file contains stale commands because Codex follows bad proof |
| Next move | |
| Continue | Clarify first |
Use Ready only when the proof is visible.
A useful AGENTS.md answers four questions. How do you work here, and what proves a change? What's risky, and what style rules actually matter?
"Write good code" tells Codex nothing useful. "Use pnpm, never edit generated files, run lint after content changes, and keep auth routes off-limits without approval" gives it something to follow.
Here pnpm is a tool that installs a project's add-on packages, generated files are files a tool writes for you, lint is an automatic style and error check, and auth routes are the sign-in pages and code. Keep the file short, because a long doc rots the day people stop updating it.
Stable rules live in AGENTS.md. Task details live in the prompt. A rare procedure lives in a linked doc Codex opens only when it needs it.
Which file wins when two disagree. Codex reads more than one AGENTS.md and joins them in a set order.
First comes your global file, in a hidden folder called .codex in your home folder (written ~/.codex/AGENTS.md). Then come the project files, from the project's top folder down to the folder you are working in.
The file closest to your work comes last, so it overrides the earlier ones. In the same folder, a file named AGENTS.override.md beats AGENTS.md. In the global folder, Codex reads only the first non-empty file it finds, override first.
Here is one conflict. The top-level AGENTS.md says Use npm, and a file inside the shop folder says Use pnpm.
Working in the shop folder, pnpm wins, because that file is closer. Everywhere else, npm still holds.
Place each rule once, where it wins. "Don't touch production data" (the live version real customers use) goes in the project's top file, and "Use pnpm here" goes in that app's own folder.
"Only fix the quote total today" goes in the prompt and nowhere else. Copies in several layers drift apart, and a run then follows a rule you forgot you loaded.
Two limits to know. Codex stops reading once the combined text reaches 32 KiB (a few thousand words), so long files lose their ends. And Codex reads these files when it starts, so quit and reopen Codex after you change one. To see what it loaded, ask: List every instruction file you loaded for this run.
Which file each tool reads. Codex reads AGENTS.md. Claude Code reads CLAUDE.md, so it does not read your AGENTS.md by itself once a CLAUDE.md exists.
For one shared file, ask Claude Code to put the single line @AGENTS.md inside CLAUDE.md, and it pulls the shared rules in. Antigravity reads both AGENTS.md and GEMINI.md.
If you already have a CLAUDE.md. Don't retype it. Ask Codex: Read my CLAUDE.md and write an AGENTS.md with the same rules, keeping only what applies to every task.
Then check the result against the four questions above. You create the file by asking, so there is no command to learn.
If a new hire would need the rule on day one, Codex needs it too.
Paste this into Codex
Part 1. Draft an AGENTS.md for this repo: Project type: [a website, a phone app, a script, or unknown] Install command: [command or unknown] Test/build commands: [commands, or unknown] Do not touch: [paths or systems] Generated files: [paths or none] Style rules: [repo rules] Human approval required for: [auth, billing, schema, deployment, etc.] Write a concise AGENTS.md with sections for commands, boundaries, proof, and approval triggers. If you wrote unknown anywhere, first ask Codex: Read this project and tell me what kind of project it is and which commands install, test and build it. Then ask Codex to save the file as AGENTS.md in the project's top folder. To check it worked, quit and reopen Codex, start a new chat, and ask: What rules did you load from AGENTS.md? Part 2. Place these rules, one layer each (global file, project AGENTS.md, a folder's own file, or the prompt). No rules of your own? Use: Reply in plain English. Never edit the invoices folder. Use pnpm in the shop app. Only fix the cart total today. Run the tests before saying done. Then tell me which file wins if the project file says npm and the shop folder's file says pnpm, and name any rule that is stale or duplicated.
What a good response looks like
Part 1, AGENTS.md for the practice site. Commands: open index.html in a browser to see the page; ask me to run the title-and-heading check. Boundaries: only edit index.html and the check; do not add files without asking. Proof: show the check passing before saying done. Ask first: before installing anything. Part 2, placement. Global file: reply in plain English. Project AGENTS.md: never edit the invoices folder, run the tests before saying done. Shop folder's own file: use pnpm. Prompt only: fix the cart total today. If the project file says npm and the shop file says pnpm, the shop file wins inside that folder because it is closer. Nothing here is stale.
Check yours against
Use Codex to help you write AGENTS.md guidance with commands, boundaries, and proof, place each rule in the right layer, and say which file wins when two disagree. Start with the exercise prompt and your real input. Ask for one draft, then check it against this proof: The file names concrete commands. Accept only the version you can verify yourself.
You can distinguish repo rules from task briefs
Pulling this out of your own head now is the part that actually moves it into long-term memory. Re-reading only feels like it does.
Think of a project of yours. Write two rules you'd put in its AGENTS.md and one detail you'd keep in the task prompt instead.
One good answer: 'Rule: run the booking test before saying done. Rule: never touch the payments folder. Prompt only: this week's change to the cancellation page.' If your rules are true for every task and the prompt detail is true only for today, that's the idea.
AGENTS.md is not documentation for everything. It is the set of repo rules Codex needs before it edits, placed once, in the layer where it should win.