I use both Claude Code and Codex, and for a while Codex sessions on the same repos felt noticeably worse, even with reasoning already turned all the way up, so before blaming the model I went and compared the instruction files, first the global ones and then the ones in a repo I work on with several agents. Getting each of them down to one source turned out to be the easy part (with one gotcha in the Claude desktop app), and the part I didn't expect was how much the rules themselves fight each other once you put them all in one place. The later sections are about the skills and agents around those files, which came up in the same cleanup.
Two files that drifted apart
The global CLAUDE.md had grown section by section over a few months (commit message style, what never to do with git, how to verify work, when to ask before starting, how to handle review findings), and the Codex AGENTS.md had been written once and mostly left alone. When I finally put them side by side, AGENTS.md was 1227 words against 2015 in CLAUDE.md, and it had none of the behavioural sections, only its own older ones about timeboxes and bounded review loops. On top of that, Claude had hooks enforcing some of the rules (a hook that blocks git checkout -- <file> on a dirty file, for example), so Codex was missing both the rule and the guard behind it.
Copy-pasting the missing sections over would have fixed it for about a week, so instead we can treat the two files as build output.
Shared fragments and a small generator
The layout is one directory of shared sections and one template per tool:
instructions/
shared/
commit-message-style.md
scope-discipline.md
root-cause.md
...
claude.template.md
codex.template.md
scripts/build-instructions.sh
A template is mostly include lines, plus whatever is specific to that tool. The Codex one, for example, adds a note where Claude has a hook and Codex doesn't, because there the rule is the only protection:
# Global AGENTS.md
<!-- include: shared/commit-message-style.md -->
<!-- include: shared/discarding-uncommitted-work.md -->
* No hook guards these commands here, so this rule is the only protection: check
`git status --short <path>` before any command that rewrites a file from HEAD.
<!-- include: shared/scope-discipline.md -->
The generator is about a hundred lines of bash that reads each template line by line, swaps every include line for the fragment's contents, and writes CLAUDE.md and AGENTS.md with a header saying not to edit them by hand. It also has a --check mode that writes nothing and fails when a generated file differs from what the templates would produce (someone edited the output directly), or when a shared fragment is included by only one of the templates, since a fragment that only one tool gets is exactly the drift we're trying to get rid of. If we run that check with the rest of the repo's checks, the two files can't drift apart again without a failing build.
Gotcha: if you emit a fragment with cat, a fragment saved without a final newline gets its last line glued onto the next template line (my first version did exactly that), so a heading ## A followed by NEXT comes out as ## ANEXT. The --check still exits 0, because it compares the files against the same broken rendering. Reading the fragment line by line fixes it:
emit_fragment() {
local line
while IFS= read -r line || [[ -n "$line" ]]; do
printf '%s\n' "$line"
done < "$1"
}
The || [[ -n "$line" ]] part is what keeps a last line without a newline, and the printf always adds one back. While we're in there, we can also make it reject CRLF line endings, nested includes and the same include twice in one template, all cheap to check.
After the sync AGENTS.md went to 2535 words and CLAUDE.md to 2844. I don't have a measurement showing Codex got better afterwards, so I'll just say the two agents now get the same rules, which was the point.
In a repo, one AGENTS.md
A repo has the same problem on a smaller scale. A personal app I work on with several coding agents had collected an instruction file for each of them, CLAUDE.md for Claude Code, AGENTS.md for Codex, .github/copilot-instructions.md for Copilot and a Cursor rule in .cursor/rules/, which started as copies of each other and were kept in sync by hand, which means they weren't. AGENTS.md was three commits behind CLAUDE.md and was missing a whole section CLAUDE.md had gained since, the Copilot file was missing two whole blocks, and the Cursor rule pointed at a section of the project's playbook that no longer existed. Nothing in that repo complained about any of it, because nothing there compared the files.
Unlike the global files, these don't need different content per tool, so there's nothing to generate, and once Claude Code started reading AGENTS.md the obvious move was to keep that one file and delete the rest.
How the fallback decides
From version 2.1.277 Claude Code checks for AGENTS.md when a folder has no CLAUDE.md. It's a built-in plugin called agents-md with one option, instructionFiles, which shows up in /config as "Project instructions" and defaults to claude-md-or-agents-md. A few details decide whether it loads anything:
- If both files exist, only
CLAUDE.mdis loaded, soAGENTS.mdonly takes over onceCLAUDE.mdis gone. - "No
CLAUDE.md" means none ofCLAUDE.md,.claude/CLAUDE.mdorCLAUDE.local.mdanywhere from the project root down to the working directory, so if you keep a personalCLAUDE.local.mdaround, deleting the sharedCLAUDE.mdstill leavesAGENTS.mdunloaded. - Setting
instructionFilestoclaude-mdturns the fallback off, and a repo with onlyAGENTS.mdthen loads nothing, without any warning. The option is read from user or managed settings only (a project's.claude/settings.jsonis ignored for it), so the repo can't pin it for you. - Until 2.1.281 it didn't work on Amazon Bedrock, Google Vertex AI, Microsoft Foundry, LLM gateways, or in sessions with telemetry disabled.
-
/memoryand#don't know aboutAGENTS.md, and directories added with--add-dirdon't contribute theirs. - Nested
AGENTS.mdfiles in subfolders are attached when a file under that folder is read, but they aren't restored after a compaction with the other recently read files, so they come back only at the next read in that folder.
None of those mattered for this repo, which has a single root file and no CLAUDE.local.md, so the plan was to check the version, move everything into AGENTS.md, and delete CLAUDE.md.
The desktop app runs its own Claude Code
The installed CLI was 2.1.268, below the cutoff, so I upgraded it, ran claude --version, got 2.1.278 and went ahead with the deletion. I also tried a headless claude -p run to confirm that a fresh session picks up AGENTS.md, which failed on authentication, so the change went in with only the version check behind it.
A bit later I opened a new session in the Claude desktop app and asked whether it had loaded AGENTS.md, and it said no, that AGENTS.md was just a file in the repo it would have to read like any other. The reason is that the desktop app doesn't use the CLI on your PATH at all and instead downloads and runs its own Claude Code, which lives here:
ls -1 ~/Library/Application\ Support/Claude/claude-code/
On that day the folder had 2.1.271 and 2.1.275 in it, and the app was running 2.1.275. The CLI I'd upgraded sits under ~/.local/share/claude/versions/, which the app never touches, and the two installs update independently, so claude --version had checked a binary that no desktop session ever runs, and every desktop session in that repo had been starting with no project instructions since the deletion (the app's own instruction reload confirmed it, listing CLAUDE.md as gone and not listing AGENTS.md at all).
If you use both the CLI and the desktop app, they can be on different versions, and the one that matters is whichever one runs the session you care about.
CLAUDE.md as a symlink
Restarting the app may pull a newer runtime, but that depends on its release channel, so instead of waiting on it CLAUDE.md came back as a relative symlink to AGENTS.md:
ln -s AGENTS.md CLAUDE.md
git add CLAUDE.md # git records it as mode 120000
An older runtime finds CLAUDE.md and loads it, and a newer one also prefers CLAUDE.md when it exists, so both end up with the same content, and there's still no second copy to drift because it's the same file. A relative target also resolves fine in git worktrees, and once the desktop runtime is on 2.1.277 or newer (the ls above tells you) the link is optional.
Gotcha: the repo has a hook that fires when someone edits the instruction file, and I'd just changed its pattern from CLAUDE.md to AGENTS.md. With the symlink in place, an agent told to "update CLAUDE.md" edits the file through the CLAUDE.md path, and the hook matches the path string it's given, not the resolved target, so it stayed silent. Hooks or CI checks keyed on a filename need both names for as long as the link exists.
Checking that the file loaded
A version number only tells you what some binary on your machine can do, and a file existing in the repo doesn't tell you whether anything loaded it. The check that does work is to start a fresh session in the app you normally use and ask it about something only the instruction file says, like a rule, a command or a name that doesn't appear anywhere else in the repo. If it can't answer, the file wasn't loaded, and the next place to look is which Claude Code that app is running.
Adding a root-cause rule
With the global rules in shared fragments, adding a rule to both agents is one edit, and the first one I added was a "root cause, not workarounds" section: fix a defect where it starts, not where it shows, and treat things like swallowed errors, sleeps hiding a race, or an "already started" flag absorbing repeated calls as symptom-level fixes.
My first wording judged a fix by size, roughly "the smallest change at the place the defect starts". It sat right next to an existing scope rule that said "smallest change that meets the requirement", and together they pushed the agent toward minimal diffs, which is the opposite of what a root-cause rule is for, since the proper fix is sometimes more code than the workaround. At the same time the root-cause rule put no limit on how far a fix could go, so "the callee is wrong, so while I'm here I'll redesign the callee" was allowed too. Both rules ended up judging a fix by soundness instead:
* **The simplest sound solution, not the smallest diff.** Pick the approach you would choose
with no time pressure and no prior work to protect; if it needs more code, write it.
and the root-cause section got the other side of it, that root cause sets where the fix goes, not how big it is, and that generalizing beyond the defect or fixing similar bugs elsewhere are follow-ups.
Reviewing the merged rules
Next, another agent with no context from the session reviewed the whole generated global file and came back with 13 findings, two of them real contradictions between sections that each made sense alone:
- The multi-PR section said to name every follow-up the moment it surfaces and ask what to do with it, while the scope section said to collect follow-ups and list them in the final report.
- The execution section said to ask first when there are "multiple valid approaches", while the scope section said to pick the simplest sound approach yourself.
With a contradiction like that the agent can pick whichever rule suits it at the moment, so it's a loophole in both directions. The fix in each case was to give each rule a boundary instead of picking a winner: only a follow-up big enough to need its own PR is raised right away, and smaller ones go to the report, and "ask first" now covers approaches that differ in behaviour, scope or cost the user would care about, while choices that differ in none of those are the agent's to make.
The same review also flagged escape hatches, words that stretch to fit whatever the agent wants to skip. "Theoretical edge cases" were allowed to be deferred, and almost any edge case can be called theoretical if you don't feel like handling it, so the rule now says what theoretical means:
An edge case counts as theoretical only when you cannot name an input or sequence that reaches it.
"Code smell" had the same problem as a reason to reject an option, and it became "nothing that breaks the codebase's own conventions", which you can at least point at.
The fixes then added a contradiction of their own (the report I'd just told it to keep for small follow-ups was offering to "fold follow-ups into scope", which is one of the options the multi-PR section reserves for big ones), and the re-review caught that one too, which is a good reason to put rule changes through the same review and re-review we'd use for code.
Removing the review-loop cap
The same repo also holds the skills and subagent definitions for both tools, and a day later a Codex review of them found leftovers from the old Codex sections, mainly a hard "one fix/re-review cycle" cap in the review skills, which came from the timebox rules the shared scope section had replaced. Deleting the cap looked like plain cleanup, but a parallel review found what it had been doing. It was the only way those review loops could end without success, so a required finding that needed a decision, or whose proper fix was too large, had no stated end at all, and one skill still sent each re-review looking for "previously unreviewed risk", so without the cap the rounds didn't have to converge. Both got their counterweight, a "blocked" exit that reports the finding as remaining work, and a re-review scope limited to the fixes and the code they touch.
Something similar happened with a skill that addresses all the review findings in a session. I let calling it count as approval for the optional, nice-to-have fixes too, which is what you'd mean when you run it by hand, except an unattended overnight skill also calls it, and there it turned optional edits into fix-now work with nobody deciding. The approval now only comes from a direct call by a person.
Both times the limit I removed had been holding something up, and I only found out afterwards (twice, yes), so now we check what a cap does before deleting it.
Fixes and trims in one audit
Those skills and agents live in the same repo as the global files, with ~/.claude and the Codex config symlinked into it, so an edit there changes every project at once. They had grown for most of a year without anyone, me included, reading them end to end, so I had an agent audit all of it. It came back with two diffs, 92 hunks across 39 files for the shared config and 9 hunks across 4 files for the agent guide of an iOS app, which I reviewed in groups and applied.
Reading the hunks again afterwards, they fell into two piles that look the same in a diff but risk very different things. The first pile fixed text that was wrong, where an agent following the old text did the wrong thing:
- a reviewer told to dispatch an
ios-expertagent and a/enhance-plancommand that were never defined; - APIs that don't exist (
withTimeout,exactOptionalProperties) and an iOS 17 floor in a project that targets 18; - a performance reviewer enforcing web budgets (200 ms, 5 KB) on a mobile app, which produces findings that are wrong by construction;
- an agent registered under a display name ("Test Automation Specialist") while seven skills dispatched it by its kebab-case id, so those dispatches didn't resolve.
None of those needs testing, since there's no version of "the agent is told something false" that's better than the corrected one.
The second pile, about 36 hunks, cut files mainly for size. A Rust expert agent went from roughly 90 lines to about 10, a performance reviewer lost its five-pass review order, a docs skill lost its MUST / MUST NOT block, a handoff skill had "comprehensive, zero information loss" softened, and six agent descriptions lost the examples that help the main agent decide when to dispatch them.
Agent and skill bodies only load when they're used, and the whole cut saved a few hundred tokens, which is a small price for keeping a rule an agent relies on.
I asked whether the edits could make runs worse, and the agent said, fairly, that it couldn't tell, since nothing had been tried on real agent runs, and proposed the usual answer of running old and new versions of each risky file against a fixed set of tasks, several times each, with blind pairwise judging. We didn't, because an eval like that catches a concrete, named failure ("it stopped writing valid frontmatter", "it no longer dispatches the performance reviewer") that a script can check over many runs, but it doesn't predict whether an agent is better at real work, since a handful of clean prompts isn't a long session in a messy repo, model judges prefer longer and more confident answers, and a few dozen runs only catch large effects.
Instead of measuring the trims, we judged each one by why it was made. A cut that removed a rule, a warning or an ordering the agent relied on was reverted, and a cut that only removed padding could stay, which reverted most of the second pile, with every revert mirrored to the Codex copies. One agent the audit had marked as fine to keep (a backend architect) had gained two good instructions in the rewrite but lost about six others, so it got its original body back with the two additions on top, which is easy to miss when a diff is mostly deletions and the audit's summary calls them intentional. In hindsight the sorting into "fixes wrong text" and "makes it shorter" should have happened before applying anything, not after :|
Counting what ran
For deciding what to delete, a file's length turned out to be a poor guide and whether it ever ran a much better one, and that we can answer, since every Claude Code session is a JSONL transcript under ~/.claude/projects/. Subagent spawns are tool_use blocks named Agent (Task in older sessions) with a subagent_type, and skill calls are tool_use blocks named Skill, so a rough count is a jq filter over every file:
find ~/.claude/projects -name '*.jsonl' -print0 \
| xargs -0 jq -r '
select(.type=="assistant") | .message.content | arrays | .[]
| select(.type=="tool_use")
| if (.name=="Agent" or .name=="Task")
then "agent " + (.input.subagent_type // "general-purpose")
elif .name=="Skill" then "skill " + .input.skill
else empty end' 2>/dev/null \
| sort | uniq -c | sort -rn
Slash commands you type yourself show up separately, as <command-name> tags in user messages, so they need their own pattern, and in Codex a skill shows up as the agent reading its SKILL.md, which you count by file path. The full scan went over about 15 GB, 20,255 Claude Code transcripts since the end of January plus 40 Codex sessions.
The counts were very lopsided. The reviewer agents had 600 to 1,800 spawns each and the most used skill (a checkpoint skill that saves progress before clearing context) had 946 calls, while 7 agents and 11 skills had never been used in either tool. Some of the zeros needed a second look before deleting anything:
- an agent that only one mode of one skill dispatches had zero spawns because that mode had never been run, which says nothing about the agent;
- two "unused" agents were named by a frontend review skill, so removing them would have broken it, and they went back in;
- a count by name won't see a skill that an agent read by opening its file, or usage under an older command name.
Before deleting a file with zero uses, grep for what names it.
After that, two agents that nothing spawned or referenced were deleted. Two skills that had never been called, an adversarial review and a parallel PR-comment resolver, were folded into skills that already covered their job, the adversarial review's probes and verification plan into an existing stress-testing skill, and the comment resolver's review-thread handling (reading threads from the base repo, paging each thread's comments, grouping threads by what they ask for) into a PR-burndown skill.
The more interesting zeros were nine thinking-lens skills (5 whys, first principles, Occam's razor, opportunity cost, 10-10-10 and so on), which I didn't want to delete because they're useful for decisions. Nobody called them because nothing pointed at them, and the three lenses that did get used were the ones the stress-testing skill calls directly. So instead of removing them we added a small think skill that maps the shape of a question to a lens, and linked lenses from the workflows at the point where their question comes up, for example 5 whys and Occam's razor in the premise check before a bug fix, and opportunity cost and second-order thinking where options get compared. Each link is conditional, so a workflow reaches for a lens only when its question shows up, which keeps them out of runs that don't need them.
The parts I'd copy into another setup are the generator with its --check, and in a repo a single AGENTS.md, checked by asking a fresh session in the app you use about something only that file says. The rules themselves are personal and will keep changing, and since each change now goes into one file, we can review it against the rest the same way we review code. For pruning, the transcript counts and a grep for what names each file did most of the work.
Top comments (0)