Skip to content

Commit ee4c0f7

Browse files
committed
Bridge .claude/CLAUDE.md to AGENTS.md for Codex CLI
Codex CLI reads AGENTS.md for project instructions, not .claude/CLAUDE.md. When AGENTS.md is absent, copy from .claude/CLAUDE.md (or root CLAUDE.md) and add it to .git/info/exclude so the agent doesn't commit the copy.
1 parent 00ff2d7 commit ee4c0f7

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

lib/drivers/codex-cli.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ agent_settings() {
6060
cli_auth_credentials_store = "file"
6161
TOML
6262

63+
# Codex reads AGENTS.md for project instructions, not
64+
# .claude/CLAUDE.md. Bridge the gap when AGENTS.md is absent.
65+
if [ ! -f "${_workspace}/AGENTS.md" ]; then
66+
local _src=""
67+
[ -f "${_workspace}/.claude/CLAUDE.md" ] \
68+
&& _src="${_workspace}/.claude/CLAUDE.md"
69+
[ -z "$_src" ] && [ -f "${_workspace}/CLAUDE.md" ] \
70+
&& _src="${_workspace}/CLAUDE.md"
71+
if [ -n "$_src" ]; then
72+
cp "$_src" "${_workspace}/AGENTS.md"
73+
mkdir -p "${_workspace}/.git/info"
74+
echo "AGENTS.md" >> "${_workspace}/.git/info/exclude"
75+
fi
76+
fi
77+
6378
if [ -n "${OPENAI_API_KEY:-}" ]; then
6479
CODEX_HOME="$codex_home" \
6580
printenv OPENAI_API_KEY \

tests/test_drivers.sh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ echo ""
800800
echo "=== 31. Codex driver — agent_settings ==="
801801

802802
CWORK="$TMPDIR/codex-workspace"
803-
mkdir -p "$CWORK"
803+
mkdir -p "$CWORK/.git/info"
804804
_test_home="$TMPDIR/fakehome"
805805
mkdir -p "$_test_home"
806806
HOME="$_test_home" agent_settings "$CWORK"
@@ -812,6 +812,42 @@ assert_eq "codex config.toml created" "true" \
812812
assert_contains "codex config has file store" "file" \
813813
"$(cat "$_test_home/.codex/config.toml")"
814814

815+
# 31b. AGENTS.md bridge: .claude/CLAUDE.md copied when no AGENTS.md.
816+
CWORK_B="$TMPDIR/codex-bridge"
817+
mkdir -p "$CWORK_B/.claude" "$CWORK_B/.git/info"
818+
echo "# Project rules" > "$CWORK_B/.claude/CLAUDE.md"
819+
HOME="$_test_home" agent_settings "$CWORK_B"
820+
assert_eq "AGENTS.md created from .claude/CLAUDE.md" "true" \
821+
"$([ -f "$CWORK_B/AGENTS.md" ] && echo true || echo false)"
822+
assert_eq "AGENTS.md content matches" "# Project rules" \
823+
"$(cat "$CWORK_B/AGENTS.md")"
824+
assert_contains "AGENTS.md in git exclude" "AGENTS.md" \
825+
"$(cat "$CWORK_B/.git/info/exclude")"
826+
827+
# 31c. AGENTS.md bridge: CLAUDE.md at root used as fallback.
828+
CWORK_C="$TMPDIR/codex-bridge-root"
829+
mkdir -p "$CWORK_C/.git/info"
830+
echo "# Root rules" > "$CWORK_C/CLAUDE.md"
831+
HOME="$_test_home" agent_settings "$CWORK_C"
832+
assert_eq "AGENTS.md from root CLAUDE.md" "# Root rules" \
833+
"$(cat "$CWORK_C/AGENTS.md")"
834+
835+
# 31d. AGENTS.md bridge: existing AGENTS.md not overwritten.
836+
CWORK_D="$TMPDIR/codex-bridge-existing"
837+
mkdir -p "$CWORK_D/.claude" "$CWORK_D/.git/info"
838+
echo "# Codex rules" > "$CWORK_D/AGENTS.md"
839+
echo "# Claude rules" > "$CWORK_D/.claude/CLAUDE.md"
840+
HOME="$_test_home" agent_settings "$CWORK_D"
841+
assert_eq "existing AGENTS.md preserved" "# Codex rules" \
842+
"$(cat "$CWORK_D/AGENTS.md")"
843+
844+
# 31e. AGENTS.md bridge: no CLAUDE.md at all, no AGENTS.md created.
845+
CWORK_E="$TMPDIR/codex-bridge-none"
846+
mkdir -p "$CWORK_E/.git/info"
847+
HOME="$_test_home" agent_settings "$CWORK_E"
848+
assert_eq "no AGENTS.md without CLAUDE.md" "false" \
849+
"$([ -f "$CWORK_E/AGENTS.md" ] && echo true || echo false)"
850+
815851
# ============================================================
816852
echo ""
817853
echo "=== 32. Codex driver — agent_extract_stats ==="

0 commit comments

Comments
 (0)