Guilds AI / AI Blog

,

Codex AGENTS.md: Setup, Examples and Instruction Rules

Code editor displaying an AGENTS.md file with sections for agents, guidelines, tools and workflow.

Codex AGENTS.md is a Markdown instruction file that gives a coding agent reusable guidance about a repository. It can explain where code lives, which commands to run, how to check changes and which boundaries to respect. Instead of repeating these details in every request, you maintain them alongside your project. For the underlying execution system that reads these instructions, see our Codex agent explanation.

OpenAI’s Codex documentation describes how global and repository-level files combine, how overrides work and how to inspect the resulting guidance. This guide uses the documented Codex CLI behavior reviewed November 29, 2026, with an original illustrative repository example. Commands in the example must be adapted to the actual project.

What is AGENTS.md in Codex?

AGENTS.md serves as an agent-facing project guide. Unlike a README intended primarily to explain the software to its users, an instructions file can focus on the practical decisions a coding agent needs to make when changing the code. It can identify test commands, files generated by build tools and areas that require additional review.

The file is particularly helpful when several developers delegate work to an agent in the same repository. The team can review changes to instructions through its existing version-control process, rather than relying on separate personal prompts. For a wider introduction to tools that modify repositories, see our AI agents for coding guide.

How Codex discovers and prioritizes instructions

Codex builds its guidance from broad instructions toward instructions for the working directory. The official documentation specifies the following order.

ScopeExample locationPurpose
Personal~/.codex/AGENTS.mdDefaults for multiple repositories
Repositoryproject/AGENTS.mdShared conventions and commands
Subdirectoryproject/services/search/AGENTS.mdRules specific to that part of the project

Within a directory, Codex checks AGENTS.override.md before AGENTS.md, then configured fallback filenames. It selects at most one non-empty instruction file per directory. Guidance nearer the working directory appears later in the combined instructions and can refine or override broader guidance. The default combined project-document budget is 32 KiB.

This matters in a monorepo. Suppose the root project describes a common JavaScript test workflow, but the search service uses Python. A nested instructions file can tell Codex which Python tests to run when working in the search service. Starting the session in the relevant directory helps ensure the appropriate guidance is loaded. For a practical example of using project instructions alongside delegated coding roles, read our guide to Codex multi agent workflows.

How to create a Codex AGENTS.md file

1. Identify the repository’s actual workflow

Inspect the existing README, package scripts, test configuration and contribution guide. Identify the commands that developers actually use. Do not invent a test command simply because another project uses it. If you cannot run a command in your environment, document that limitation.

2. Create the project instructions file

Create a plain Markdown file named AGENTS.md at the repository root. Codex also offers the /init command to scaffold a starting file. Review any generated instructions before committing them, particularly commands and assumptions about the repository structure.

3. Separate stable instructions from individual tasks

Use the file for expectations that persist across requests. A requirement to add a dark-mode toggle belongs in the relevant task prompt; a requirement to preserve accessibility when changing controls may belong in the repository guidance. Keeping these separate helps prevent obsolete feature requirements from affecting unrelated work.

4. Verify the guidance in a fresh run

Start Codex from the intended directory. Ask it to identify applicable instructions, explain the relevant checks and describe any restrictions before modifying files. Verify its answer against the actual repository.

AGENTS.md example for a software repository

Consider a fictional inventory application containing a TypeScript web interface, a Python API and generated client code. The team wants agents to preserve API compatibility and use existing tests. Its root file could look like this:

# Repository guidance

## Project layout
- web/ contains the TypeScript interface.
- api/ contains the Python service.
- generated/ contains generated client files.

## Change boundaries
- Preserve existing public API contracts unless a change is approved.
- Do not edit generated client files manually.
- Ask before adding production dependencies.

## Verification
- Web changes: run npm test from web/.
- API changes: run python -m pytest from api/.
- Inspect the final diff for unrelated changes.
- Report any checks that could not be run.

This is a sample, not a universal template or a tested repository. Replace the paths and commands with those verified in your environment. For example, if the API uses a dedicated test environment, include its setup command and clarify what it requires.

Specific instructions are easier to verify than broad preferences. Instead of saying that code should be maintainable, identify where reusable components belong and what changes require additional review. Our comparison of agentic engineering vs vibe coding explains why observable acceptance criteria matter.

Nested instructions, overrides and configuration

For a temporary service-specific exception, create an override at that directory level. For example, if a search component needs an additional check, a file at api/search/AGENTS.override.md might contain:

# Search service instructions

- Run the API tests before reporting completion.
- Run the search relevance test suite for ranking changes.
- Do not modify production index configuration.
- Report any unverified ranking changes.

An override replaces the regular instruction file at the same location; it does not erase the entire global and repository instruction chain. Include the local rules that still need to apply. A different filename can be recognized through the documented project_doc_fallback_filenames configuration, and the project_doc_max_bytes setting controls the document-size limit. Keep the defaults unless the repository has a clear need to change them.

A useful directory structure for this example is:

inventory-app/
  AGENTS.md
  web/
  api/
    search/
      AGENTS.override.md
  generated/

A Codex session launched within the search directory can load the applicable parent instructions and the local override. A session started at the root does not discover every unrelated nested file as part of its initial directory-chain scan.

How to verify and troubleshoot instructions

OpenAI documents checking active guidance by asking Codex to summarize the loaded instructions. From the repository root, for instance, you can start a read-only inspection request:

codex "Summarize the applicable instruction files and the required checks. Do not modify any files."

To examine a nested scope, launch from the intended subdirectory or use the CLI’s directory option:

codex --cd api/search "Describe the active instructions and their scope. Do not modify files."

These commands are illustrative verification prompts, not executed tests. The model’s summary is useful evidence but not proof that every instruction will be followed. For a stronger check, independently inspect the files, observe actual command execution and compare the changes with the expected results.

SymptomWhat to check
Instructions appear missingWorking directory, repository root and empty files
Unexpected local rulesAGENTS.override.md at the relevant level
Old guidance persistsRestart the run after editing the file
Custom filename ignoredFallback filename configuration and spelling
Long guidance is incompleteCombined instruction-size budget

Best practices for reliable coding workflows

Keep instructions short and concrete. Store detailed architecture documentation separately and refer to the specific document when relevant. Do not repeat long manuals in each nested file. Review instructions when build commands or ownership boundaries change.

Do not place API keys, access tokens or personal data in AGENTS.md. Treat guidance from unfamiliar repositories cautiously, since instructions may attempt to steer an agent toward unintended actions. Use sandboxing, permission controls and appropriate approval settings rather than relying solely on Markdown to prevent changes. Our guide to integrating external APIs with AI coding agents covers related access boundaries.

Finally, use a task prompt that describes the desired outcome and relevant acceptance checks. The persistent file describes how the team works; the prompt describes what should happen now. Review the output and report any limitations instead of assuming that a successful agent response proves a successful implementation.

Frequently asked questions

Does Codex require AGENTS.md?

No. It is an optional way to supply durable instructions to Codex. You can still give the agent task-specific guidance directly.

Where should I put AGENTS.md?

Place project-wide instructions at the repository root and narrower guidance in relevant subdirectories. Personal defaults can go in the Codex home directory, usually ~/.codex.

What happens when AGENTS.md and AGENTS.override.md exist together?

Codex chooses the non-empty override file before the regular instructions file at that directory level. Remove or rename the override when it is no longer needed.

Can I change AGENTS.md while Codex is running?

You can edit it, but start a fresh run to ensure Codex rebuilds the instruction chain. Do not assume an existing session automatically reloads the updated file.

Does AGENTS.md prevent dangerous commands?

No. It provides natural-language guidance. Use appropriate sandbox settings, permissions, approval policies and independent verification to enforce security boundaries.