Skip to main content

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
Think of custom instructions as a persistent system prompt that Codex reads at the start of every session.

AGENTS.md Files

Custom instructions are defined in AGENTS.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
src/ features/ auth/ dashboard/ settings/

Example Configurations

Personal Preferences

~/.codex/AGENTS.md

Team Standards

AGENTS.md (repo root)

Feature-Specific

src/features/auth/AGENTS.md
  • 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

  1. Verify file location: ls -la AGENTS.md
  2. Check file is valid Markdown
  3. Ensure CODEX_DISABLE_PROJECT_DOC is not set
  4. Try codex --no-project-doc to confirm it’s the AGENTS.md causing issues
  • Simplify global ~/.codex/AGENTS.md to only personal preferences
  • Keep repo-level AGENTS.md focused on critical standards
  • Use directory-level files sparingly for truly module-specific notes
  • 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

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