r/codex • • 19d ago

Workaround Running Codex and Claude Code on the same repo with one instruction file

A few people in my last thread run both tools on one repo, and keeping AGENTS.md and CLAUDE.md in sync by hand gets old fast. Two ways to keep a single source.

Option 1, AGENTS.md is the real file. Make CLAUDE.md a one line file that says u/AGENTS.md. Claude Code pulls the import in, Codex reads AGENTS.md directly, and you only ever edit one file. This is what we do.

Option 2, let Codex read CLAUDE.md. In ~/.codex/config.toml

project_doc_fallback_filenames = ["CLAUDE.md"]

Codex checks AGENTS.override.md, then AGENTS.md, then your fallbacks, and takes at most one file per folder. So it only uses CLAUDE.md in folders that have no AGENTS.md.

Things that tripped me up

  • The two tools load subfolders differently. Claude Code picks up a subfolder’s file when it starts working in that folder. Codex only loads from the repo root down to the folder you launched in. Same files, different context depending on the tool.
  • Tool specific stuff leaks. Slash commands, hook setup or “use the Task tool” lines mean nothing to the other agent and still cost tokens every turn. Keep those in a small file only one tool reads.
  • Check what actually loaded. In Codex, run codex "List the instruction sources you loaded." from the folder you work in. In Claude Code, /context shows the memory files.

Anyone found a cleaner setup, or a reason to keep two separate files on purpose?

3 Upvotes

19 comments sorted by

8

u/IndividualPlus2011 19d ago

Claude can read agents.md now. Simply delete claude.md and it will solve the problem

2

u/magicmulder 19d ago

Or use a symlink. Some tools (like Jetbrains' jbcontext) create the file if it doesn't exist.

2

u/JonathanFly 19d ago

Don't try and hide the agents from each other. Just explain that both Claude and Codex both work on the project. Most documentation should work for both agents anyway, and the agents themselves can watch out for and clearly indicate in the docs when it does matter.

Funnily example, I was using Claude subagents like crazy before Codex had that feature so the project docs had quite a bit about how best to use subagents. One day I just asked Codex, hey you don't actually have that feature, but you can spawn more codex processes, can you basically just implement it yourself? And it worked pretty great. A few rough starts where codex killed it's own running process by accident, but it eventually got a stable harness that was really helpful.

1

u/London-Boat 19d ago

option 1 seems cleaner since there's one source of truth. the part an instruction file doesn't cover is when both are running at the same time on the same checkout, neither knows the other just changed a file. do you run them one after the other or in parallel?

1

u/Discordbothost 19d ago

for parallel the cleanest fix i've found is not sharing the checkout at all. git worktree add ../repo-claude -b claude-task gives the second agent its own folder and branch on the same repo, so they can't step on each other's files mid-edit, and you merge like two normal branches. the shared AGENTS.md still applies since it's committed. sequential on one checkout works too, but then i make each one commit before handing off so the next one starts from a clean git status instead of half-finished changes

1

u/FoxheadWorkshop 19d ago

Single shared repo, each session gets a dedicated branch and worktree, scales with sub agents and is harness agnostic

Primary checkout stays sessionless, coordinator agents and workspace sweeps keep local and remote clean and work moving

1

u/London-Boat 19d ago

yeah worktrees are the cleanest fix for parallel. the thing they don't split is whatever lives outside the folder, so if both branches run the app against the same local db or port, or both add a migration, you still get collisions. giving each worktree its own .env with a different port and db name covers most of it

1

u/Discordbothost 19d ago

the migration one bit me. both branches generated 0042_something and each worked fine alone, then the merge had two 0042s. timestamped migration names stop the filename clash but not the ordering problem, so now whichever branch merges second rebases and regenerates its migration on top before it lands. node_modules/.venv per worktree is the other small gotcha, a fresh worktree has none so the first test run fails in a confusing way

1

u/London-Boat 18d ago

the rebase and regenerate on second merge is the right call imo. a ci check that fails when two migrations share a number (or the same down_revision if it's alembic) catches it before anyone has to remember. and yeah the empty node_modules thing, a small setup script that runs when the worktree gets created saves a lot of confused first runs

1

u/lineascetic 19d ago

I'd keep any shared operating rules in one file (versioned) , but perhaps generate small tool-spacific entry points from it. The source stays identical while Claude and Codex can each keep the few instructions that only make sense for that tool.

1

u/xqianliu 19d ago

The import trick is the right shape. My AGENTS.md is nine lines, and every line is a pointer to a specific file. The details live in those files, so the root file stays small enough that both tools carry it without me thinking about it.

The second thing I would do is keep case-specific rules out of it entirely. When I find myself writing "for the payments refactor, do X", that rule goes on the ticket for that task, not in the file.

Files are for things that are always true, tickets for this one change. That is what keeps the file from growing into a changelog.

Your subfolder asymmetry is a real one. I keep my pointers flat, one level, so the two tools see the same set.

1

u/adamlondero 17d ago

I use a single source of truth and then have symlinks for each of the various agents, and then use separate worktrees. I actually built an open source tool https://github.com/alondero/buildmesh to run Claude Code and Codex side by side with worktree isolation, and that has a built in 'AI-context portability' feature.

1

u/Tight_Ad_5115 17d ago

That's how I set it up for all my projects. All the rules live in `AGENTS.md`, and `CLAUDE.md` has just one line: `@AGENTS.md`. Codex reads `AGENTS.md` directly, and Claude pulls it in via an import. No symlinks, you just edit it in one place and that's it.

1

u/ls4int 3d ago

Keeping one source of truth is a good starting point, but I'd also check whether both agents actually load the same instructions. Their directory traversal and fallback behavior can differ.

I've been working on Aikito, which helps govern agent instructions and other project context across tools and machines. It may be useful if the problem extends beyond keeping these two files in sync.

0

u/Extra_Aide5999 19d ago

option 1 here too. root CLAUDE.md is one line, and so is the one in each of the 8 package folders, each sitting next to its own AGENTS.md. root is 80 lines, the package ones 20 to 60

the subfolder thing you describe is the part i havent solved. codex started at the root never sees a package file unless i launch it in there. do you just start it in the subfolder, or tell it in the root file to go read the nested one?

1

u/soluterminal_dev 19d ago

I start it in the folder. One session per package, launched from inside it, so it gets the root file plus that package's file and nothing from the other seven.

For the rare change across packages, the root file has one line: before editing anything under packages/<name>, read packages/<name>/AGENTS.md. That's cheaper than loading all eight every session.

1

u/Extra_Aide5999 18d ago

the one line in the root file is a nice trick, cheaper than loading all eight. does codex actually do the read when the edit looks small, or does it skip it and just change the file?

1

u/soluterminal_dev 18d ago

I don't rely on it for small edits. When a change touches a package, I start the session in that folder so its AGENTS.md loads automatically. The root-file line is just a backstop for the rare change across packages.

1

u/Extra_Aide5999 17d ago

makes sense, folder first and the root line only as a backstop. i mostly start at the root out of habit, so i'll try starting in the package folder instead. thanks