Overview
Custom instructions let you provide Codex with context, preferences, and guidelines that persist across sessions. This is especially useful for:- Defining coding standards and style preferences
- Documenting project-specific conventions
- Providing context about architecture decisions
- Setting workflow preferences
AGENTS.md Files
Custom instructions are defined inAGENTS.md files. Codex looks for these files in three locations and merges them in order:
1
Global Instructions
~/.codex/AGENTS.md - Personal preferences that apply to all projectsExample use cases:- Your preferred coding style
- Tools you always want to use
- Communication preferences
2
Repository Instructions
AGENTS.md at repo root - Team-wide project guidanceExample use cases:- Project architecture overview
- Team coding standards
- Important constraints or requirements
Commit this file to version control so all team members share the same context.
3
Directory Instructions
AGENTS.md in current working directory - Subsystem-specific notesExample use cases:- Feature-specific guidelines
- Module architecture notes
- Local development setup
File Format
AGENTS.md files use standard Markdown format. Codex treats all content as guidance:AGENTS.md
Example Configurations
Personal Preferences
~/.codex/AGENTS.md
Team Standards
AGENTS.md (repo root)
Feature-Specific
src/features/auth/AGENTS.md
Related
- API integration:
src/api/auth.ts - Backend docs:
docs/auth-api.md
Environment Variable
This only disables project-specific AGENTS.md files. Your personal
~/.codex/AGENTS.md is still loaded.Advanced Examples
Multi-Language Project
Microservices Architecture
Troubleshooting
Instructions not being applied
Instructions not being applied
- Verify file location:
ls -la AGENTS.md - Check file is valid Markdown
- Ensure
CODEX_DISABLE_PROJECT_DOCis not set - Try
codex --no-project-docto confirm it’s the AGENTS.md causing issues
Too much conflicting guidance
Too much conflicting guidance
- Simplify global
~/.codex/AGENTS.mdto only personal preferences - Keep repo-level
AGENTS.mdfocused on critical standards - Use directory-level files sparingly for truly module-specific notes
Codex ignoring specific instructions
Codex ignoring specific instructions
- Be more explicit and specific in your wording
- Provide examples that illustrate the rule
- Move critical rules to the top of the file
- Consider if the instruction conflicts with model knowledge
Real-World Examples
- Open Source Project
- Enterprise Application
- Startup MVP
See Also
Configuration
Global Codex configuration options
Exec Policies
Control command execution
Memory System
How Codex remembers context
Best Practices
Tips for using Codex effectively