Skip to content
zero2vibecodelearn vibe coding
Level 0 · Install and first run 7 min Reviewed by the author · Oct 22, 2026 Verified against Codex CLI v0.163.0 · Oct 22, 2026Official docs: Agent configuration: AGENTS.md, Developer commands

AGENTS.md — the instructions Codex reads every time

Codex reads AGENTS.md files before it does any work: one in your Codex home folder, then one per folder from the project root down to where you are. Write the things you would otherwise repeat every session, and keep the file short.

Level 0 · 0 / 4 lessons0%
In this lesson

Three sessions in, you notice you keep typing the same sentences. Use pnpm, not npm. Run the tests before saying it is done. Do not touch the generated folder.

Write them down once instead.

What AGENTS.md is

A plain file in your project. Codex reads AGENTS.md files before doing any work, so whatever is in them shapes every task without you repeating it.

There is no special syntax. Headings and bullet points are fine. The Codex docs' own example looks like this:

# AGENTS.md

## Repository expectations

- Run npm run lint before opening a pull request.
- Document public utilities in docs/ when you change behavior.

Where Codex looks, and in what order

When it starts, Codex builds a chain of instructions:

  1. Your global file. In your Codex home folder, ~/.codex/AGENTS.md. Preferences that should follow you into every repository go here.
  2. The project, folder by folder. Starting at the project root — usually the root of the Git repository — Codex walks down to the folder you are in and picks up an AGENTS.md in each one along the way.
  3. Root first, nearest last. The files are joined in that order. Something closer to your current folder appears later, so where two files disagree, the closer one wins.

Two details matter in practice. A folder can hold an AGENTS.override.md, which Codex reads instead of that folder’s AGENTS.md. And Codex builds this chain once, when it starts: after editing a file, restart Codex in the folder you are working in.

Quick check

You started Codex, then added a rule to AGENTS.md. It keeps ignoring the rule. What is the likely reason?

Let it draft one

Inside a session, /init generates an AGENTS.md scaffold in the current folder. Use it, and then read every line. A generated file full of confident, wrong statements about your project is worse than no file.

To check what Codex actually loaded, the docs suggest asking it from the repository root:

codex --ask-for-approval never "Summarize the current instructions."

What earns a line

The test: would I otherwise say this at the start of every session?

  • Commands. How to run the tests, the build, the linter. This turns “it suggests a command” into “it runs the right one”.
  • Boundaries. Generated folders, vendored code, anything that must not be edited by hand.
  • Conventions you cannot see in the code. “Dates are stored as UTC strings.”

And keep it short. Codex stops adding files once the combined instructions reach a size limit, and long before that, every line is competing with the actual task for attention.

Write the exercise version in the terminal: the test command and one hands-off folder.

Switching from another agent

Should AGENTS.md be committed to Git?

Yes, for project rules: everyone on the project gets the same instructions, and they change together with the code. Personal preferences belong in ~/.codex/AGENTS.md instead.

Do other tools read AGENTS.md too?

AGENTS.md is a plain Markdown convention with its own site at agents.md, which the Codex docs point to. Whether another agent reads it by default is up to that agent, so check its documentation for the file it loads rather than assuming.

Check your understanding

Answered 0/3
Mode:

Your repository has an AGENTS.md at the root and another in services/payments. You start Codex inside services/payments. Which one wins where they disagree?

You edit AGENTS.md in the middle of a session. When does Codex see the change?

Where do preferences go that should follow you into every repository?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

Write a small AGENTS.md for this project: how to run the tests, and one folder Codex must not edit. Then read it back.

Tab complete · ↑ history · Ctrl+L clear · help commands

  • Not done: Create AGENTS.md in the project root
  • Not done: Write down the test command
  • Not done: Write down what must not be edited
  • Not done: Read back what you wrote

Lesson Q&A

Your repository has an AGENTS.md at the root and another in services/payments. You start Codex inside services/payments. Which one wins where they disagree?

The one in services/payments, because it is closer to where you are — Codex joins the files from the root down. Files closer to your current folder come later in the combined instructions, so their guidance overrides the earlier ones.

You edit AGENTS.md in the middle of a session. When does Codex see the change?

The next time Codex starts, because it reads the files once at the start of a run or session — The instruction chain is built when Codex starts. Restart it in the folder you are working in and the new rules are loaded; there is no cache to clear.

Where do preferences go that should follow you into every repository?

~/.codex/AGENTS.md, in your Codex home folder — The global file is read first, before any project file, so your personal working agreements apply everywhere and each project can add to them.

You started Codex, then added a rule to AGENTS.md. It keeps ignoring the rule. What is the likely reason?

The instruction chain is built at the start of each run. Restart Codex and it is loaded.

Commands in this lesson

Move between lessons with ← → · search with ⌘K

Written and reviewed by Mikhail Kuzmitskii