How to write an AGENTS.md file that Codex follows

Day 2, 25 minutes · beginner

Goal of this lessonWrite a short AGENTS.md for your practice repository, check that Codex loads it and see it follow your rules in a real change.

Why it matters

Every Codex session starts fresh. If you want Codex to follow the same house rules each time, you either repeat them in every prompt or you write them down once. AGENTS.md is that note: a plain markdown file in your repository that Codex reads before it does any work.

The difference shows up in small jobs. Without a note, "raise the price of the Gull Delta" may only change the web page and leave the price list file behind. With one line in AGENTS.md that says where prices live, Codex changes both and checks them against each other, without you asking.

Today you write a short AGENTS.md for the Puffinreach Kites site, check that Codex really loads it, and watch it follow your rules in a real change. At the end the file is committed, so every later session on this repository starts from the same rules.

How Codex finds AGENTS.md

The Codex docs describe a simple chain. When a session starts, Codex reads:

  1. Your personal file in your Codex home folder, ~/.codex/AGENTS.md. Use it for habits that fit every project.
  2. Project files, starting at the root of the git repository and walking down to the folder where you started Codex. Each folder can have one.

Files closer to your current folder come later, so their rules win when two rules clash. Empty files are skipped, and by default Codex stops adding text after 32 KiB in total. Codex builds this chain once per session, so after you edit the file, start a new session.

If you know CLAUDE.md from Claude Code 101, this is the same idea for Codex.

What belongs in it

The Codex best practices guide suggests a short, accurate file over a long one full of vague rules. Good content:

  • how to run and check the project (build, test or lint commands, or a manual check)
  • conventions and "do not" rules
  • what done means and how to verify it

Start with the basics and add a rule only after Codex makes the same mistake twice. The guide even suggests asking Codex for a short retrospective when that happens, and turning the answer into a new line.

The steps

  1. Let Codex draft the file. The /init command writes a starter AGENTS.md in the current folder. It is a starting point, not the final text.
  2. Cut it down. Keep only rules that change what Codex does. For a one-page site that is three things: where prices live, what not to add, and what done means.
  3. Check that it loads. Ask Codex to summarize its current instructions. It should quote your rules.
  4. Test it with a task that relies on a rule. Ask for a price change without saying which files to touch. If AGENTS.md works, Codex changes both files and reports that the prices match.
  5. Commit the file. A committed AGENTS.md travels with the repository, so every Codex session on it starts from the same rules. Codex code review on GitHub follows it too.

Follow the guide for Codex below for the exact commands and a ready-made AGENTS.md for the kite shop.

Example: Benthe's file

Benthe's /init draft was about thirty lines, with a section on project structure that only described two files. She replaced it with the short version from the guide: one line about the site, three rules, and a "done means" section.

Her test prompt was only "Raise the price of the Gull Delta to 36.50." Codex opened prices.json first, changed it, then updated index.html, and ended with "Prices in index.html match prices.json." Before AGENTS.md, she would have had to say all of that herself.

Common mistakes

  • Keeping the whole /init draft. Long files cost context in every session and bury the rules that matter.
  • Editing AGENTS.md mid-session and expecting a change. Start a new session first.
  • Rules without a check. "Be careful with prices" does nothing. "Compare every price with prices.json and say so" gives Codex something to do and you something to read.
  • Secrets in the file. AGENTS.md is committed and shared. Never put a password or key in it.

Deeper dive

Today's actions

Ticks are not saved without an account

Do it in OpenAI Codex

OpenAI Codex

  1. In the terminal, go into your practice repository and start Codex.
    cd puffinreach-kites
    codex
  2. Type /init and press Enter. Codex writes an AGENTS.md draft in the current folder. Read it in the transcript or open the file in your editor.
  3. Type /exit. Open AGENTS.md in your editor, replace the draft with this shorter version and save it.
    # AGENTS.md
    
    ## About this repository
    - One-page website for Puffinreach Kites, a small kite shop. Plain HTML and CSS, no build tools.
    
    ## Rules
    - prices.json is the only source of prices. When a price changes, change prices.json first, then index.html.
    - Do not add new files, scripts, fonts or tracking code unless the task asks for it.
    - Write prices with two decimals, for example 34.95.
    
    ## Done means
    - Every price in index.html matches prices.json. Compare them and say so in your final message.
    - List every file you changed.
  4. Check that Codex loads the file. Codex should quote your rules back to you. Read the answer, then type /exit.
    codex --ask-for-approval never "Summarize the current instructions."
  5. Start codex again and give a small task that your rules cover. Do not mention prices.json in the prompt.
    Raise the price of the Gull Delta to 36.50.
  6. When Codex is done, type /diff. Both prices.json and index.html should show the new price, and the final message should say the prices match.
  7. Type /exit and commit the file and the change yourself.
    git add -A
    git commit -m "Add AGENTS.md and raise Gull Delta price"

Note: Codex reads AGENTS.md once when a session starts, so restart Codex after you edit it. A personal file in your Codex home folder (~/.codex/AGENTS.md) applies to every repository. By default Codex reads up to 32 KiB of these files in total.

Paid planSame as lesson 1: the Codex CLI with ChatGPT Plus, Pro, Business, Edu or Enterprise, or with an OpenAI API key.

Checked on 4 December 2026 · Source: Codex docs: Custom instructions with AGENTS.md (opens in a new tab)

Create a free account to save your progress. Sign in or sign up