Branchwell

AI Resource Pro / website / content / tutorials / chatgpt / agents-md-codex.mdx

1---
2title: "How to set up AGENTS.md for Codex (with examples)"
3description: "Give OpenAI Codex standing instructions with AGENTS.md: where the files go, how Codex combines them, overrides for one folder, size limits, and how to check what it loaded."
4level: Beginner
5minutes: 9
6publishedAt: 2026-10-31
7---
8
9`AGENTS.md` is a plain Markdown file that tells a coding agent how to work in your project: how to install, build and test, the conventions to follow, and what to avoid. Codex reads it before it starts working, so you don't repeat the same instructions in every prompt.
10
11It's also an open format, not a Codex-only file. [agents.md](https://agents.md) lists support in Codex, Cursor, GitHub Copilot's coding agent, Gemini CLI, Jules, Zed, Warp, VS Code and others, and recent versions of Claude Code read it too. The format is now stewarded by the Agentic AI Foundation under the Linux Foundation. There are no required fields: any Markdown works.
12
13This guide follows OpenAI's [AGENTS.md guide for Codex](https://learn.chatgpt.com/docs/agent-configuration/agents-md).
14
15## Where Codex looks
16
17Codex builds its instructions from two places, every time it starts:
18
191. **Your global file.** In your Codex home folder, `~/.codex` unless you set `CODEX_HOME`, Codex reads `AGENTS.override.md` if it exists, otherwise `AGENTS.md`. Use this for preferences that apply to every project.
202. **Your project.** Starting at the project root, usually the Git root, Codex walks down folder by folder to the directory you're working in. In each folder it takes the first file it finds of `AGENTS.override.md`, then `AGENTS.md`. It reads at most one file per folder, and skips empty files.
21
22Codex joins everything it found in that order: global first, then the project root, then each folder down to where you are. Files closer to your working directory come later, so their instructions win when two disagree.
23
24Two details catch people out:
25
26- Codex stops at your current directory. An `AGENTS.md` in a folder below it isn't read until you work from that folder.
27- The instructions are built once, when Codex starts. Edit an `AGENTS.md` and you need a new session to see the change.
28
29## A global AGENTS.md
30
31Start with the few things you want in every project. This is the example from OpenAI's guide:
32
33```markdown
34# ~/.codex/AGENTS.md
35
36## Working agreements
37
38- Always run `npm test` after modifying JavaScript files.
39- Prefer `pnpm` when installing dependencies.
40- Ask for confirmation before adding new production dependencies.
41```
42
43## A project AGENTS.md
44
45At the root of your repo, describe the project the way you'd brief a new teammate. Keep each line something Codex can act on or check:
46
47```markdown
48# AGENTS.md
49
50## Setup
51- Install dependencies: `pnpm install`
52- Start the dev server: `pnpm dev` (http://localhost:3000)
53- Run tests: `pnpm test`. Run them after every change.
54
55## Code style
56- TypeScript strict mode. No `any` without a comment saying why.
57- Server components by default; add "use client" only when needed.
58
59## Repository expectations
60- Run `pnpm lint` before opening a pull request.
61- Document public utilities in `docs/` when you change their behavior.
62- Never commit `.env` files or secrets.
63```
64
65OpenAI's advice is to keep the rules short and leave formatting and lint checks to CI, where they're enforced anyway.
66
67## Override one folder
68
69Some parts of a codebase need their own rules. Put an `AGENTS.override.md` in that folder and Codex uses it there instead of that folder's `AGENTS.md`. The root file still loads. OpenAI's example for a payments service:
70
71```markdown
72# services/payments/AGENTS.override.md
73
74## Payments service rules
75
76- Use `make test-payments` instead of `npm test`.
77- Never rotate API keys without notifying the security channel.
78```
79
80An override works globally too: `~/.codex/AGENTS.override.md` temporarily replaces your global `AGENTS.md` without deleting it. Delete the override to go back.
81
82## Size limits and other file names
83
84Codex stops adding files once the combined instructions reach 32 KiB, the default for `project_doc_max_bytes`. If your team already uses a different file name, Codex can read that when a folder has no `AGENTS.md`. Both settings go in `~/.codex/config.toml`:
85
86```toml
87# ~/.codex/config.toml
88project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
89project_doc_max_bytes = 65536
90```
91
92With that config, Codex checks each folder for `AGENTS.override.md`, then `AGENTS.md`, then `TEAM_GUIDE.md`, then `.agents.md`. Other names are ignored.
93
94## Check what Codex loaded
95
96Ask Codex directly. These commands from OpenAI's guide run without stopping for approvals:
97
98```bash
99# From the repo root
100codex --ask-for-approval never "Summarize the current instructions."
101
102# From a subfolder, to check overrides
103codex --cd services/payments --ask-for-approval never "List the instruction sources you loaded."
104```
105
106If the answer is missing something, check the file isn't empty, that it's between the project root and your working directory, and that the combined size is under the limit.
107
108## Share one file with Claude Code
109
110If your team also uses Claude Code, you don't need two copies. Claude Code reads `AGENTS.md` when the project has no `CLAUDE.md`, and a `CLAUDE.md` that starts with `@AGENTS.md` imports it. [How to write a CLAUDE.md that Claude Code follows](/claude/claude-md-guide) covers the Claude side.