Deduplicate AGENTS.md when CODEX_HOME is also the project root

Open
#34,193 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
cli

Research direction

Start with the instruction assembly paths exercised by codex debug prompt-input, comparing global $CODEX_HOME/AGENTS.md loading with project instruction discovery. Reproduce the issue using the shell commands in the report and inspect the resulting JSON counts. Done means identical canonical paths are included once, the duplicate --- project-doc --- wrapper is absent, and distinct project instructions still load.

Written by the indexing model from the issue text.

Description

bug CLI config

Summary

When CODEX_HOME is also the project root and current working directory, Codex loads the same canonical AGENTS.md file twice:

  1. as the global $CODEX_HOME/AGENTS.md;
  2. again through project instruction discovery.

The second copy is wrapped as --- project-doc ---.

Environment

  • codex-cli 0.144.6
  • Linux x86_64
  • zsh

Minimal reproduction

tmp="$(mktemp -d)"
export CODEX_HOME="$tmp"
cd "$tmp"
git init -q
printf '# CANONICAL_DEDUPE_MARKER\n' > AGENTS.md

codex debug prompt-input DEDUPE_CHECK |
  jq -c '[.. | strings] as $strings |
    {marker_count:([$strings[] | scan("# CANONICAL_DEDUPE_MARKER")]|length),
     project_doc_wrappers:([$strings[] | scan("--- project-doc ---")]|length)}'

Observed: the marker appears twice and one project-doc wrapper is present.

The same behavior was measured in a real Codex home repository:

{"agents_headers":2,"project_doc_wrappers":1,"marker_count":1,"total_string_bytes":45422}

With the one-run override -c project_doc_max_bytes=0:

{"agents_headers":1,"project_doc_wrappers":0,"marker_count":1,"total_string_bytes":31123}

Expected behavior

Instruction assembly should deduplicate identical canonical source paths across global and project discovery. If $CODEX_HOME/AGENTS.md was already loaded globally, project discovery should not append the same file again.

Impact

  • duplicate durable instructions in every turn;
  • unnecessary input-token consumption;
  • additional prompt processing latency;
  • misleading provenance because one physical file appears as two logical instruction layers.

Configuration limitations

  • Named profiles require explicit --profile selection.
  • Project config cannot select a profile.
  • A global project_doc_max_bytes=0 would incorrectly disable project instructions in every repository.
  • A conditional -c project_doc_max_bytes=0 suppresses the duplicate locally, but also suppresses the entire project instruction chain and is only a workaround.

Related work

  • #23416 tracks incorrect instruction provenance when both global and project instructions are loaded.
  • #17091 reports global and project AGENTS.md as separate layers in /status, but does not deduplicate identical paths.
Dominant language
Rust
Stars
125k
Forks
19.5k
Avg merge
1m
Merged PRs (30d)
1k

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openai/codex

All issues in openai/codex

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.