md-optimizer: Use when the user asks to audit, optimize, review, clean up, or improve a CLAUDE.md file. Also use when Claude is ignoring instructions, behaving inconsistently, or the CLAUDE.md appears bloated or overloaded. Does not cover SKILL.md files, plugin commands, or other markdown files.
Installation
Details
Usage
After installing, this skill will be available to your AI coding assistant.
Verify installation:
npx agent-skills-cli listSkill Instructions
name: md-optimizer description: Use when the user asks to audit, optimize, review, clean up, or improve a CLAUDE.md file. Also use when Claude is ignoring instructions, behaving inconsistently, or the CLAUDE.md appears bloated or overloaded. Does not cover SKILL.md files, plugin commands, or other markdown files.
Audit and optimize a CLAUDE.md file against Claude Code best practices.
Freedom level: Rigid β Execute all six steps in the order listed. Do not skip, combine, or reorder them.
Table of Contents
- Step 1 β Resolve the target file
- Step 2 β Read and measure
- Step 3 β Run the 6-dimension audit
- Step 4 β Present the scored report
- Step 5 β Offer an optimized version
- Step 6 β Offer to write the optimized file
Step 1 β Resolve the target file
Determine which CLAUDE.md to audit using this priority order:
- Explicit path provided in the user's message (if present)
CLAUDE.mdin the current working directory (primary project location).claude/CLAUDE.mdin the current working directory (alternate, checked if primary absent)~/.claude/CLAUDE.md(global user-level)
Tell the user which file will be audited before continuing. If none of the four locations has a file and no argument was given, stop and ask the user to provide a path.
If a path was given but the file does not exist, stop and report the error clearly.
Step 2 β Read and measure
Read the target file in full, then collect these metrics:
- Line count β total lines in the file
- Instruction count (estimated) β count verb-starting bullet points, numbered directives, and bolded imperatives (e.g.,
**Always**,**Never**). Acknowledge a Β±30β50 variance in your estimate. - Section inventory β list every
##heading present - Sensitive data scan β flag any matches for:
sk-,ghp_,AKIA,xoxb-,-----BEGIN, or a label followed by a long alphanumeric string (e.g.,TOKEN=abc123...). Report matches verbatim so the user can verify. - Import scan β detect any
@path/to/filereferences in the file. List each one found. Note that imported content counts toward effective instruction load but is not visible in the raw line count.
Report all five metrics before proceeding to Step 3.
Step 3 β Run the 6-dimension audit
Score each dimension 0, 1, or 2. Maximum score: 12.
Full dimension definitions, scoring tables, and example audit output are in
references/audit-steps.md. Load that file before scoring.
Step 4 β Present the scored report
Output a structured report in this format:
## CLAUDE.md Audit Report
**File:** [path audited]
**Lines:** [n] | **Estimated instructions:** [n Β± 30β50]
### Scores
| Dimension | Score | Max |
|------------------------|-------|-----|
| Instruction Budget | [n] | 2 |
| Section Quality | [n] | 2 |
| 80% Rule Compliance | [n] | 2 |
| Progressive Disclosure | [n] | 2 |
| Safety & Hygiene | [n] | 2 |
| Structure | [n] | 2 |
| **Total** | **[n]** | **12** |
**Grade:** [see scale below]
Grade scale:
| Total | Grade |
|---|---|
| 10β12 | Optimized |
| 7β9 | Functional |
| 4β6 | Needs work |
| 0β3 | Rewrite |
After the table:
- Critical Issues β list any secrets found, plus dimension scores of 0, in priority order
- Per-dimension findings β one bullet per dimension with specific observations
- Top 3 recommendations β the highest-impact changes, in order
When Progressive Disclosure scores 0 or 1, include as a Top 3 item: "Use Step 5's rule-file generation to break path-specific content into .claude/rules/ files."
Step 5 β Offer an optimized version
Ask the user: "Would you like me to generate an optimized version of this file in the chat?"
If the user says yes, generate the optimized content in a code block in the chat (do not write to disk yet). Apply these transformations:
- Remove any credentials or secrets (replace with
[REDACTED - move to .env]) - Extract 80%-rule violations and path-specific content β these will be offered as
.claude/rules/files below, not embedded in the CLAUDE.md output - Condense padded or overly verbose sections (summarize rather than reproduce)
- Add stub headings for any missing key sections from Dimension 2
- Do not invent new content β preserve the user's intent and wording where possible
Offer to generate .claude/rules/ files:
For each section removed as an 80%-rule violation or path-specific content:
- Show the proposed rule file in a code block with
paths:frontmatter:
---
paths:
- "<glob>"
---
# <Descriptive Title>
- Rule bullet 1
- Rule bullet 2
- Rule bullet 3
- Check if
.claude/rules/exists. If not, ask: "The.claude/rules/directory does not exist. Should I create it?" - Ask: "Should I write this to
.claude/rules/<name>.md?" Wait for explicit confirmation before writing each file.
After the CLAUDE.md code block, show a separate callout:
To make this optimizer always available in your project, add the following to your CLAUDE.md
(replace <plugin-dir> with the path passed to --plugin-dir when loading this plugin):
@<plugin-dir>/skills/claude-md-optimizer/SKILL.md
If the user says no, stop here.
Step 6 β Offer to write the optimized file
After showing the optimized version, ask: "Should I write this to disk? Commit or back up your current CLAUDE.md first β this will overwrite it."
Wait for an explicit second confirmation before writing. Write only the file that was audited in Step 1.
More by shawn-sandy
View allUse when the user asks to stress-test, validate, critique, or find gaps and risks in an implementation plan. Does not execute the plan or apply fixes.
Reviews HTML/CSS and React/TypeScript code for WCAG 2.2 Level AA accessibility compliance. Use when the user asks to review code for accessibility, check WCAG compliance, identify accessibility issues, or audit components/pages for a11y standards. Applicable for code reviews, component development, and accessibility testing.
Use when the user wants to create path-specific rules, add rules for specific file types or directories, organize Claude rules by file type, or check whether the current project needs path-specific rules in .claude/rules/.
Review code for best practices, bugs, and security issues. Use when the user asks to review code, check for problems, or analyze code quality.
