/agents-md-optimizer:agents-md-optimizerfrom MSApps Agents MD Optimizer
Audits and rewrites bloated agent-instruction files (CLAUDE.md, AGENTS.md) to stay under 200 lines, or authors new ones from scratch. Detects anti-patterns like embedded API docs and negative rules.
Ships in MSApps Agents MD Optimizer. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
CLAUDE.md is loaded into every Claude session for the project it belongs to. That means every line is a recurring tax on the context window — paid before any real work starts, across every session, forever. Most CLAUDE.md files drift into bloat: people copy-paste API docs, write step-by-step tutorials, hoard historical state, stack negative "don't do X" rules. The result is a ~2,000-token baseline cost that degrades focus and wastes budget.
The fix is to treat CLAUDE.md like a focused recipe book: essential guidance only, everything else extracted to a location that loads on-demand. This skill does two things:
CLAUDE.md, diagnose what's bloat, and produce a slimmed rewrite plus an extraction plan (what moves where).CLAUDE.md from scratch using the template.Detect mode from input:
CLAUDE.md for a new or undocumented project → author mode.If it's ambiguous, ask one clarifying question: "Are we trimming an existing one, or writing a new one?"
Every recommendation in this skill depends on understanding that CLAUDE.md isn't monolithic. Claude loads four layers in precedence order:
./CLAUDE.md — project-level, committed to the repo. This is what most people mean by "CLAUDE.md." Shared with every collaborator.~/.claude/CLAUDE.md — user-level, personal defaults that apply across every project. Communication prefs, your own account info, your shell aliases../CLAUDE.local.md — project-local overrides, gitignored. Personal notes about this specific repo that shouldn't be shared with collaborators.When you find content that doesn't belong in the project CLAUDE.md, the right extraction target is usually one of these other layers, not just "delete it."
Rule of thumb for extraction:
~/.claude/CLAUDE.md./CLAUDE.local.md./CLAUDE.mddocs/, referenced by pathA good project CLAUDE.md fits on roughly one screen (~200 lines max). See references/template.md for the full skeleton. The essential sections:
docs/ for anything deeper.Everything else is bloat. If it's not needed on every interaction with this repo, it belongs somewhere that loads on demand.
Read the target CLAUDE.md. Run scripts/audit.py <path> to get a structured report:
python3 scripts/audit.py <path-to-CLAUDE.md>
The script reports: line count, estimated token count (~4 chars/token heuristic), detected anti-patterns with line numbers, and section-by-section classification (essential / extract / delete).
If the file is already ≤200 lines and the audit finds no anti-patterns, tell the user it's already lean and stop. Don't invent problems.
For each section of the file, decide: keep, extract, or delete.
docs/hooks.md, ~/.claude/CLAUDE.md, CLAUDE.local.md, a new skill).See references/anti-patterns.md for the full list and rewrite patterns. Summary:
var" becomes "Use const/let." Positive instructions compile to shorter mental models and avoid reinforcing the thing you're trying to prevent.CLAUDE.md becomes See docs/api-reference.md for endpoint schemas..claude/skills/<name>/SKILL.md where it loads only when relevant.src/config.ts at session start" are almost always wasteful; Claude can read files on demand when the task requires them.CLAUDE.local.md. Anything dated (gcloud auth status from 3 weeks ago, "current sprint goal") is ephemeral and doesn't belong in a shared file.CLAUDE.md — the full replacement file, lean and ready to drop in.Show the before/after stats at the top of the plan: original line count, new line count, estimated token delta, percent reduction.
Do not silently lose content. Every deleted or moved section must appear somewhere in the extraction plan, so the user can audit the move.
Ask the user about:
docs/)?Batch these questions — two or three at a time, not one by one. Don't ask about every conceivable section; the template has defaults for missing info.
Fill in references/template.md. Keep each section tight. If a section has nothing real to put in it, delete the section rather than pad with "TBD" — missing sections are information, padding is noise.
Run scripts/audit.py on the result. It should pass all checks. If it doesn't (e.g., you accidentally included a 40-line JSON example), fix before delivering.
Whichever mode, the final output structure is:
## Stats
[before/after line and token counts, percent reduction if auditing]
## CLAUDE.md
` ` `md
[the full lean file, ready to save]
` ` `
## Extraction plan (audit mode only)
- Lines X–Y [topic] → [destination] — [one-line why]
- …
## Next steps
[concrete actions: create docs/foo.md with content X, add Y to ~/.claude/CLAUDE.md, etc.]
This skill only rewrites CLAUDE.md-family files (CLAUDE.md, AGENTS.md, CLAUDE.local.md). Never modify source code, configs, or secrets while doing this. Never delete the original until the user confirms the rewrite works — write the new file alongside the old one (e.g., CLAUDE.md.new) or show the diff and let them apply it.
If the audit would extract content to new files the user hasn't seen yet (a new docs/hooks.md, a new Skill), draft those too but clearly mark them as "proposed" — don't auto-create a web of new files without consent.
references/template.md — The lean CLAUDE.md skeleton with all essential sections and inline guidance. Read this before writing in author mode.references/anti-patterns.md — The catalog of common bloat patterns with before/after rewrite examples. Read this before auditing.scripts/audit.py — Runs a quantitative audit: line count, token estimate, anti-pattern detection by regex, section classification. Use it at the start of audit mode and again as a final check on any rewrite (author or audit).What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub msapps-mobile/claude-plugins --plugin agents-md-optimizerOther plugins' skills for the same job