Direct answer
Write a router. Load a delta. Verify the result.
For Codex, use AGENTS.md as a small instruction router—not a repository encyclopedia. Keep universal commands, hard boundaries, and source-of-truth links at the root. Put only real package differences in nested files.
Codex builds project guidance from the repository root to the current working directory, prefersAGENTS.override.md within each directory, and stops at a combined 32 KiB by default. Start in the directory whose rules you need, ask Codex to summarize the active chain, and restart after edits. For guided creation and audits, see Supercode Specs & Docs, available after you install Supercode for Codex.
Native resolution
How Codex resolves AGENTS.md
Codex builds the instruction chain once when a run starts. A launched TUI session normally counts as one run, so the working directory and the files present at startup are part of the result.
$CODEX_HOMEOverride first, otherwise AGENTS.md. Only the first non-empty choice is used.
repo/AGENTS.mdBroad repository map, shared commands, boundaries, and completion rules.
root → CWDOne instruction file per directory, concatenated from broad to specific.
your promptDirect system, developer, and user instructions still outrank repository guidance.
AGENTS.override.mdAGENTS.mdconfigured fallbacksCodex loads at most one file from each directory. A same-directory override does not merge with the base file; it replaces that choice in the chain.
Project files are concatenated from root downward. A deeper rule appears later and wins when it conflicts with a broader one. Empty files are skipped, and project guidance stops when the combined size reaches project_doc_max_bytes—32 KiB by default.
A file elsewhere in the repository is not proof that the current run loaded it. In current Codex discovery, the active path runs from the project root to the startup working directory.
Information architecture
Use the root file as a map, not a manual
OpenAI's agent-first engineering team reports that one giant AGENTS.md consumed scarce context, made every rule look equally important, became stale, and was difficult to verify. Its replacement is a short entry point—roughly 100 lines in that repository—that routes the agent into structured, versioned documentation.
The exact line count is not a universal target. The useful separation is: the instruction file routes, repository documents explain, and executable tools prove. If a linter already enforces an import boundary, name its command and link the architecture rationale instead of duplicating the configuration in prose.
Content routing
What belongs in the instruction file—and what does not
Choose the destination by function. Guidance belongs in the active chain only when Codex needs it to select the next action, boundary, authority, or proof.
Put in AGENTS.md
- Repository map and package boundaries
- Exact setup and validation commands
- Files or systems the agent must not change
- Required evidence before completion
- Conditions that require asking first
Link to project truth
- Architecture and domain explanations
- Specifications, ADRs, and runbooks
- Long API and schema references
- Product terminology and rationale
- Ownership and operational history
Enforce in tooling
- Formatting and lint rules
- Import and dependency boundaries
- Generated-file drift
- Types, tests, and coverage gates
- Secret scanning and policy checks
Avoid payload that adds words without resolution
Full copies of READMEs, formatter rules, generated inventories, secrets, historical narrative, duplicated parent guidance, and aspirations such as “write clean code” all consume attention while leaving the decision ambiguous.
Prefer an observable rule: “Do not import from infrastructure/ into domain/; run npm run check:boundaries after moving modules.”
Copyable starting point
A concise root instructions template
The root should remain true for almost every package. Replace every example command with one that actually exists; a false command turns each task into a setup investigation.
Treat the sections below as responsibilities rather than a mandatory schema. Standard Markdown is enough. Keep the repository map stable, point to changing detail, and make the completion contract specific enough that a reviewer can distinguish a finished task from an unverified edit.
# Repository guide
## Repository map
- `apps/` contains deployable applications.
- `packages/` contains shared libraries.
- `docs/` is the source of truth for architecture and decisions.
## Read before editing
- Architecture: `docs/ARCHITECTURE.md`
- Current plans: `docs/plans/`
- Read the nearest nested `AGENTS.md`.
## Authoritative commands
- Install: `npm ci`
- Focused validation: run the changed package's test script.
- Full gate: `npm run check`
## Boundaries
- Do not edit generated files; update their source.
- Ask before adding a production dependency or changing a public API.
- Never commit credentials, local env files, or build output.
## Completion contract
- Add or update tests for changed behavior.
- Run focused checks, then the full gate once.
- Report changed files, validation, and unresolved risks.Local precision
Write nested files as deltas
# Payments service delta
## Local scope
- Applies to `services/payments/`.
- Read `docs/payments/ledger-invariants.md` first.
## Different commands
- Focused tests: `make test-payments`
- Contract tests: `make test-payment-contracts`
## Local boundaries
- Never change ledger history in place.
- Ask before changing an external event schema.
## Completion evidence
- Name the invariant or contract exercised by each changed test.Create a nested file when a subtree has a real difference: another package manager, stricter boundaries, different checks, a specialized runtime, or a separate source of truth. Everything else remains inherited.
Use AGENTS.override.md for an intentional replacement, not as a casual second file. An old override is a common reason edits to the same-directory AGENTS.md appear ignored.
Worked example
Two working directories, two resolved chains
AGENTS.mdshareddocs/ARCHITECTURE.mdtruthapps/web/AGENTS.mdweb deltaservices/AGENTS.mdservice deltaservices/payments/AGENTS.override.mdlocal winner
No ledger commands enter the startup chain.
Frontend conventions stay out of the payments task.
If one task genuinely spans peer packages, start at their nearest shared ancestor and link each package's authoritative documents. Do not paste every local manual into the root merely to make one broad session possible.
Preflight
Audit the chain before starting Codex
find . -type f \
+ \( -name 'AGENTS.md' -o -name 'AGENTS.override.md' \) \
+ -printwc -c AGENTS.md \
+ services/AGENTS.md \
+ services/payments/AGENTS.override.mdThe byte total is a preflight estimate; global guidance and configuration still matter. Use it to catch accidental growth, not to optimize toward the 32 KiB ceiling.
- 01
Does every command exist and run from the directory implied by the rule?
- 02
Does a deeper file replace a broad rule explicitly, or merely contradict it?
- 03
Is any paragraph duplicated from an inherited file?
- 04
Could a source document or executable check replace this prose?
# ~/.codex/config.toml
project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]Raising the byte ceiling can prevent truncation; it cannot turn bloated guidance into useful guidance.
Proof, not presence
Verify what Codex actually loaded
codex --ask-for-approval never
"Summarize the current instructions."codex --cd services/payments
--ask-for-approval never
"Show which instruction files are active."Check the answer for shared rules, the expected local delta, and the absence of unrelated package guidance. When the summary remains ambiguous, enable a plaintext log withcodex -c log_dir=./.codex-log or inspect the latest session JSONL when session logging is enabled. Keep logs out of version control.
Then test one small representative task. Confirm that Codex chooses the documented command, respects the boundary, and reports the required evidence. A file can load correctly and still contain weak instructions.
Failure isolation
When Codex appears to ignore repository guidance
Eliminate structural causes before adding prose. More text cannot repair a file that was shadowed, truncated, outside the startup path, or stale for the active run.
- 01Confirm the root and CWD
The expected nested file must be on the active root-to-CWD path.
- 02Look for an override
A same-directory AGENTS.override.md wins over AGENTS.md.
- 03Check the filename
Custom names are ignored unless configured as fallbacks.
- 04Check content and size
Empty files are skipped; the combined chain can hit its byte ceiling.
- 05Restart the run
The current session does not continuously rebuild instructions.
- 06Ask for a summary
Separate a discovery failure from vague or conflicting guidance.
- 07Test one behavior
Use a command, boundary, example, and proof—not a general aspiration.
If discovery succeeds but behavior remains inconsistent, name the scope, trigger, required action, and proof. “After changing database migrations, run make test-migrations” is testable; “test database changes carefully” is not.
Adjacent product layers
Where Supercode fits
Native Codex owns instruction discovery, precedence, fallback filenames, and the combined byte limit. Supercode does not change those rules.
Specs & Docs
Guided workflows can initialize, refresh, and audit agent-facing repository documentation. The changes still require review, and the repository remains authoritative.
Orient before the main taskContext Boosting
It can provide a bounded project layout or relevant repository context near the start of a turn. It may return no boost and does not replace durable instructions.
If those layers match the repository, install Supercode for Codex. Keep the contract explicit: AGENTS.md routes persistent working agreements, documentation holds durable knowledge, and executable checks prove compliance.
Keep it trustworthy
Instruction maintenance checklist
- The root file is a map and working agreement, not a copied manual.
- Every command exists and runs from the documented directory.
- Every nested file contains local differences rather than inherited text.
- Overrides are intentional, visible, and removed when temporary work ends.
- Long explanations point to versioned source documents.
- Mechanical rules are enforced by tools and name their validation command.
- The relevant root-to-CWD chain stays comfortably below its byte ceiling.
- A new Codex run can summarize the expected chain and local overrides.
- A representative task proves the guidance changes observable behavior.
- Rules likely to drift have an owner or review trigger.
The goal is not to tell Codex everything. Give the current task the smallest reliable path to the right knowledge, commands, boundaries, and proof.
Primary mechanics and supporting evidence
Sources and freshness
Codex discovery, precedence, size defaults, and verification commands were reviewed on September 17, 2026. The GitHub analysis concerns adjacent custom-agent files and is supporting editorial evidence, not a Codex outcome study.
The next useful action
Make repository knowledge easier to create and find
Use guided documentation workflows and bounded repository orientation around the native Codex instruction chain. Discovery and precedence remain under Codex control.

