How Codex loads AGENTS.md
Run /init inside Codex and it creates an AGENTS.md with instructions for your project. Codex builds its instructions from these files each time it starts.
- Global: your Codex home folder (
~/.codexby default). It checksAGENTS.override.mdfirst, thenAGENTS.md, and uses the first non-empty one. - Project: it starts at the project root (usually the git root) and walks down to the folder you're working in, taking at most one file per folder.
- Closest wins: files nearer your current folder come later, so their rules override the general ones.
- Size: it stops adding files once they reach 32 KiB combined (the default
project_doc_max_bytes). Keep each file short. - Changes: restart Codex after editing, because the instructions are built once per run.
The templates
Root AGENTS.md (whole project)
AGENTS.md
# AGENTS.md ## Project [Marketing site + booking for a small business]. Main users are on phones. ## Stack - [Next.js + TypeScript + Tailwind] - Package manager: [npm] (never switch it) ## Commands - Install: `[npm install]` - Dev: `[npm run dev]` - Check before finishing: `[npm run lint && npm run build]` ## Code style - Small components in `[components/]`. Reuse before creating. - Tailwind classes only. No new CSS files. - Every image has alt text. Every button has a clear label. ## Rules - Make the smallest change that solves the task. - Don't edit `.env`, lock files or `[content/legal/]`. - Ask before adding dependencies. - When done, list changed files and how to test them.
Subfolder api/AGENTS.md (extra rules for that part only)
api/AGENTS.md
# API rules - Validate every request body before using it. - Never log emails, phone numbers or payment details. - Return clear error messages with the right status code.
Use it in Claude Code too, and check it loaded
- Claude Code reads
AGENTS.mdas your project instructions when there's noCLAUDE.mdin your folder or above it. This needs Claude Code v2.1.277 or later. - Already have a CLAUDE.md? Add a line
@AGENTS.mdto it, so Claude imports the same rules and you keep one source of truth. - Check in Codex: from the repo root run
codex --ask-for-approval never "Summarize the current instructions.". It should repeat your rules back.
Checked against the official docs (Nov 2026): Codex docs: AGENTS.md · Codex CLI · Claude Code docs: AGENTS.md
Need a website built properly?
We build fast, mobile-first websites for businesses, with this exact AI workflow.
