Re-evaluate and refactor your agent instruction files (AGENTS.md, CLAUDE.md, global overlays, policy docs) for effectiveness — inventory, loader truth, audit, decisions, design, review, ledgered migration.
Ships in md-refactor. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Re-evaluate your agent instruction corpus and refactor it for effectiveness: in any session, the rule that binds the moment is in the agent's context, true, unambiguous, and stated once. Size is an outcome, never the target — text leaves only with a ledger reason.
Scope. The corpus is:
~/.claude/CLAUDE.md, Pi ~/.pi/agent/AGENTS.md, Codex ~/.codex/AGENTS.md, plus any
cross-harness global file you keep that several harnesses read (e.g. ~/AGENTS.md).AGENTS.md / CLAUDE.md under the WORKSPACE
ROOT the operator (the person you are working for) names.The workspace root is the first argument; if it is absent, establish the whole scope with one structured question in Phase 0. Exclusions are operator-declared (archives, vendored trees, generated trees), recorded with a reason — never a hardcoded path. An argument narrows the scope (one repo, one batch, one layer); the phases stay the same.
Run bundle. Each run owns docs/instruction-refactor[-YYYY-MM-DD]/ in a repo the operator
names (ask in Phase 0 if it was not given): status.md (current phase, next step), decisions.md,
design.md, evidence/, ledger/. Everything a phase produces lands there the moment it exists
and is committed — scratch and run-scoped directories are not durable. The newest earlier bundle
is the baseline.
Structured questions go through AskUserQuestion on Claude Code or ask_user_question on Pi.
On a harness with no question tool (Codex, or Pi without the extension), present the same options
numbered in one message; the operator answers by number or in their own words.
Reference — read the section a phase names. Script and file paths in this skill are relative to the skill's own directory; a harness that does not show you that directory resolves them against wherever the skill is installed:
These bind every run; a run's decisions never override them.
status.md and repeated in the final report, which is carrying it, never satisfying it.Each phase ends on its completion criterion. Keep status.md current; report progress by phase.
no baseline (first run) in status.md and
continue.writing-for-agents; otherwise PRINCIPLES.md is the style authority), your
global file(s), each harness overlay, and the
library index. Every later judgement depends on them; a subagent's summary of them is a lead,
never a substitute.scripts/retired-terms.tsv (an example) into the bundle's evidence/ and replace its rows
with the systems your corpus has retired; it may end up empty. Phase 3 passes that copy to
--terms.Done when you can state, from your own reading, the baseline's decisions and open items (or that there is no baseline), what the always-loaded layer says today, and the corpus's exact scope.
Run scripts/inventory.sh --root <workspace-root> --out <bundle>/evidence/inventory.tsv [--exclude PATTERN]... (AUDIT.md § Inventory). Confirm each file's candidate class; record
coverage gaps in evidence/coverage.md — exit status 3 means the inventory was written but is
incomplete, and every stderr line it printed is a gap to record.
Done when every instruction file has a confirmed class and every exclusion a reason. This inventory is the ledger's denominator.
Re-derive what each harness loads from its installed source and its current documentation — never
from memory or the baseline (AUDIT.md § Loaders). A harness whose source and documentation you
cannot read is recorded in evidence/loaders.md as unmeasured (<why>); it is never reported as
derived. Then check transport: which extensions or proxies
rewrite the request on each provider route, and what they drop — by capturing the outgoing request,
never by inference (MIGRATE.md § Probes); with no proxy and a single provider route, record that as
the transport result. Measure always-loaded bytes for representative working directories, the
global and workspace layers separately from repo files.
Write evidence/loaders.md naming each fact's source and version.
Done when, for each layer you load from — global, workspace, repo — you can list exactly which files each harness you use loads and which of them reach the model on each provider route (on a single direct route, the loaded-file list is the answer). Cover at least three working directories where the corpus has that many; where it has fewer, cover every directory it has and say so.
scripts/crosscut.py <bundle>/evidence/inventory.tsv --terms <bundle>/evidence/retired-terms.tsv; save its output as evidence/crosscut.md.evidence/audit-<batch>.md as it lands.Done when every batch has a persisted report, every check has a result, and every claim you will use carries your own evidence.
For each candidate (AUDIT.md § Superseded), establish from live state what now owns the meaning, or that nothing does, and disposition it: remove | investigate | keep as a fence.
Done when each candidate has evidence and a disposition. "No importers found" alone is a lead and never yields remove.
Enumerate the operator's decisions (AUDIT.md § Decision catalogue) and ask them as one
questionnaire through the structured question tool: one question per decision, sized to the tool —
a tool that pages a long questionnaire takes the whole set in one call, one that caps questions per
call is fed in batches of that many, and with no tool the numbered message may take several turns.
A decision with more positions than one question holds is split across questions. On a
re-evaluation, carry unchanged decisions from the baseline and re-ask only those whose context
changed. Record answers verbatim in decisions.md.
Then grill for intent (GRILL.md): the refactor's own intent — purpose, top invariant, non-goals,
audience, core bet, evidence, posture — and each always-loaded rule's intent, the rule the design
judges its text against. Keep grilling names a missing intent: trace the operator's own failing
example end to end before asking again.
Done when every decision is chosen or negative, and the project intent and the rule-intent register are approved and written down.
Write design.md from PRINCIPLES.md: goal with bounded, testable success criteria; decisions;
evidence, split into verified and auditor-reported; principles; rungs and load map; the thin
always-loaded file and its delivery mechanisms; the placement procedure and ledger; library
restructure; repo templates; superseded table; generators and lint; verification; rollout; risks;
alternatives. Name the acceptance bars in it — the representative directories, the probe kinds with
their keys and grading, the lint check set with a failing fixture per check — and let each bar's
tooling be built when the change needs it (MIGRATE.md). Commit the design with its evidence.
Done when every factual claim cites evidence or is labelled a lead, every section traces to evidence or a decision, and every acceptance bar names the tool that will measure it.
Run the second-opinion pass (REVIEW.md), revise, freeze (REVIEW.md § Freeze), then run the cross-vendor adversarial gate with the slice templates (REVIEW.md). Triage, revise narrowly, respect the round cap, and ask for approval with the verdict and every advisory's disposition.
Done when the gate completes and the operator approves the design. With no different-vendor
reviewer reachable the gate stays outstanding: report that, and either stop here or continue only
on the operator's explicit direction, with the deficit recorded in status.md and repeated in the
final report.
Execute in small verified steps, one layer or wave at a time — per step: moves and ledger rows, references repointed, lint, probes, install or commit (MIGRATE.md). Write a plan only where the work is genuinely multi-part (an implementation-plan step, if such a skill is installed), and keep implementation in real files with tests: a plan whose code lives in its Markdown grows with every review round and cannot be executed as written.
Done when the ledger covers the whole denominator, the lint's deterministic checks pass, the probes show no regression against today's file on each harness, the wiring checks pass, the live files are installed and verified through ordinary sessions, and every repo's commits have landed.
AUDIT.md (opens in a new tab)GRILL.md (opens in a new tab)MIGRATE.md (opens in a new tab)PRINCIPLES.md (opens in a new tab)REVIEW.md (opens in a new tab)agents/openai.yaml (opens in a new tab)scripts/crosscut.py (opens in a new tab)scripts/inventory.sh (opens in a new tab)scripts/retired-terms.tsv (opens in a new tab)test/scripts.test.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/md-refactor:md-refactorfrom md-refactor
npx claudepluginhub rasatpetabit/ai-skills --plugin md-refactor