Codex

Codex AGENTS.md: global, project and override instruction files explained

How do I set up AGENTS.md so Codex follows my project instructions?

Put a global AGENTS.md in your Codex home (~/.codex by default) and an AGENTS.md at your repository root, plus nested files in subfolders that need different rules. Codex reads one file per directory from the project root down to your current directory and joins them, so files closer to where you work take priority. An AGENTS.override.md in the same directory wins over AGENTS.md.

Where Codex looks for instructions

  • Global: your Codex home, which is ~/.codex by default or the folder in CODEX_HOME if set. Codex reads AGENTS.override.md if present, otherwise AGENTS.md, and uses only the first non-empty file.
  • Project: Codex walks from the project root (usually the Git root) down to the current directory. If it finds no root, it checks only the current directory.
  • Each directory gives at most one file, checked in this order: AGENTS.override.md, AGENTS.md, then any names in project_doc_fallback_filenames.
  • Files are joined from the root down, separated by blank lines. Later files, closer to your current directory, override earlier guidance.

Create a global AGENTS.md

Use the global file for personal habits that apply to every repository, such as your preferred package manager or test command.

Create the Codex home folder

mkdir -p ~/.codex

~/.codex/AGENTS.md

# Personal defaults

- Run npm test after changing JavaScript files.
- Prefer pnpm when installing dependencies.
- Ask before adding production dependencies.

Add project and nested files

Put shared team rules in AGENTS.md at the repository root. For a folder that needs different rules, add an AGENTS.override.md inside it.

AGENTS.md at the repository root

# Repository rules

- Run npm run lint before opening a pull request.
- Document public utilities in docs/ when behavior changes.

services/payments/AGENTS.override.md

# Payments service rules

- Use make test-payments instead of npm test.
- Never rotate API keys without notifying the security channel.

Use other file names and raise the size limit

Loading stops once the combined size reaches project_doc_max_bytes, which defaults to 32 KiB. Empty files are skipped. You can also tell Codex to treat other file names as instruction files with project_doc_fallback_filenames.

~/.codex/config.toml

project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
project_doc_max_bytes = 65536

After changing these settings, restart Codex or run a new command. Codex builds the instruction chain when it starts: once per run, and in the TUI usually once per launched session.

Check which files Codex loaded

From the repository root

codex --ask-for-approval never "Summarize the current instructions."

From a nested folder

codex --cd services/payments --ask-for-approval never "List the instruction sources you loaded."
  • Nothing loads: confirm you are in the right repository and that the files are not empty.
  • Wrong guidance: look for an AGENTS.override.md higher in the tree or in your Codex home.
  • Instructions cut off: raise project_doc_max_bytes or split rules across nested folders.
  • Unexpected home folder: run echo $CODEX_HOME to see which one is in use.

Sources

More on Codex

Other guides

Cursor: allow all terminal commandsClaude Code: allow commands without promptsCodex CLI: approval and sandbox modesGemini CLI: YOLO mode, auto_edit and allowing specific shell commandsCursor Privacy Mode: telemetry, training and data retentionClaude Code telemetry and data retention: what is sent and how to turn it offGemini CLI: turn off usage statistics and telemetryCLAUDE.md: where it goes, how it loads, and how it works with AGENTS.mdClaude Code hooks: format on save, block risky edits, get notifiedClaude Code subagents: create one, limit its tools, and call itAdd MCP servers to Cursor with mcp.json: Keep files out of Cursor with .cursorignore: Configure Codex with config.toml: Configure Gemini CLI with settings.json: Add MCP servers to Claude Code (claude mcp add, .mcp.json, scopes): Claude Code custom slash commands and skills (SKILL.md): GitHub Copilot custom instructions: Adding MCP servers to GitHub Copilot: Claude Code settings.json: file locations, precedence, and key settingsClaude Code plugins and marketplaces: install, create, and shareGemini CLI extensions and custom commands: Configuring OpenCode with opencode.json: Cline Rules: workspace, global, and conditional rulesKiro steering files: .kiro/steering, inclusion modes, and AGENTS.mdZed agent: instruction files, MCP servers, tool permissions, and ACP agentsCursor CLI: install, headless mode, permissions and CIAider: CONVENTIONS.md, .aider.conf.yml and API keysJunie guidelines, MCP and the Action Allowlist: Amp AGENTS.md, settings.json and MCP: Configure Goose extensions, hints, recipes and permissions: Customize OpenHands with skills, AGENTS.md, setup.sh and MCP: Configure Factory Droid CLI: AGENTS.md, settings.json, autonomy, custom droids and MCPConfigure Qwen Code: settings.json, providers, QWEN.md, MCP and approval modesCursor hooks: hooks.json, beforeShellExecution, afterFileEdit and exit codesCursor sandbox: sandbox.json, network allowlist and run modesCursor settings: settings.json, Cursor Settings and the ~/.cursor config filesCursor browser agent: @browser, browser automation and approval modesCursor subagents: .cursor/agents, frontmatter, built-in Explore, Bash and BrowserCursor telemetry and OpenTelemetry export (Privacy Mode, OTLP, Analytics API): Cursor rules setup: .cursor/rules, .mdc frontmatter, globs, alwaysApply and AGENTS.mdClaude Code headless mode: claude -p, --output-format json, --bare and CI flagsClaude Code statusline: custom status bar in settings.json with context %, cost and git branchClaude Code /model: switch models, aliasesClaude Code /cost and /usage: check token spend, usage limits and reduce costsClaude Code VS Code extension: install, shortcuts, settings and /ideCodex MCP servers: codex mcp add and [mcp_servers] in config.tomlCodex sandbox modes: read-only, workspace-write, danger-full-access and network accesscodex exec: run Codex non-interactively in scripts and CI with JSON outputCodex skills: create SKILL.md, skill folder locations and $skill invocationGEMINI.md in Gemini CLI: context file locations, imports and /memoryGemini CLI MCP servers: gemini mcp add and mcpServers in settings.jsonGemini CLI custom slash commands: TOML files, {{args}}, !{shell} and @{file}Gemini CLI headless mode: gemini -p, JSON output and exit codes for scripts and CIGemini CLI sandbox: enable Docker, Podman, macOS Seatbelt or gVisorcopilot-setup-steps.yml: set up the GitHub Copilot cloudGitHub Copilot CLI permissions: --allow-tool, --deny-tool, --allow-all-tools and trusted directoriesGitHub Copilot custom agents: .github/agents/*.agent.md profiles, tools and frontmatterGitHub Copilot code review settings: automatic PR reviews, rulesets, effort level and approvals

Get the weekly agent stack update

New official MCP servers, spec changes and harness releases, checked against the source. One email a week, no fluff.

Reviewed Oct 13, 2026. Settings change often; the linked vendor docs are the source of truth.