Codex CLI Overwrites Existing AGENTS.md Due to Missing Enforcement Layer

Resolved 💬 1 comment Opened Jun 27, 2025 by askusWT Closed Aug 7, 2025

What version of Codex is running?

0.1.2504301751

Which model were you using?

04-mini

What platform is your computer?

Linux 6.6.76-08174-g2f3b34fb3650 x86_64 unknown

What steps can reproduce the bug?

mkdir codex-agents-test && cd codex-agents-test
git init
echo "MANDATORY: Use TypeScript only. Do not modify this file." > AGENTS.md
git add AGENTS.md && git commit -m "Initial constraints"

codex "create an agents file with basic structure"
cat AGENTS.md  # file has been replaced

What is the expected behavior?

  • CLI should detect that AGENTS.md already exists.
  • It should either:
  • Prompt before overwriting it, or
  • Treat it as a protected file, or
  • Load its contents as project instruction constraints automatically.
  • Bonus: Inject instructions from AGENTS.md into the model context unless explicitly bypassed with --no-project-doc.

---

What do you see instead?

  • CLI silently overwrites AGENTS.md with newly generated content.
  • There’s no prompt, no warning, and no protection.
  • Any existing project constraints not backed up or in git are lost.

This is especially dangerous when AGENTS.md is being used to enforce structural or compliance constraints in agent workflows.

---

Additional information

Why This Is a Problem

AGENTS.md is the canonical instruction file in many agent-based workflows. It contains critical coding rules (e.g. "always use TypeScript"). Currently, it is treated like any markdown file — which means it's the first thing that gets nuked, even when the instructions say not to modify it.

It seems this might be a regression or design gap from OpenAI’s internal implementation where AGENTS.md was injected or respected implicitly.

Workaround (Confirmed)

Wrap Codex to manually inject AGENTS.md content.

With Doppler:

# Store AGENTS.md in Doppler
doppler secrets set AGENTS_MD_CONTENT@AGENTS.md

# codex-safe.sh
#!/usr/bin/env bash
PROMPT="Project instructions:

$AGENTS_MD_CONTENT

User request:
$*"
codex "$PROMPT"

With direnv, expose AGENTS_MD_CONTENT in .envrc and use similar wrapper logic.

It works — but it’s a patch, not a fix.

---

Proposed Fix

  • Codex CLI should detect and load instruction files like AGENTS.md, CODEX.md, or instructions.md.
  • Their contents should be injected automatically unless explicitly disabled via a flag.
  • File overwrite operations should check for prior existence and require override flags to replace instruction files.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗