What to put in AGENTS.md, one section at a time

By Christophe Paka · Facts checked on 23 October 2026

AGENTS.md is a plain text file in your project that briefs Codex, OpenAI's coding agent, at the start of every session. You write one rule: "could you ask before adding dependencies," meaning the outside code packages your project uses. Then Codex adds a package without asking. On r/codex, one post warns that your rules can be overridden. Another calls the file trash that just takes up room.

Both are half right. Codex weighs the file; it does not obey it, so polite or vague lines lose. The cure is knowing what to put in AGENTS.md: eight sections, each with one job. The figure lays them out, and two of them pay back your time fastest.

An AGENTS.md file drawn as eight stacked sections: dos and don'ts, file scoped commands, safety and permissions, structure hints, concrete examples, API docs locations, PR checklist, escape hatches. Sections 2 and 5 are highlighted.
Figure 5.2 Anatomy of a working AGENTS.md: eight sections, each with one job; file scoped commands and concrete examples repay the effort fastest.
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. Section 1, dos and don'ts. Write the versions you pin, the libraries you prefer, and the patterns to copy or avoid. Make each line a fact Codex can check, such as the name of your date library. A wish like "write clean code" changes nothing.

  2. Section 2, file scoped commands, highlighted. These commands check and test one file only, such as npx eslint src/lib/parse.ts. Two common checks: a typecheck looks for type mistakes, and a lint looks for style mistakes. Codex can then check its own edit in seconds, instead of running a full build or skipping the check. Run each command yourself first, and keep only the ones that pass.

  3. Section 3, safety and permissions. Say what runs freely and what needs asking first: installs, deletions, git push. Write each rule as a test: "Stop and ask before any change to the dependencies in package.json." This works beside the approval setting, not instead of it; see approvals vs sandbox.

  4. Section 4, structure hints. Add a short map of where things live: routing, components, the payments folder. A few lines save a fresh agent from exploring the whole project at the start of every task.

  5. Section 5, concrete examples, highlighted. Point at real files that show the pattern you want, plus the old code not to copy. A path beats a paragraph: "new export formats follow src/lib/parse.ts." Codex can open the file and copy its shape.

  6. Sections 6 to 8: docs, checklist, way out. Section 6 says where the API docs live, so Codex never guesses their shapes. Section 7 is the checklist for a pull request, a change sent for review: commit format, tests must pass, small diffs. Section 8 is the escape hatch: when unsure, stop and ask, or propose a plan before touching code.

Key takeaways

  • Write the file scoped commands and two real example files first; they pay back your time fastest.
  • Phrase every approval rule as "stop and ask before" plus a named action, never "could you".
  • Turn each surprise into one new line in the file, then commit it so the next session gets it.

Try this: from a generated starter to a real briefing

You need Codex and a project saved in git, the tool that keeps every version of your files. Each step fills one or more sections of the figure.

  1. Type /init in a Codex session at the top folder of your project. It writes a starter AGENTS.md. Read it before you accept it.
  2. Cut every line the code already shows: the framework name, the folder list, "write clean code".
  3. Fill sections 1 and 2. Name the libraries to use. Then ask Codex which commands check one file here, and run each one yourself.
  4. Fill sections 3, 5 and 8: one "stop and ask before" rule, two example files, one file not to copy, and "if unsure, ask; for changes to several files, propose a plan first."
  5. Commit the file. Start a new session and rerun a prompt that went wrong before, without restating the rule.

Expected result: The fixed behavior appears on its own, such as the right test command or a plan before a big edit. If it does not, rewrite the rule so it names a command or a file instead of a wish.

Questions readers ask

Does AGENTS.md help, or does it just take up context?

It helps when you write it by hand, short and concrete. A curated file says what the code cannot: your preferences, your traps, your definition of done. Addy Osmani, who writes on running teams of agents, cites data in The Code Agent Orchestra (in the sources below): hand curated files raised task success by about 4%, while files the agent wrote itself lowered it by about 3% and needed over 20% more computing per task. Small gains, but one direction: write it yourself, and cut what the code already shows.

Why does Codex ignore my AGENTS.md rules?

Codex weighs the file against its own instructions and your prompt, and your prompt wins. Polite wording reads as optional: "could you ask first" is a wish. Write a test instead, such as "Stop and ask before any change to the dependencies in package.json." A rule that names a command or a file holds best.

Can I let Codex write its own AGENTS.md?

Yes, as a start. The /init command writes a starter file. Treat it as a draft. A generated file describes what the code already shows. Your file should say what the code cannot: your traps, your preferences and your definition of done. Those are plain words, so a lead can write and review them too. One correction committed to the file stops the whole team from hitting the same mistake.

Can AGENTS.md stop Codex from deleting files?

No. The file is advice. It cannot change the approval policy or move the sandbox walls, the limits on what Codex can touch. Those are settings. Write "stop and ask before deleting files" in section 3, and set the approval mode as well. Never put a secret in the file: every agent and teammate reads it.

Sources: AGENTS.md guide (Codex docs); The Code Agent Orchestra (Addy Osmani); Improve your AI code output with AGENTS.md (Builder.io).

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