# Writing AGENTS.md for Codex: what loads, what fits, what to leave out

URL: https://codexmemory.com/agents-md
Last updated: 2026-11-07
Published by Glen (https://tryglen.com), shared memory for coding agents.

> Codex reads AGENTS.md before it starts work: the global file in ~/.codex (or AGENTS.override.md in its place), then one file per directory from the repo root down, until the total reaches project_doc_max_bytes, 32 KiB by default. Put the rules every task must follow there. Leave personal habits to Codex memories and the history of past sessions to a searchable team memory such as Glen.

## How Codex assembles its instructions

1. Your global file, `~/.codex/AGENTS.md`. An `AGENTS.override.md` there is used in its place.
2. The `AGENTS.md` at the repository root.
3. An `AGENTS.md` in each directory below that, down to the one you are working in.

Codex stops adding files once the combined text reaches `project_doc_max_bytes`, which is 32 KiB unless you change it. A deep monorepo with a long root file can hit that ceiling before the most specific directory gets read. Raising the setting is possible, but every byte you add rides along on every request.

## What earns a place in AGENTS.md

- The commands Codex should run: install, test, lint, typecheck, and the order that matters.
- Conventions you'd otherwise repeat in review, such as where new modules go or how errors are returned.
- Lines it must not cross. Generated files stay untouched; secrets never get logged.
- Short pointers into deeper docs, so the detail loads only for tasks that need it.

> **A quick test:** Would you want this applied on a task that has nothing to do with it? If yes, it is a rule and belongs in AGENTS.md. If it only matters when someone touches one subsystem, put it in that subsystem's AGENTS.md or out of the file entirely.

## AGENTS.md, Codex memories or Glen

*Three places Codex knowledge can live*

|  | AGENTS.md | Codex memories | Glen |
| --- | --- | --- | --- |
| Written by | People, by hand | Codex, once enabled | Glen's hooks, every turn |
| Stored in | The repo and `~/.codex` | `$CODEX_HOME/memories/` | Your organization's hosted memory |
| Enabled | Always | Off by default (`memories = true`) | After `glen install` |
| Reaches | Everyone with the repo | One machine | Teammates, filtered by what each may see |
| Good for | Rules that must always hold | Your own habits | Why past work went the way it did |

OpenAI recommends keeping required team guidance in AGENTS.md, and that advice holds with Glen installed. Recall from Glen depends on a prompt matching past work. A rule in AGENTS.md applies whether or not anything matches.

## One file, several agents

AGENTS.md is not Codex-only. Cursor reads it alongside its rules, and [Grok Build reads it too](https://grokmemory.dev/grok-build). A team that mixes agents can commit one AGENTS.md and get the same rules everywhere, instead of keeping three files in sync.

## Knowledge that doesn't fit in a file

The 32 KiB cap is a good discipline, and it also means most of what a team learns never makes it in. Which fix was tried first, why a timeout is 45 seconds, what a reviewer objected to: all of that lives in session transcripts. [Glen](https://tryglen.com/docs/codex) records those for the organization and returns the relevant part with the prompt that needs it, so AGENTS.md can stay lean. When something recalled from Glen proves to be a standing rule, promote it into AGENTS.md.

> **Keep AGENTS.md short** Let Glen hold the history every Codex session can recall. Free for 15,000 memories. Install: `npx @tryglen/cli@latest install`. Start free at https://tryglen.com

## Frequently asked questions

### Where does Codex look for AGENTS.md?

In ~/.codex for your global file (AGENTS.override.md takes its place if present), then in the repository root and each directory below it down to where you are working.

### What is project_doc_max_bytes in Codex?

The limit on how much AGENTS.md text Codex loads, 32 KiB by default. Files past that budget are not read.

### Should I use AGENTS.md or Codex memories?

AGENTS.md for anything the team needs, because it is shared through git. Codex memories stays on one machine, which suits personal preferences.

### Can other coding agents read AGENTS.md?

Yes. Cursor and Grok Build both read AGENTS.md, so a single committed file can carry the same rules to several agents.
