md-refactor
Skill0 starsChanged 2 months agoMITView on GitHub
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.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- docs-rebuildSkill
- intentSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 2 are distinctive, and 6 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.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 58
Every rule gets individual judgement — verified, placed, rewritten.
- Very specific: line 80
Read the baseline bundle — decisions, ledger, open items, what its design promised and what landed.
- Very specific: line 83
Read yourself, in full: a writing-for-agents style guide if you have one installed (e.g.
- Very specific: line 101
Run scripts/inventory.sh --root <workspace-root> --out <bundle>/evidence/inventory.tsv [--exclude PATTERN]...
- Very specific: line 119
Write evidence/loaders.md naming each fact's source and version.
- Very specific: line 128
Run scripts/crosscut.py <bundle>/evidence/inventory.tsv --terms <bundle>/evidence/retired-terms.tsv.
- Very specific: line 167
Write design.md from PRINCIPLES.md: goal with bounded, testable success criteria.
- Distinctive: line 180
Run the second-opinion pass (REVIEW.md), revise, freeze (REVIEW.md § Freeze), then run the cross-vendor adversarial gate with the slice …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
md-refactor
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:
- Global layer — the instruction file(s) each harness you use loads every session: e.g. Claude
Code
~/.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). - Library layer (optional) — the policy or docs library those global files point at.
- Workspace layer — every repo and subtree
AGENTS.md/CLAUDE.mdunder 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:
- AUDIT.md — the inventory and census scripts, loader re-derivation, the batch-audit brief and bucket taxonomy, cross-cutting and superseded-element checks, the decision catalogue.
- GRILL.md — the intent interview: the project's intent, each always-loaded rule's intent, and how to keep grilling when the operator says one is missing.
- PRINCIPLES.md — rungs, one normative owner, the thin always-loaded file, routine changes, the placement procedure and ledger, repo templates, lint tiers.
- MIGRATE.md — moves and the ledger tool, reference repointing, verification, probes, global-file install, deploying the library, shared ground and landing.
- REVIEW.md — the second-opinion pass, the adversarial slice templates for the design gate, and how to delegate the revision itself.
Standing preferences
These bind every run; a run's decisions never override them.
- Effectiveness and quality decide every change. Size budgets are goals; removing text to reach a number is the failure this skill exists to prevent.
- Every rule gets individual judgement — verified, placed, rewritten. A removal without a per-rule disposition is a defect.
- Hunt for elements superseded by other components: docs, hooks, scripts, generators, boilerplate.
- The design gets an independent second-opinion pass and a cross-vendor adversarial review before
approval. When no reviewer from a different vendor is reachable, the gate stays outstanding
(REVIEW.md); a same-vendor review never stands in for it, and approval does not waive it. Say so
and let the operator decide: they may direct the run onward with the deficit recorded in
status.mdand repeated in the final report, which is carrying it, never satisfying it. - Progress in small verified steps, and let the evidence and tooling grow alongside the work rather than ahead of it: build each measuring tool when a change needs it, as tested files in the run bundle.
- The author decides implementation and review mechanics; the operator decides scope, policy content, irreversible or outward-facing acts and protected-file writes. Bring the second kind, and only that kind.
- Upstream-owned files in forks stay byte-identical.
Phases
Each phase ends on its completion criterion. Keep status.md current; report progress by phase.
0 Orient
- Read the baseline bundle — decisions, ledger, open items, what its design promised and what
landed. On a first run there is none: record
no baseline (first run)instatus.mdand continue. - Read yourself, in full: a writing-for-agents style guide if you have one installed (e.g.
mattpocock/skills
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. - Consult any persistent memory or notes you keep on the corpus, and note decisions made since the baseline.
- Establish the scope from the argument, or ask one structured question for the workspace root, the global files, the declared exclusions, and the run-bundle repo.
- Copy
scripts/retired-terms.tsv(an example) into the bundle'sevidence/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.
1 Inventory
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.
2 Loader truth
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.
3 Audit
- Run
scripts/crosscut.py <bundle>/evidence/inventory.tsv --terms <bundle>/evidence/retired-terms.tsv; save its output asevidence/crosscut.md. - Fan out the read-only batch audits (AUDIT.md § Batch audit); persist each report to
evidence/audit-<batch>.mdas it lands. - While they run, do the checks the scripts cannot (AUDIT.md § Cross-cutting).
- Spot-check every high-impact auditor claim against the file itself before relying on it. A claim you have not verified is reported as "auditor-reported".
Done when every batch has a persisted report, every check has a result, and every claim you will use carries your own evidence.
4 Superseded elements
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.
5 Decisions and intent
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.
6 Design
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.
7 Review
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.
8 Migrate
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.
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.

