From Unify Agent Docs
Consolidate a project's AI-agent instruction files (CLAUDE.md, AGENTS.md, GEMINI.md, .cursorrules, copilot-instructions) into ONE canonical file per directory, exposed under every tool's filename via symlink, plus a drift-proof guard. Use this whenever the user wants agent instructions to stay in sync across tools, mentions that CLAUDE.md and AGENTS.md have drifted or disagree, says switching between Claude Code and Codex (or Cursor/Gemini) changes the rules, wants a single source of truth for agent context, asks to dedupe or centralize CLAUDE.md/AGENTS.md across a repo or monorepo, or wants the same setup replicated in another project. Works for single-repo, monorepo, and multi-repo layouts on any stack.
How this skill is triggered — by the user, by Claude, or both
Slash command
/unify-agent-docs:unify-agent-docsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Most projects accumulate several agent-instruction files — `CLAUDE.md` (Claude Code),
Most projects accumulate several agent-instruction files — CLAUDE.md (Claude Code),
AGENTS.md (Codex/Cursor), GEMINI.md (Gemini CLI) — at multiple directory levels. They
drift: the same facts get restated and disagree, and the CLAUDE.md vs AGENTS.md in the
same directory carry different rules, so switching tools silently changes the agent's
instructions. That is the bug this skill removes.
The fix is structural, not vigilance-based: one real file per directory, every other tool
name is a symlink to it. All tools then read identical bytes — drift between names becomes
physically impossible. Cross-cutting facts that would otherwise be copy-pasted live in one
shared-core file. A pre-commit guard fails loudly if anything is tampered with. The result
survives sessions, tool switches, and new contributors.
Bundled with this skill:
scripts/agent-docs.sh — generic sync/check engine. Auto-discovers every directory with a
real canonical file; no per-project config. Copy it into the target repo's tools/.scripts/pre-commit — the guard hook.references/multi-root.md — the shared-core pattern and a shared-core.md template (read
only when the project is a monorepo or has sibling repos).Do this before changing anything. The point is to learn the project's actual shape rather than assume one.
CLAUDE.md, AGENTS.md, GEMINI.md, .cursorrules, and
.github/copilot-instructions.md at all levels. Exclude node_modules, .git,
vendor, build, dist, Pods, and other vendored/generated dirs.diff any same-directory CLAUDE.md vs AGENTS.md pair to surface
conflicts.references/multi-root.md.AGENTS.md (broadest tool support) as the
one real file; CLAUDE.md/GEMINI.md become symlinks. Only invert if the project clearly
treats CLAUDE.md as primary — symlink either way. (The script's canonical name is set via
AGENT_DOCS_CANONICAL, default AGENTS.md.)This is the step that most needs judgment, so spend care here. Where a directory has both a rich file and a thin one, merge all operational detail into the single canonical file — never drop the richer file's content to "let the source of truth win." The thin file is usually the less complete one even when it's nominally authoritative.
/foo slash command for Claude vs a $foo
invocation for Codex), keep ONE section with clearly labeled subsections
(### Claude Code, ### Codex, ### Gemini CLI). Resolving these conflicts in plain sight
is the whole point — it's what stops the drift from coming back.tools/agent-docs.sh). Edit this
file, never the symlinks."Don't invent project facts. Only consolidate what already exists; if two files state a fact differently and you can't tell which is right, flag it for the user rather than guessing.
Skip entirely for single-root projects — put cross-cutting facts directly in the root
canonical file. For monorepos/sibling repos, follow references/multi-root.md: extract the
invariants (domain rules, schema/enum values, pricing constants, ownership tables, agent/skill
name tables, anti-hallucination rules) into docs/agents/shared-core.md, which the script
embeds into the root canonical file between <!-- BEGIN SHARED-CORE hash:… --> sentinels. For
sibling repos, pick one upstream and have the others pull it via AGENT_DOCS_UPSTREAM.
mkdir -p <repo>/tools <repo>/.githooks
cp <skill>/scripts/agent-docs.sh <repo>/tools/agent-docs.sh && chmod +x <repo>/tools/agent-docs.sh
cp <skill>/scripts/pre-commit <repo>/.githooks/pre-commit && chmod +x <repo>/.githooks/pre-commit
cd <repo> && git config core.hooksPath .githooks
tools/agent-docs.sh --sync # creates the symlinks (+ embeds shared-core if present)
The script needs no editing — it discovers in-scope directories itself. Run --sync only
after the canonical AGENTS.md files from Phase 1 exist, because --sync replaces each
directory's CLAUDE.md/GEMINI.md with a symlink; running it before the merge would
overwrite a rich CLAUDE.md you hadn't folded in yet.
Unification fixes where the rules live; this pass fixes how good they are. Now that each directory has one canonical file, audit and tighten it so the agent actually has what it needs — a structurally-perfect file full of vague or stale guidance still fails the agent.
AGENTS.md only. CLAUDE.md/GEMINI.md are symlinks and reflect the
change automatically; writing to a symlink replaces it and trips the guard. If you change
docs/agents/shared-core.md, re-run tools/agent-docs.sh --sync to re-embed it.references/quality-pass.md — commands present, architecture
clear, non-obvious gotchas captured, concise, current, actionable. Score each, output a short
report, and get the user's OK before writing.claude-md-management:claude-md-improver skill is installed you can drive this pass
with it — but point it at the canonical AGENTS.md files (not the CLAUDE.md symlinks).Verification is non-negotiable — the value of this skill is that drift fails loudly, so prove the guard actually fires.
tools/agent-docs.sh --check passes; show the output.--check fails
(and the pre-commit hook would block), then restore it.ls -l shows CLAUDE.md/GEMINI.md resolving to the canonical file in every in-scope dir.tools/agent-docs.sh --check-cross <other-repo> shows zero drift.chore/unify-agent-docs, staging files by name (no git add -A). Do
not push or open a PR unless the user asked — report what's staged and let them review.git config core.hooksPath .githooks once; git deliberately won't
auto-activate a repo's own hooks on clone. Note this for the user.120000; confirm that after merging a PR so a squash
didn't turn them back into regular files.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub shanemhamilton/unify-agent-docs --plugin unify-agent-docs