sync-docs
Keep CLAUDE.md, AGENTS.md, existing path-scoped rule files, SKILL.md, and README.md accurate after new commits land: find the last docs-sync point, classify every commit since then, and write targeted edits. Syncing is bidirectional: add what is new, and remove or correct anything the current codebase contradicts.
Edit the docs that exist; never create a new top-level doc (AGENTS.md, CHANGELOG.md, SKILL.md) or a new rule file during a sync. If one seems warranted, tell the user.
A sync ends in one of three outcomes: "no doc changes", an open docs PR, or blocked (step 11, or a failed agent guide contract rule in guide-contract.md), which leaves no commit, push, or PR. A caller such as sync-docs-release reads that outcome.
Audiences: CLAUDE.md is the organized agent reference (architecture, symbol and file names, file:line cues, grouped by area) and describes current behavior, never history. AGENTS.md mirrors it for other agent tools (step 6). Path-scoped rule files are the existing tracked .claude/rules/**/*.md files; each holds the rules for one area, and its paths: frontmatter, when present, limits it to matching files. Claude Code loads them; Codex and other AGENTS.md readers load one only when the shared guide tells them to read it. SKILL.md is operator-facing and imperative (config keys, setup, CLI flows); no symbol or field names in its tables. README.md is the newcomer entry point and changes only when the public surface changes. CHANGELOG.md, when present, holds per-issue rationale and migration history.
Preconditions: gh auth status succeeds. Resolve DEFAULT=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name), run git fetch origin, record the range end T0=$(git rev-parse "origin/$DEFAULT"), and create a worktree off that tip with the harness branch prefix (cc/ on Claude Code): git worktree add .claude/worktrees/cc+sync-docs-<YYYY-MM-DD> -b cc/sync-docs-<YYYY-MM-DD> "$T0". Every range below ends at $T0, never at a later origin/$DEFAULT. When that branch already exists locally or on origin, never delete or reuse it: add the next free suffix to the branch and the worktree name (-2, then -3). Read, edit, and run every git command in that worktree (-C <worktree>), never in the main checkout.
Agent guide contract: run git show "$T0:CLAUDE.md" | grep -qxF '## Agent guide contract'. No match: the steps below run as written. A match that sits only inside a code fence is an example and no statement, so the steps below also run as written. A match outside a code fence: the project generates its agent guides with a command, so read guide-contract.md before step 3 and apply its statement form and its rules for steps 3, 6, 10, and 12 and the blocked outcome. Read the statement from that $T0 text only.
Steps
- Baseline.
git log --oneline "origin/$DEFAULT" | grep -m1 -E '^[0-9a-f]+ ([Ss]ync docs\b|docs(\([^)]*\))?: sync\b|docs\(sync\):)'. A sync is adocs:ordocs(<scope>):subject that begins with "sync", adocs(sync):scope, or a subject that begins with "sync docs"; a commit that mentions "sync docs" later in its subject is no sync, and a docs commit that only names CLAUDE.md or SKILL.md is no sync. The matched commitMis the baseline unless it records a range end: readgit log -1 --format=%B <M>for aDocs-sync-range-end: <sha>line; when the body has none and the subject ends with(#N)(a squash merge), readgh pr view <N> --json body -q .bodyfor that line. When a recorded<sha>exists andgit merge-base --is-ancestor <sha> "origin/$DEFAULT"holds, the baseline is<sha>; otherwise it isM. If none, ask the user for the last-known-good tag or SHA, or use the initial commit for a first sync. - Range.
git log <baseline>.."$T0" --oneline. Skip pure CI, workflow, and chore commits unless they change agent- or operator-facing behavior. - Size policy and rule layout. Before any edit, find what the repository requires.
- Read the tracked instructions: CLAUDE.md, AGENTS.md (
ls -l CLAUDE.md AGENTS.md: when one is a symlink to the other, the two paths are one file, measured once and edited once through the real file), every rule file (git ls-files '.claude/rules/'), and any contributing guide. Then find the size checks:git grep -n -E 'CLAUDE\.md|AGENTS\.md|\.claude/rules'across CI workflows, hook configs, scripts, and package or make targets, and read each definition that measures a guide (wc -c,stat, a byte or line comparison). Read check definitions to learn the policy; never run them for that. - For each guide, record its advisory target (a warning or "target") and its mandatory ceiling (a failure or a stated hard limit), each with its exact comparison and its source
file:line, and record its byte count now (wc -c). Keep each comparison as written: a warning above 16500 bytes and a failure at 17000 bytes or more mean 16999 bytes warns and proceeds, and 17000 bytes fails. - One file, one policy. When two guide paths are one file, a policy the repository states for either path is the policy of that file, whichever name the source uses. The same rule holds for a pair this sync keeps the same: when AGENTS.md is a real file, step 6 mirrors every CLAUDE.md body edit into it, so a policy the repository states for either name governs both files, and each file is measured against it.
- When more than one mandatory requirement applies to a guide, apply the strictest. Sources that cannot all hold, or a check definition that cannot be read or interpreted with confidence, are an unresolved conflict: record it with each source and the guides it governs; step 10 decides whether it blocks.
- Fallback. When the repository states no size policy under either guide name (CLAUDE.md or AGENTS.md, whether the two are one file or a mirrored pair), use this skill's generic thresholds for CLAUDE.md: above 35000 bytes, condense to under 30000; a result still above 40000 bytes fails as the mandatory ceiling. The fallback never applies when either name has a stated policy. A guide outside that pair gets only the policy the repository states for it.
- Note which agents load each rule file (step 6 placement). When AGENTS.md exists as a symlink or a mirrored copy, a rule Codex needs stays in a file Codex loads.
- Classify each commit (an unrelated-areas commit is classified per area):
| Category | Docs target | Action |
|----------|-------------|--------|
| New config field / flag | CLAUDE.md config; SKILL.md settings table; README.md only for a public top-level setting | Add field description |
| Changed default behavior | CLAUDE.md patterns; SKILL.md; README.md only if a documented example now contradicts the code | Update; note old vs new |
| New pluggable unit (plugin, command, integration, provider, theme) | Every doc that enumerates the set | Add one entry per doc |
| Bug fix (behavior change) | CLAUDE.md patterns, if pattern-level | Update the bullet |
| New CLI command / flag | SKILL.md commands; README.md Getting Started only if part of setup | Add usage |
| Setup / install flow change | README.md Getting Started; SKILL.md if operator-facing | Update the block |
| Removed field | Whichever doc lists it | Delete the row or bullet |
| Behavior reversal (fix reverted) | Whichever doc carries it | Note the revert explicitly |
| Internal refactor / test | Skip | none |
| Release milestone | Project notes file, if one exists (step 9) | Append version entry |
| Rationale or migration history (CHANGELOG.md exists) | CHANGELOG.md | Keyed entry there; CLAUDE.md keeps only the current invariant |
| Doc claim contradicted by code | Whichever doc carries the claim | Correct or delete it |
An area rule targets the matching existing rule file only under the step 6 placement rule; otherwise it targets CLAUDE.md.
- Audit docs near in-scope commits, including each rule file whose area or
paths:filter covers a file an in-scope commit touched. Verify surrounding claims: paths exist, symbol names match, defaults and versions are current, CLI flags accept the documented args. Delete or correct what the code contradicts; grep first, and never remove a claim you haven't verified is wrong. Stay scoped; if the docs look broadly drifted, flag it instead of rewriting. Check "current/active/default" claims against the deciding switch (build target, feature-flag default, active-environment key), never against the doc's own prior text. When a commit touches a directory of pluggable items,lsit and diff against every catalog, index, and README list. When one item is promoted and another retired, confirm the active state (self-referencing URLs, indexing directives, flags, defaults) flipped on both; if that invariant is real but undocumented, add a short rule. Never edit apaths:filter; when a commit renamed or removed a path that a filter names, report the stale filter to the user. - Edit CLAUDE.md and the rule files, then mirror into AGENTS.md. Edit only changed sections; terse bullets, one behavioral change each, under the section for their area; update any schema or config version constant a migration bumped; rewrite PR descriptions as imperative phrases. Placement: a rule that already lives in a rule file is edited there. A new area rule goes into an existing rule file that matches its area only when every agent that needs the rule loads that file. Claude Code loads it for matching files. Codex and other AGENTS.md readers need the rule when the repository has AGENTS.md, and they load the rule file only when the shared guide names it for that area. A rule shared by Claude and Codex stays in CLAUDE.md, and never moves to a rule file to make room when that would remove Codex coverage. With no suitable rule file, keep the repository's layout and put the rule in CLAUDE.md. Then AGENTS.md: symlink to CLAUDE.md, skip it and never open it for writing; CLAUDE.md a symlink to AGENTS.md, the edits above already went to that one file, so apply none again; real file, apply every CLAUDE.md body edit verbatim, keep its own intro line, and audit it per step 5; absent, skip.
- Edit SKILL.md (only if the repo has one). Add new keys to the settings table and the upgrade or post-update reference; update commands, reload scope, and safety-control sections when those surfaces change.
- Edit README.md (only if the public surface changed). Default to no edit. Touch it only for a new supported feature or integration, a new public unit in an enumerated list, a new top-level CLI subcommand, a setup or install change, or a public config example the code now contradicts. Tutorial tone: no
file:linecues, internals, or PR numbers; one line per list item in the existing format. Always check its enumerated lists for new public units. - Project notes file, if the repo keeps one with a Releases section and the range includes a version tag or release PR: append
- **vX.Y.Z** — YYYY-MM-DD: <summary> (PRs #N, #M). - Size check, after the last edit and before staging.
wc -ceach guide this sync edited and each guide a step 3 policy covers; a symlinked guide counts once. Compare each against its own policy with the policy's own comparisons.
- Over an advisory target or the fallback trigger: condense in place toward the target. The sync proceeds when no mandatory ceiling fails; report the warning with the byte count and its source.
- Failing a mandatory ceiling: shorten wording first, then move text to an existing destination the repository permits (a matching rule file under the step 6 placement rule, or CHANGELOG.md for history). Re-measure; a guide that still fails goes to step 11, unless it is an existing failure.
- Existing failure. A guide that already failed its ceiling at the step 3 byte count, and that this sync did not make larger (its final byte count is at or below the step 3 count), is an existing failure. Report it with both byte counts, the limit, and its source; it never goes to step 11 and never blocks the sync. Only a failure that this sync's edits cause or make worse goes to step 11.
- Unresolved conflict. A step 3 conflict that governs a guide whose final byte count is above its step 3 byte count goes to step 11. Report any other conflict with each source and the guide it governs; it never goes to step 11 and never blocks the sync.
- Condensing keeps every guardrail: symbol and file names, field lists, enum values, defaults, limits, version numbers, gotchas, concurrency and ordering rules, safety stops, live behavior, the Environment, Setup, Build & Deploy, and Testing blocks, lookup tables of IDs, paths, or prefixes, and repo-defined format conventions. Drop "why" prose where the rule alone is actionable, shipped-migration narrative, resolved-incident stories, duplicates, and examples that restate a rule; move history to CHANGELOG.md when it exists.
- Report the old and new byte count of each measured guide. For a guide over its target, recommend a split into rule files only when the repository permits more guide files (no instruction or check forbids them), and name the proposed areas; never perform a split during a sync.
- Mandatory-limit decision. When a guide still fails a mandatory ceiling that this sync's edits cause or make worse (step 10) and cannot fit without losing a guardrail, or step 10 sent a step 3 conflict here, report the guide, its original and proposed byte counts, the limit with its comparison, and its source
file:line(each source, for a conflict). Then ask the user once (AskUserQuestion): raise the limit (edit every tracked source that states it, and stage those files in step 12; when the failing limit is the step 3 fallback, no tracked source states it, so ask for the new ceiling and add one line to the guide's real file that states that ceiling and its comparison, which step 3 reads as the repository's policy for both guide names in the repeat of step 10 and in every later sync), approve specific cuts (name each guardrail the cut removes), or skip the edit (drop the edits that do not fit, which returns the guide to its step 3 byte count). For a conflict, ask instead: choose the policy (the user names the source that governs, or states the limit and comparison that apply; that choice replaces the conflict for this run, and step 12 records it with each source in the PR body), approve the edit as it is (the conflict stays reported in the PR body and no longer blocks), or skip the edit (as above, after which the conflict no longer blocks). Raise a limit or remove a guardrail only on that explicit approval. Apply the answer and repeat step 10, which no longer sends a resolved conflict here. When no answer can come (an unattended caller), the answer is to stop, or the guide still fails, the sync is blocked: reportblockedwith the numbers above, make no commit, push, or PR, keep the worktree and its uncommitted edits for the owner, and stop. - Land the edits through a PR. Run only when step 10 sent no guide to step 11, or step 11 resolved each one; an existing failure or a conflict that does not block (step 10) does not stop this step, and the PR body names it.
git statusin the worktree. Stage only the doc files this sync changed, plus the limit sources an approved step 11 change edited, by name. Nothing staged: report "no doc changes", remove the worktree and delete its unpushed local branch (git branch -D <branch>), and stop. Otherwise commit with a subject that matches the step 1 baseline pattern (docs: sync <what> after <range>, ordocs(sync): ...), a body lineDocs-sync-range-end: $T0(the full SHA), and the repo's commit footer, push the branch, open a PR against$DEFAULTwhose title begins with that same subject (plus any title suffix the repo's PR convention requires, such as[C<score>, <model>, <effort>]) and whose body follows the repo's PR body rules and carries the sameDocs-sync-range-end: $T0line, and report its number and URL. A standalone run leaves the PR open for review; a caller such assync-docs-releaseowns the merge decision.