AI Context Management
Keep AGENTS.md (canonical, shared) and CLAUDE.md (slim, Claude-only addendum)
aligned across a repo. Generates Copilot prompt-file shims so VS Code teammates
get parity slash commands.
Input: $ARGUMENTS — audit | reconcile | generate-prompts | migrate
(plus optional --repo <path> for cross-repo invocation).
Step 0 — Parse Mode
| Input | Mode | Effect |
|---|---|---|
audit |
AUDIT | Run npm run context:check; report findings; no writes |
reconcile |
RECONCILE | Detect drift, propose patch, apply after confirmation |
generate-prompts |
GENERATE_PROMPTS | Run npm run skills:regenerate; refresh .github/prompts/*.prompt.md |
migrate |
MIGRATE | Convert legacy CLAUDE.md-canonical → AGENTS.md-canonical |
| (no args) | AUDIT | Default to audit |
For reconcile and migrate, never write files without user confirmation —
present the proposed patch first, ask for apply / cancel, then act.
Step 1 — AUDIT Mode
Run the drift detector and summarise findings.
npm run context:check 2>&1
Exit codes: 0 = no findings, 1 = HIGH (blocking), 2 = MEDIUM only.
For each finding, show:
- Rule ID (e.g.
ctx/missing-import) - Severity (HIGH / MEDIUM)
- File and line
- Single-sentence why-it-matters (from the rule's documentation)
Detailed rule reference + severity rubric: references/drift-rules.md.
Step 2 — RECONCILE Mode
Goal: bring AGENTS.md and CLAUDE.md into alignment, preserving any genuine
Claude-only content in CLAUDE.md.
Steps:
- Run
npm run context:check:json > /tmp/drift.jsonto get structured findings. - For each finding:
ctx/missing-import→ propose adding@./AGENTS.mdnear top of CLAUDE.md.ctx/non-allowlist-heading→ propose moving the section to AGENTS.md and removing from CLAUDE.md.ctx/shared-section-drift→ propose deleting from CLAUDE.md (AGENTS.md wins for shared content).ctx/oversized-claude-md→ identify the largest non-allowlisted sections; propose moving them.
- Show a unified diff of proposed changes.
- Wait for
applyconfirmation. - Apply via Edit tool.
- Re-run
npm run context:checkto confirm green.
Full step-by-step playbook with conflict resolution: references/reconcile-playbook.md.
Step 3 — GENERATE_PROMPTS Mode
Goal: ensure every registered skill has a current .github/prompts/<name>.prompt.md
shim for VS Code Copilot users.
npm run skills:regenerate 2>&1 | grep -E 'prompt|verdict'
The script handles:
- Reading each
skills/<name>/SKILL.mdfrontmatter - Cross-referencing the
SKILL_ENTRY_SCRIPTSregistry inscripts/lib/install/copilot-prompts.mjs - Generating a managed-block-wrapped
.prompt.mdfor each registered skill - Pruning managed prompt files for skills no longer in the registry
If a skill is missing from the registry, it silently skips — add it to
SKILL_ENTRY_SCRIPTS to enable Copilot parity.
Format spec + registry editing rules: references/prompt-file-format.md.
Step 4 — MIGRATE Mode
For repos that currently use CLAUDE.md as the canonical project context (legacy
single-file pattern). Flips to AGENTS.md-canonical so the wider AI ecosystem
(Copilot, Cursor, Windsurf, Codex) reads the same content.
Steps:
- Detect current state:
AGENTS.mdexists? Drift vs CLAUDE.md?CLAUDE.mdis canonical (full content) vs slim addendum?
- If
CLAUDE.mdis canonical andAGENTS.mdis missing/drifted:- Propose: copy CLAUDE.md → AGENTS.md (rename heading)
- Propose: replace CLAUDE.md with
@./AGENTS.mdimport + Claude-only addendum
- Show diff. Wait for confirmation. Apply.
- Run
npm run context:checkto verify alignment. - Update brief generators that read CLAUDE.md to also/preferably read AGENTS.md
(see
scripts/lib/context.mjsINSTRUCTION_FILE_CANDIDATESfor the pattern).
Migration playbook with edge cases: references/canonical-flip.md.
Step 5 — Status Card
After every mode, emit a compact status card:
═══════════════════════════════════════
AI-CONTEXT-MANAGEMENT — <MODE> — Done
HIGH: 0 MEDIUM: 0 Files updated: 2
AGENTS.md: 349 lines CLAUDE.md: 41 lines
Next: npm run context:check (verify) | git diff (review)
═══════════════════════════════════════
Key Principles
- AGENTS.md is canonical — shared content lives there; CLAUDE.md is a slim addendum that imports it. Reverse only for legacy single-file Claude-only repos.
- Never write without confirmation in
reconcileandmigratemodes — show the diff first. - Preserve Claude-only content — items in the allowlist (
Slash Commands,Hooks,Memory,Local Overrides,Claude-only Notes, etc.) stay in CLAUDE.md. - Subdirectory AGENTS.md is fine — for monorepos. No sibling CLAUDE.md required at sub-paths.
- Drift detection runs on every PR —
npm run context:checkis wired into CI via.github/workflows/context-drift.yml.
Reference files
This skill's canonical flow is above. The files below cover specialised situations — read them only when the trigger applies.
| File | Summary | Read when |
|---|---|---|
references/drift-rules.md |
Per-rule severity, fix recipes, and the Claude-only heading allowlist for ctx/* rules. | A finding's rule ID is unfamiliar, OR you need to extend the allowlist for a custom heading. |
references/reconcile-playbook.md |
Step-by-step: bring drifted AGENTS.md and CLAUDE.md back into alignment safely. | RECONCILE mode is firing AND a finding has competing edits in both files. |
references/prompt-file-format.md |
Copilot .prompt.md format spec, frontmatter rules, and the SKILL_ENTRY_SCRIPTS registry. | Adding a new skill that needs Copilot parity, OR diagnosing why a skill has no .github/prompts/ shim. |
references/canonical-flip.md |
Migration guide: switch a repo from CLAUDE.md-canonical to AGENTS.md-canonical. | MIGRATE mode is firing on a legacy single-file repo. |
examples/slim-claude-md.md |
Canonical 30-line CLAUDE.md template after AGENTS.md flip. | Producing a slim CLAUDE.md from scratch in MIGRATE mode. |
examples/well-formed-agents-md.md |
100-150 line AGENTS.md exemplar with reasoned rules and standard sections. | A repo has no AGENTS.md and you're producing one from project knowledge. |
examples/monorepo-layout.md |
Root + per-package AGENTS.md layout for monorepos. | The repo has multiple packages and you're deciding where AGENTS.md goes. |
Source: Lbstrydom/claude-engineering-skills — distributed by TomeVault.