← All posts

How to Write an Effective AGENTS.md File

One of the most effective ways to improve an AI coding agent is not to change the model. It is to give the model better instructions about the repository it is working in.

When planning an application for discovering and crowdsourcing ping-pong locations, I wanted to hand an AI agent more than a feature request. The project needed decisions about data verification, location search, rewards, photographs and application architecture. An AGENTS.md file offered a way to turn those decisions into persistent repository guidance.

What AGENTS.md should contain

Think of AGENTS.md as an onboarding guide for an automated contributor. It should explain how to work safely and successfully in the repository, not reproduce the entire product specification.

A good file answers six questions: what the application does, how the code is organized, how to run it, how to verify changes, which constraints are non-negotiable, and what requires human approval. Detailed product requirements belong in versioned documentation that the agent can consult when needed.

Codex supports layered instruction discovery from global and project-level guidance. Other agents may have different discovery rules, precedence or size limits, so test the behavior of the agent you actually use.

An example repository guide

The following is an illustrative guide for a React and Python application; adapt commands and directories to the actual repository rather than copying them blindly.

# AGENTS.md

## Purpose
Build a location discovery application with verified community submissions.

## Architecture
- frontend/: React client
- backend/: Python API
- docs/: architecture and product requirements
- tests/: integration tests

## Local development
- Use the committed lockfile and existing package manager.
- Install frontend dependencies with `npm ci`.
- Install Python dependencies in a virtual environment.
- Follow docs/development.md to start both services.

## Implementation rules
- Validate all coordinates and user submissions on the server.
- Never fabricate location verification or user reviews.
- Keep credentials and production data out of source control.
- Preserve existing API contracts unless explicitly changing them.
- Add tests for changed behavior and update documentation.

## Validation
- Frontend: npm run lint; npm test; npm run build
- Backend: python -m pytest
- Report which checks ran and any failures or skipped checks.

## Approval boundaries
- Do not deploy, delete data, change billing or rotate credentials
  without explicit approval.
- Propose new production dependencies before adding them.

The most useful lines describe observable behavior. "Use best practices" is vague; "validate all coordinates on the server" is actionable. Similarly, an instruction to run tests should name the actual commands and working directories.

Give instructions the right scope

A monorepo can have a root guide for shared conventions and nested guidance for specialized components:

repository/
  AGENTS.md
  frontend/
    AGENTS.md
  backend/
    AGENTS.md
  docs/
    development.md
    architecture.md

With Codex, closer applicable instructions can refine higher-level guidance. Be careful to avoid contradictions and keep the root file short enough to fit the agent's instruction budget. Confirm the agent actually reads the relevant nested guidance when making changes. Agent instructions do not override higher-priority runtime permissions, security controls or user approval requirements.

Make the instructions testable

An instruction file is not an enforcement mechanism. An agent can misunderstand a requirement or encounter a misleading file. Enforce critical rules in CI, access policies, branch protections, schema validation and tests. Never rely on prose alone to prevent exposure of secrets or unauthorized deployment.

I would validate an initial guide by giving the coding agent a small task, asking it to identify the relevant constraints and checking whether its changes and test report comply. If the guide fails, clarify the instructions or enforce the requirement in code.

Review AGENTS.md whenever build commands, dependencies or architectural boundaries change. Stale instructions can be worse than no instructions because they give the agent confidence in an incorrect workflow.

The goal is not to create a long prompt. It is to make project context discoverable, specific, and reproducible. A well-written AGENTS.md turns repeated explanations into a versioned engineering asset that benefits both humans and agents.

Further reading