feat(cli): add `codex debug agents-md` subcommand to inspect AGENTS.md discovery
What variant of Codex are you using?
CLI
What feature would you like to see?
Add codex debug agents-md — a new codex debug subcommand that reports the exact AGENTS.md discovery result for the current cwd, without spawning a session. Analogous to codex debug prompt-input / codex debug models, but scoped to AGENTS.md/instruction assembly.
The problem
Today, if AGENTS.md behavior looks wrong, the only user-facing way to inspect what actually loaded is codex debug prompt-input "test" — which dumps a 50KB+ JSON blob mixing sandbox prose, skills manifest, environment context, and (buried inside a user message) the resolved # AGENTS.md instructions for <path> block. That is a reverse-engineering exercise, not an observability primitive.
Every AGENTS.md-discovery bug filed in the last quarter — #28903 (ancestor dirs), #29535 (relative-link resolution), #24855 (wrong workspace/cwd on resume), #11757 (stale rehydrate from another workspace), #25884 (loaded but inconsistently applied), #22785 (SSH permission-denied) — requires the user to grep raw JSON to answer questions Codex already knows the answer to at load time:
- Which project root did discovery pick (marker file, path)?
- Which AGENTS.md files were walked, in which order, from root ? cwd?
- What bytes did each contribute? What was truncated against
project_doc_max_bytes? - Was
AGENTS.override.mdpresent at any level? Did it override anything? - Which
project_root_markerslist was in effect (default.gitvs user override)? - Were any files skipped due to I/O errors, symlink cycles, or size caps?
Users, plugin authors, and issue triagers all need this. Right now they either read codex-rs/core/src/agents_md.rs or file a bug that a maintainer resolves with "please share debug prompt-input output."
Proposed shape
$ codex debug agents-md
project_root: C:\D\oriz\repos\frk\omniroute (marker: .git)
project_root_markers: [".git"] (source: default)
project_doc_max_bytes: 32768
project_doc_fallback_filenames: []
Discovered files (root ? cwd):
1. C:\D\oriz\repos\frk\omniroute\AGENTS.md 36405 B ? TRUNCATED to 32768 B (remaining budget)
Total loaded: 32768 B / 32768 B (100%)
Not discovered:
- C:\D\oriz\AGENTS.md (above project root, not walked)
- AGENTS.override.md (not present at any level)
User-scope instructions:
- ~/.codex/AGENTS.md 4210 B ? loaded (user-scope)
Add --json for CI/harness consumers (matches #16037's ask for machine-readable status).
Why a new subcommand and not extend /status
/status is session-scoped and inside the TUI. codex debug agents-md is:
- Pre-session — answer "what will Codex load?" before starting a chat.
- Deterministic — no model in the loop, no cache state, no thread history.
- Scriptable — CI can gate on AGENTS.md drift (e.g. "assert this repo's
AGENTS.mdstill resolves to 3 files totaling < 20KB"). - Debuggable — reproduces the pure discovery function in isolation, so a bug reporter can attach one command's output instead of a redacted
prompt-inputdump.
Implementation notes
- Discovery logic already exists as
read_agents_md/agents_md_pathsincodex-rs/core/src/agents_md.rs. This subcommand wires that up to thecodex debugCLI dispatcher — same pattern asdebug prompt-input. - No model calls, no network. Pure filesystem + config walk.
- Should honor
-c project_root_markers='[".hg",".git"]'overrides via the shared-cflag so users can preview marker changes without editing~/.codex/config.toml. - On the
--jsonshape: mirrordebug models' style (top-level object withproject_root,markers,discovered[],not_discovered[],user_scope[],total_bytes,truncated: bool).
Related issues / prior art
- #17401 — "@include directive for composable AGENTS.md files" — the comment thread explicitly requests "emit resolved include graph: source file, resolved path, bytes/tokens, and whether it was inlined or left as a reference" (unitedideas, caioribeiroclw-pixel, olijboyd). This subcommand is the minimum viable form of that.
- #16037 — machine-readable
/status --json. - #23279 — analogous
codex modelscommand (shipped ascodex debug models). - #17498 (closed) — "/status shows Agents.md: <none> even when AGENTS.md exists" — exactly the kind of report that a
debug agents-mdcommand lets a user self-diagnose in one line. - #22785 (SSH permission-denied), #28903 (ancestor dirs), #29535 (relative links), #24855, #11757, #25884 — every one of these would have been faster to file and faster to close with
debug agents-mdoutput attached.
Version tested
codex-cli 0.142.4 (Windows x64). Verified by running codex debug prompt-input "hi" from C:\D\oriz\repos\frk\omniroute and grepping the JSON for the AGENTS.md block — that block exists but is not the primary tool for the job.