validate-branch-refs
Skill316 starsChanged 5 months agoMITView on GitHub
Use when checking a branch for drift before merge — references or claims a diff left stale: renamed/moved paths, removed exports, changed signatures, dropped env vars, dead doc links, outdated commands or version/port numbers. Triggers: "validate references", "check stale refs", "validate branch", "fix outdated docs", "/validate-branch-refs". Compares current branch vs base (default `dev`) and writes fixes.
- Reads credentials
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-content-typeSkill
- add-localeSkill
- add-ui-componentSkill
- consolidate-patternsSkill
- copy-componentSkill
- create-content-componentSkill
- find-componentSkill
- find-skillsSkill
- frontend-designSkill
- make-prSkill
- next-best-practicesSkill
- remove-azure-monitorSkill
- remove-cache-revalidationSkill
- remove-cdn-purgeSkill
- remove-sentrySkill
- resolve-review-suggestionsSkill
- review-prSkill
- seed-contentSkill
- start-workSkill
- strapi-schema-checkSkill
- vercel-react-best-practicesSkill
- write-testsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 34
If git status --porcelain is non-empty and not --dry-run, warn that uncommitted edits will mix with skill edits and ask whether to continue.
- Very specific: line 94
Write .claude/skills/validate-branch-refs/last-run.md (only add it to .gitignore on explicit user opt-in) with the inventory table, …
- Distinctive: line 104
Never auto-commit — the user reviews and commits.
- Distinctive: line 110
If a target file is already user-modified (git status), ask before stacking an edit on it.
- Very specific: line 116
If the inventory exceeds ~50 changed files or the scan yields ~200+ hits, delegate Phases 2–3 to a general-purpose subagent (inventory …
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<objective>
Detect drift between the current branch and a base (default `dev`): find references in the working tree to anything the diff changed — renamed/moved paths, deleted or renamed exports, changed signatures, removed env vars, dead links, outdated commands — and fix them. Then validate factual claims the diff did NOT touch but may still be wrong (e.g. a doc says `port 3000` but config now says `4000`).This skill writes edits — it is not read-only. Use --dry-run to preview.
</objective>
<arguments>
Parse `$ARGUMENTS` literally; a flag is active only if its token appears.- First non-flag token → base branch (default
dev). --dry-run→ report only; no writes, no commits.--scope=docs|code|all→ limit the reference scan.docs=*.md/*.mdx/README*/CHANGELOG*;code= everything else;all= default.--no-questions→ never prompt; log ambiguous findings as UNRESOLVED and continue.</arguments>
<preconditions>
1. `git rev-parse --is-inside-work-tree` is `true`, else abort.
2. `git rev-parse --verify <base>` succeeds (try `origin/<base>`; if still missing, ask for the base).
3. If `git status --porcelain` is non-empty and not `--dry-run`, warn that uncommitted edits will mix with skill edits and ask whether to continue.
4. `MERGE_BASE=$(git merge-base HEAD <base>)` — all diffs use `${MERGE_BASE}..HEAD`.
</preconditions><process>Phase 1 — Inventory the diff
In parallel:
git diff --name-status ${MERGE_BASE}..HEAD→ classify each path (A / D / M / R→rename / C).git diff ${MERGE_BASE}..HEAD -- '*.json' '*.yaml' '*.yml' '*.toml' '*.env*'→ config drift.git log ${MERGE_BASE}..HEAD --format='%H %s'→ commit context.
Build a table: change_type | old_path | new_path | symbols_removed | symbols_renamed | values_changed. For modified source files, pull removed/renamed top-level symbols from git diff -U0 (lines matching ^-(export|function|class|const|type|interface), language-aware: ts/tsx/js/jsx/py/go/rs/rb). For config files, diff changed keys (jq for JSON, plain diff otherwise).
Phase 2 — Reference scan
For each inventory row, git grep -nI the current tree (skips binaries, respects .gitignore) for:
- Paths — old path, basename, and extensionless form.
- Symbols — removed/renamed identifiers, word-boundary matched.
- Config values — old values of changed keys (env names, ports, URLs, versions).
- Commands — if
package.jsonscripts /Makefiletargets changed, their old names in docs. - Links — for renamed docs, old relative links and anchor slugs.
Exclude the changed files themselves and node_modules/, dist/, build/, .next/, coverage/, .git/. Honor --scope.
Phase 3 — Classify each hit
Produce findings: id | file:line | reference | inventory_row | proposed_fix | confidence.
- high — unambiguous rename/move, or a symbol renamed with a single definition.
- medium — a similarly-named symbol still exists, or multiple move candidates match.
- low — a Phase 4 claim that maps to no diff row.
Phase 4 — Claim validation (independent of the diff)
Scan docs (README*, docs/**, *.md, *.mdx) for claims regardless of the diff:
- backticked file paths → exist on disk?
- repo-internal anchors → anchor exists?
- env vars (
process.env.X,${X}, bash fences) → defined somewhere (.env.example, config, code)? pnpm/npm run/yarnscripts → exist in the nearestpackage.json?- ports, version pins → match config/package files?
- quoted signatures or types → symbol still has that shape?
Each failure is a low-confidence finding.
Phase 5 — Resolution
In confidence order (high → medium → low):
- high, not
--dry-run→ applyEditand log it. - medium / low →
AskUserQuestionwith file:line, the reference, candidate fixes, and Skip / "mark UNRESOLVED" / "intentional" options. Under--no-questions, mark UNRESOLVED.
Batch related questions (same symbol or renamed path) into one multiSelect call. Cap at 8 AskUserQuestion calls per run; mark the remainder UNRESOLVED.
Phase 6 — Report
Write .claude/skills/validate-branch-refs/last-run.md (only add it to .gitignore on explicit user opt-in) with the inventory table, per-finding outcome (APPLIED / SKIPPED / UNRESOLVED + reason), and counts. Then print a compact chat summary:
Branch: <head> vs <base> (merge-base <short-sha>)
Inventory: <n> files (<A>A <D>D <M>M <R>R)
Findings: <total> (high <h>, medium <m>, low <l>)
Outcome: applied <a>, skipped <s>, unresolved <u>
Report: .claude/skills/validate-branch-refs/last-run.mdNever auto-commit — the user reviews and commits.
</process>
<safety>
- Edit only — never delete files, never push or touch the base branch.
- A fix that would change semantics (not just a reference) → downgrade to medium and ask.
- If a target file is already user-modified (`git status`), ask before stacking an edit on it.
- On any `git` failure, surface stderr and abort the phase — don't continue silently.
- On failure, report the error clearly and leave no half-applied edits.
</safety><delegation>
If the inventory exceeds ~50 changed files or the scan yields ~200+ hits, delegate Phases 2–3 to a `general-purpose` subagent (inventory table embedded in the prompt; it returns the findings table). Keep Phase 5 resolution on the main thread to preserve `AskUserQuestion` control.
</delegation>Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

