Blog · Codex

Codex AGENTS.md: where it goes, the order it loads, and what to write

AGENTS.md is the instructions file OpenAI's Codex reads before doing any work: your build and test commands, conventions and rules, in plain Markdown. Codex combines a global file in ~/.codex with files from your repository, from the root down to the folder you're working in. This guide covers every location, the exact load order and size limit, overrides, fallback filenames, code review rules, and examples you can copy.

Where Codex looks for AGENTS.md, in load order

Codex builds the instruction chain once when it starts (in the terminal UI, once per session). Files are joined from the top of this table down, so instructions closer to your working directory come later and win.

OrderLocationWhat Codex reads
1. Global~/.codex/ (or $CODEX_HOME)AGENTS.override.md if it exists, otherwise AGENTS.md; only the first non-empty one
2. Project rootUsually the Git rootAGENTS.override.md, else AGENTS.md, else a fallback filename; at most one file
3. Each folder downEvery directory from the root to where you started CodexThe same check in each directory, one file each
StopYour current directoryFolders below it aren't read

How to set up AGENTS.md for Codex

  1. Create global defaults

    Run mkdir -p ~/.codex and write ~/.codex/AGENTS.md with preferences you want in every repository. Check it loaded by asking Codex to summarize its instructions.

    # ~/.codex/AGENTS.md
    
    ## Working agreements
    
    - Always run `npm test` after modifying JavaScript files.
    - Prefer `pnpm` when installing dependencies.
    - Ask for confirmation before adding new production dependencies.
  2. Add a project file, and overrides where teams differ

    Put an AGENTS.md at the repository root for shared setup. In a folder with different rules, add AGENTS.override.md: it replaces that folder's AGENTS.md, which Codex then ignores.

    # AGENTS.md (repository root)
    
    ## Repository expectations
    
    - Run `npm run lint` before opening a pull request.
    - Document public utilities in `docs/` when you change behavior.
    
    # services/payments/AGENTS.override.md
    
    ## Payments service rules
    
    - Use `make test-payments` instead of `npm test`.
    - Never rotate API keys without notifying the security channel.
  3. Confirm what loaded

    Start Codex in the folder you care about, for example codex --cd services/payments, and ask it to list the instruction sources it loaded. It should list the global file, then the root file, then the folder's file.

  4. Reuse an existing file name, or raise the limit

    If your repository already keeps instructions in another file, add it to project_doc_fallback_filenames in ~/.codex/config.toml. Codex stops adding files once the combined size reaches project_doc_max_bytes, 32 KiB by default.

    # ~/.codex/config.toml
    project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
    project_doc_max_bytes = 65536
  5. Add rules for Codex code review

    For @codex review on GitHub, add a ## Code Review Rules section to the AGENTS.md closest to the code it governs. Say what to flag and the safe alternative; leave formatting and lint to CI.

    ## Code Review Rules
    
    ### Experiment cohorts
    
    - Do not filter treatment comparisons on post-exposure behavior.
      Safe path: build cohorts from assignment or exposure.

Source: Codex docs, Custom instructions with AGENTS.md

AGENTS.md best practices

  • Keep it to what Codex can't work out: exact build, test and lint commands (including how to run one test), traps in the codebase, and decisions that aren't written down.
  • Put the most specific rules closest to the code: a nested AGENTS.md in services/payments/ beats a long root file with a payments section.
  • Mind the 32 KiB budget: files are added from the root down and the rest is cut off, so split long files into nested ones or raise project_doc_max_bytes.
  • Use AGENTS.override.md for temporary changes, globally or in one folder, and delete it to go back.
  • An empty AGENTS.md is skipped, and the search for that directory moves on to the next file name.
  • Use a separate CODEX_HOME for automation users so their global instructions don't mix with yours.

AGENTS.md in Codex vs Claude Code and others

AGENTS.md is an open format that many agents read, which makes it the best place for instructions you want to share. Claude Code has its own file, CLAUDE.md; see the CLAUDE.md guide for the details.

CodexClaude Code
Main fileAGENTS.mdCLAUDE.md; reads AGENTS.md only if there's no CLAUDE.md
Personal or temporary fileAGENTS.override.mdCLAUDE.local.md
Global file~/.codex/AGENTS.md~/.claude/CLAUDE.md
Nested foldersRoot down to the current directoryParents at launch; subfolders when Claude works in them
Size limit32 KiB combined by defaultPer-file limits; aim for under 200 lines
Sharing one fileNativePut @AGENTS.md at the top of CLAUDE.md
With Crewmark

AGENTS.md tells Codex how. Crewmark tells it what's next.

A good AGENTS.md makes every Codex session start informed; the session still waits for your prompt. Crewmark turns a Codex, Claude Code, DeepSeek Harness or OpenCode session into an AI employee with a role, a goal and working hours, and wakes it on a heartbeat to take the next issue from a board.

  1. Keep AGENTS.md in the repository

    The employee's Codex session reads it like yours, so conventions and test commands come along.

  2. Let the heartbeat start the work

    During working hours the employee wakes every 15, 30 or 60 minutes in the same conversation; see how to make Codex proactive.

  3. Mix agents on one board

    One AGENTS.md can serve Codex and Claude Code employees side by side; compare them in Claude Code vs Codex.

Codex AGENTS.md FAQ

What is AGENTS.md in Codex?

A Markdown file of instructions Codex reads before any work: commands, conventions and rules for your project. Codex combines a global file with files from your repository.

Where does Codex look for AGENTS.md?

First in ~/.codex (or $CODEX_HOME), then in every directory from the project root down to the folder where you started Codex, reading at most one file per directory.

In what order are AGENTS.md files loaded?

Global first, then the project root, then each nested folder down to the current directory. They're joined in that order, so the closest file comes last and takes precedence.

What is AGENTS.override.md?

A file Codex reads instead of AGENTS.md in the same directory, globally or in a folder. Use it for temporary or team-specific rules without editing the shared file.

Is there a size limit for AGENTS.md?

Yes: Codex stops adding files once the combined size reaches project_doc_max_bytes, 32 KiB by default. Raise it in ~/.codex/config.toml or split instructions into nested files.

Can I use one file for Codex and Claude Code?

Yes. Keep shared instructions in AGENTS.md and add @AGENTS.md at the top of CLAUDE.md, with any Claude-only notes below it.

Does Codex code review read AGENTS.md?

Yes. Add a ## Code Review Rules section to the AGENTS.md nearest the code, and @codex review on GitHub applies it.

Checked against OpenAI's Codex docs (Custom instructions with AGENTS.md) on November 6, 2026.

Give your well-briefed Codex a job to do.

Crewmark turns Codex, Claude Code and DeepSeek Harness sessions into AI employees with roles, goals, working hours and a heartbeat.