Agent Instruction Files: Writing Guidelines, Load Order, and Multi-Tool Sync
Learn how to write agent instruction files, distinguish them from README files and tool-specific configuration, and keep project rules consistent across AI coding assistants. This guide also explains layered loading in Codex CLI, override behavior, and practical checks for verifying that instructions are applied.
Developers often use two or three AI coding assistants in the same project. Each tool may have its own configuration file. When those files drift apart, the tools can produce different coding styles, run different build commands, or modify different parts of the repository.
Agent instruction files provide a central place for project rules so that multiple tools can work from the same expectations. This guide covers what to include, how these files differ from other project documentation, and how tools load them.
1. What Is an Agent Instruction File?
An agent instruction file is a Markdown file, typically placed in the project root, written for AI agents. It has no mandatory fields; teams decide what it should contain.
Common instructions fall into four categories:
- Build and test commands
- Directories the agent may or may not modify
- Coding style requirements
- Files that must be updated alongside particular changes
There is currently no single universal standard. AGENTS.md is a common filename convention supported by several coding assistants and IDE extensions. However, support, file discovery locations, and precedence vary by tool. Check each tool’s official documentation for the applicable behavior.
2. How It Differs from a README or Tool-Specific Configuration
README: documentation for people
A README explains the project’s purpose, features, setup steps, and contribution process. Its content is usually descriptive.
Agent instructions: actionable rules for AI
An instruction file should use clear, executable statements, such as:
- “Run tests with
npm test.” - “Do not modify files under
db/migrations/.”
Combining these rules with extensive narrative documentation forces the agent to extract instructions from longer passages, increasing the risk of omissions or misinterpretation.
Tool-specific files: configuration for one assistant
Some files are intended for a particular tool, such as CLAUDE.md for Claude Code and GEMINI.md for Gemini CLI. These files are generally read by their corresponding tools.
Keep tool-specific settings in those files. Shared project rules are better maintained in a common agent instruction file.
3. Three Ways to Keep Multiple Tools in Sync
Option 1: Use native support
If a tool natively supports the shared instruction file, it can read that file directly from the project without additional configuration.
Option 2: Import the shared file
Some tools support file references. Claude Code, for example, allows other files to be imported into CLAUDE.md using @file-path syntax.
A CLAUDE.md containing only this line imports the shared file from the project root:
@AGENTS.md
This approach works only with tools that support the syntax. Confirm support in the official documentation before using it.
Option 3: Copy the content or request a manual read
If a tool supports neither native discovery nor imports, a script can copy the shared instructions into the tool-specific file before a commit. Add a CI check to verify that the two remain consistent.
Alternatively, ask the assistant to read the shared instruction file at the start of each session.
Copied files are prone to drift, so consistency checks are essential. Symbolic links may also behave differently across operating systems and should be tested before adoption.
4. How Instructions Load: Codex CLI as an Example
Loading order differs across tools. The following example illustrates layered loading as described in the official documentation for OpenAI Codex CLI. Details may change between versions, so consult the documentation for the version you use.
| Layer | Location | Loading behavior |
|---|---|---|
| Global | The user’s Codex configuration directory, ~/.codex/ |
If AGENTS.override.md exists, only that file is read; AGENTS.md in the same directory is ignored. The two are not combined. |
| Project root | Repository root | Reads AGENTS.md. |
| Subdirectories | Directories along the path from the project root to the current working directory | Reads instructions progressively. Content loaded later is appended and generally takes precedence. |
Mutual exclusion applies within a single layer: only one of the applicable files is selected there. Global and project instructions are generally combined in order rather than replacing one another.
Instructions are typically loaded once at the beginning of a session. If you edit an instruction file during a session, you may need to restart the session for the change to take effect.
Verify that the file is being loaded
Temporarily add a test rule such as:
Start every response with
[TEST-OK]on the first line.
Start a new session and ask the assistant to respond. If the marker does not appear, the file may not have been loaded. Remove the test rule after verification.
You can also ask the assistant which instruction files it has loaded, but treat its answer as a reference rather than proof. A marker test provides a more direct check.
Use override files carefully
Override files are useful for temporary environments or specific containers—for example, when a rule needs to be relaxed only in a test environment.
Keep these precautions in mind:
- An override replaces the standard file in the same directory. Team rules omitted from the override will no longer apply through that file.
- Back up changes and track them in version control. This supports auditing and rollback.
- Remove temporary overrides when finished. Otherwise, they may unintentionally affect the normal development environment.
- Verify behavior after enabling an override. Check that critical rules still take effect.
5. Four Sections Every Practical Instruction File Needs
A useful instruction file typically covers four areas.
Environment and build
Specify runtime versions, dependency installation commands, build commands, and test commands.
Run every command locally before adding it. Verified commands reduce the need for the assistant to guess and help prevent unintended changes to the environment.
Directory boundaries
List directories the agent may modify and core directories it must not touch without approval.
For example, a business-logic refactor might permit changes to feature code while prohibiting changes to the underlying framework or database migrations.
Coding style and self-checks
Define indentation, naming, and commenting requirements, then provide executable validation commands.
Rules enforced by linting tools are more reliable than prose alone.
Coordinated updates
Specify which files must change together. For example, changes to a public interface should include updates to its documentation and corresponding tests.
Use the following template as a starting point and adapt it to your repository:
# Project Instructions## Environment and Build- Runtime: Node.js 20.x- Install dependencies: `npm ci`- Build: `npm run build`- Unit tests: `npm test`## Directory Boundaries- Allowed changes: src/features/, tests/- Do not modify src/core/ or db/migrations/ without approval from the responsible maintainer## Coding Style- Use 2-space indentation and camelCase for variables- After generating code, run `npm run lint` and ensure it reports no errors## Coordinated Updates- When changing a public interface, update docs/api.md and the corresponding test files
Before sharing the file with the team, check that:
- Every command has run successfully in the local environment.
- Directory boundaries match the actual repository structure.
- Style requirements are tool-checkable or include an explicit validation command.
- Coordinated-update rules name specific files rather than vaguely referring to “related documentation.”
6. Common Mistakes
Copying the entire README
An oversized instruction file buries important rules in background information, making them easier for the assistant to miss.
Leaving outdated commands in place
An old build command can cause immediate failures when the assistant follows it.
Letting multiple copies drift apart
If the shared file changes but tool-specific copies do not, different assistants may produce contradictory recommendations.
Treating instructions as enforcement
Instructions guide behavior; they do not guarantee compliance. Enforce mandatory constraints through CI checks, code review, and repository permissions.
Forgetting to remove overrides
Temporary instructions can remain in the repository and silently displace team rules in a directory long after their intended use.
7. Getting Started
Create a shared instruction file in the project root. Begin with environment and build commands and directory boundaries, then add the remaining sections as the project’s requirements become clearer.
