Codex and compatible agents configuration

Configure AGENTS.md

Configure AGENTS.md for Codex and compatible coding agents with the correct global, repository, nested, and override scope, then verify what loads.

Last verifiedAugust 13, 2026
Quick answer

Put shared repository instructions in `AGENTS.md` at the project root. Add a nested file only when a subtree needs different rules. Codex walks from the project root to the current working directory and combines one instruction file per directory; guidance closer to the working directory appears later and takes precedence.

Choose the right scope

ChoiceUse it forAvoid it for
Root AGENTS.md

Commands, repository map, shared safety boundaries, and definition of done.

Framework details that apply to only one package.

Nested AGENTS.md

Rules for one app, service, language, or independently owned subtree.

Repeating the entire root file.

AGENTS.override.md

A deliberate replacement at one directory level, including temporary global overrides.

A permanent second copy that silently drifts.

Prompt or task brief

Temporary outcome, acceptance criteria, and task-specific scope.

Durable repository facts repeated every session.

Configuration 1

Understand the discovery chain

Codex loads global guidance first, then walks from the project root—normally the Git root—down to the current working directory.

  1. At the global level, `~/.codex/AGENTS.override.md` wins over `~/.codex/AGENTS.md`.
  2. At each project directory, Codex checks `AGENTS.override.md`, then `AGENTS.md`, then configured fallback names, and includes at most one.
  3. Root guidance appears before deeper guidance, so the more specific file can override it.
  4. Discovery happens once per run; start a new session after changing instructions.

Important: Codex stops adding project instruction files at the configured size limit, 32 KiB by default. Keep root guidance compact and scope details closer to the code.

Configuration 2

Make the root file a repository contract

The root file should answer how to orient, work safely, verify changes, and hand off—not explain the entire product.

  1. Copy commands from repository files and CI, then run them.
  2. Name non-obvious source-of-truth and generated directories.
  3. Keep critical controls in permissions, hooks, or CI; AGENTS.md is instruction context, not a security boundary.
Recommended root shape
# Repository Instructions

## Commands
- Test: `npm test`
- Lint: `npm run lint`
- Build: `npm run build`

## Boundaries
- Do not edit generated output in `dist/`.
- Ask before migrations, deployments, or external writes.

## Definition of Done
- Relevant checks pass.
- The diff contains no unrelated changes.
- Report commands, results, and remaining risks.

Configuration 3

Add nested instructions only for real differences

A nested file should contain the delta for its subtree, such as a different language, test runner, ownership boundary, or release process.

  1. Do not copy root safety and handoff rules into every package.
  2. State which root command must still run after a package-specific check.
  3. Resolve contradictions explicitly instead of relying on file order as hidden behavior.
Example layout
AGENTS.md
apps/
  web/
    AGENTS.md
services/
  billing/
    AGENTS.override.md

Configuration 4

Share facts across tools without duplicating them

Use AGENTS.md as the shared repository contract when multiple agents support it. Tool-specific files should import or add only the behavior unique to that tool.

Claude Code bridge
@AGENTS.md

## Claude Code
- Use plan mode for changes under `src/billing/`.

Important: Claude Code reads `CLAUDE.md`, not AGENTS.md directly. The import belongs in CLAUDE.md.

Validation checklist

  • Start Codex at the repository root and ask it to summarize active instructions.
  • Start a new run from a nested package and confirm both shared and package rules are present.
  • Check that every command in the file exists and completes in the intended environment.
  • Make one bounded test change and verify the required handoff evidence appears.
  • Review global, root, nested, and override files together for contradictions.

Common configuration mistakes

Codex ignores a new edit

Start a new run; instruction discovery occurs once per run.

A nested rule applies unexpectedly

Check the working directory and every instruction file from project root to that directory.

Later instructions are missing

Reduce combined size or split guidance into scoped nested files.

Rules sound right but actions are not blocked

Enforce non-negotiable restrictions with approvals, sandboxing, hooks, and CI.

Related paths

All configuration guides

Official sources

Loading order, configuration formats, and commands were checked on August 13, 2026. Recheck official documentation before enforcing a configuration across a team.