Branchwell

Become a Pro / website · becomeapro.ai / content / lessons / knowledge-work / using-ai / agents-md-codex.mdx

Raw 5.3 KB on f63bc385c0fa362af985bfb576a8b5aa2a3df60f
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
6updated: 2026-10-31
7order: 4
8---
9
10`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.
11
12It'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.
13
14This guide follows OpenAI's [AGENTS.md guide for Codex](https://learn.chatgpt.com/docs/agent-configuration/agents-md).
15
16## Where Codex looks
17
18Codex builds its instructions from two places, every time it starts:
19
201. **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.
212. **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.
22
23Codex 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.
24
25Two details catch people out:
26
27- Codex stops at your current directory. An `AGENTS.md` in a folder below it isn't read until you work from that folder.
28- The instructions are built once, when Codex starts. Edit an `AGENTS.md` and you need a new session to see the change.
29
30## A global AGENTS.md
31
32Start with the few things you want in every project. This is the example from OpenAI's guide:
33
34```markdown
35# ~/.codex/AGENTS.md
36
37## Working agreements
38
39- Always run `npm test` after modifying JavaScript files.
40- Prefer `pnpm` when installing dependencies.
41- Ask for confirmation before adding new production dependencies.
42```
43
44## A project AGENTS.md
45
46At 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:
47
48```markdown
49# AGENTS.md
50
51## Setup
52- Install dependencies: `pnpm install`
53- Start the dev server: `pnpm dev` (http://localhost:3000)
54- Run tests: `pnpm test`. Run them after every change.
55
56## Code style
57- TypeScript strict mode. No `any` without a comment saying why.
58- Server components by default; add "use client" only when needed.
59
60## Repository expectations
61- Run `pnpm lint` before opening a pull request.
62- Document public utilities in `docs/` when you change their behavior.
63- Never commit `.env` files or secrets.
64```
65
66OpenAI's advice is to keep the rules short and leave formatting and lint checks to CI, where they're enforced anyway.
67
68## Override one folder
69
70Some 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:
71
72```markdown
73# services/payments/AGENTS.override.md
74
75## Payments service rules
76
77- Use `make test-payments` instead of `npm test`.
78- Never rotate API keys without notifying the security channel.
79```
80
81An override works globally too: `~/.codex/AGENTS.override.md` temporarily replaces your global `AGENTS.md` without deleting it. Delete the override to go back.
82
83## Size limits and other file names
84
85Codex 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`:
86
87```toml
88# ~/.codex/config.toml
89project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
90project_doc_max_bytes = 65536
91```
92
93With that config, Codex checks each folder for `AGENTS.override.md`, then `AGENTS.md`, then `TEAM_GUIDE.md`, then `.agents.md`. Other names are ignored.
94
95## Check what Codex loaded
96
97Ask Codex directly. These commands from OpenAI's guide run without stopping for approvals:
98
99```bash
100# From the repo root
101codex --ask-for-approval never "Summarize the current instructions."
102
103# From a subfolder, to check overrides
104codex --cd services/payments --ask-for-approval never "List the instruction sources you loaded."
105```
106
107If 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.
108
109## Share one file with Claude Code
110
111If 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](/knowledge-work/using-ai/claude-md-guide) covers the Claude side.