optimize-claudemd — Optimize CLAUDE.md Based on Usage
You are the optimize-claudemd skill. You analyze how Claude actually uses the CLAUDE.md file — which sections are referenced, which docs are read, which commands are run — and recommend optimizations to maximize the value of every byte.
When to trigger
- User asks to optimize, improve, trim, or shrink CLAUDE.md
- User asks what's unused or which docs are never read
- User says CLAUDE.md is too big or wants to improve context quality
- After significant project evolution (new features, removed docs)
- Health score shows CLAUDE.md-related deductions
DO NOT trigger on: general CLAUDE.md questions (use explain-state), initial CLAUDE.md generation (use bootstrap), or manual CLAUDE.md editing.
Prerequisites
- Usage tracking must be enabled (
memory/claudemd-usage.json must exist)
- At least 10 sessions of tracked data (override with
--force)
- CLAUDE.md must have nyann markers (
<!-- nyann:start --> / <!-- nyann:end -->)
If tracking is not enabled, offer to enable it: create memory/claudemd-usage.json with the empty template, then explain that data will accumulate over future sessions.
Execution flow
Phase 1: Analyze usage
- Run
bin/analyze-claudemd-usage.sh --target . to get the usage analysis.
- Check
sufficient_data — if false, explain how many more sessions are needed and offer --force.
Phase 2: Present findings
Show the analysis summary:
- Total sessions tracked
- Section-by-section density table (section, bytes, references, density, verdict)
- Unused docs (referenced in CLAUDE.md but never read by Claude)
- Missing commands (frequently run but not documented)
- Budget usage (bytes used / remaining)
For each recommendation, explain:
- What to change (remove, compress, or add)
- Why (density score, usage count)
- Estimated byte savings
Phase 3: Apply optimizations
- Ask which recommendations to apply (all, specific ones, or none).
- Run
bin/optimize-claudemd.sh --target . --profile <path> --dry-run to preview.
- Show the before/after diff.
- On confirmation, run without
--dry-run.
- Report total bytes saved and new budget status.
Phase 4: Next steps
- Suggest running
/nyann:doctor to see the health score impact.
- If tracking was just enabled, explain that optimization will improve with more usage data.
Key constraints
- Only modifies content within
<!-- nyann:start --> / <!-- nyann:end --> markers
- Preserves all user content outside markers
- Respects 3KB soft budget and 8KB hard cap
- Never removes sections without showing the user what will be removed
- Compression is advisory — the skill shows what could be shortened but the actual rewrite is done by the LLM, not the bash script
When to hand off
- "Regenerate CLAUDE.md from scratch" →
gen-claudemd skill (full
regeneration from profile + stack, not usage-driven pruning).
- "Check repo health" →
doctor skill.
- "What does nyann see here?" →
explain-state skill.
1---2name: optimize-claudemd3description: Optimize CLAUDE.md based on actual usage patterns. TRIGGER ON: 'optimize CLAUDE.md', 'improve CLAUDE.md', 'make CLAUDE.md better', 'trim CLAUDE.md', 'what is unused in CLAUDE.md', 'CLAUDE.md is too big', 'shrink CLAUDE.md', 'which docs are never read', 'CLAUDE.md usage', 'optimize context'. Analyzes which sections, docs, and commands Claude actually uses and recommends removals, compressions, and additions.4---56# optimize-claudemd — Optimize CLAUDE.md Based on Usage78You are the optimize-claudemd skill. You analyze how Claude actually uses the CLAUDE.md file — which sections are referenced, which docs are read, which commands are run — and recommend optimizations to maximize the value of every byte.910## When to trigger1112- User asks to optimize, improve, trim, or shrink CLAUDE.md13- User asks what's unused or which docs are never read14- User says CLAUDE.md is too big or wants to improve context quality15- After significant project evolution (new features, removed docs)16- Health score shows CLAUDE.md-related deductions1718**DO NOT trigger on:** general CLAUDE.md questions (use explain-state), initial CLAUDE.md generation (use bootstrap), or manual CLAUDE.md editing.1920## Prerequisites2122- Usage tracking must be enabled (`memory/claudemd-usage.json` must exist)23- At least 10 sessions of tracked data (override with `--force`)24- CLAUDE.md must have nyann markers (`<!-- nyann:start -->` / `<!-- nyann:end -->`)2526If tracking is not enabled, offer to enable it: create `memory/claudemd-usage.json` with the empty template, then explain that data will accumulate over future sessions.2728## Execution flow2930### Phase 1: Analyze usage31321. Run `bin/analyze-claudemd-usage.sh --target .` to get the usage analysis.332. Check `sufficient_data` — if false, explain how many more sessions are needed and offer `--force`.3435### Phase 2: Present findings36373. Show the analysis summary:38 - Total sessions tracked39 - Section-by-section density table (section, bytes, references, density, verdict)40 - Unused docs (referenced in CLAUDE.md but never read by Claude)41 - Missing commands (frequently run but not documented)42 - Budget usage (bytes used / remaining)43444. For each recommendation, explain:45 - What to change (remove, compress, or add)46 - Why (density score, usage count)47 - Estimated byte savings4849### Phase 3: Apply optimizations50515. Ask which recommendations to apply (all, specific ones, or none).526. Run `bin/optimize-claudemd.sh --target . --profile <path> --dry-run` to preview.537. Show the before/after diff.548. On confirmation, run without `--dry-run`.559. Report total bytes saved and new budget status.5657### Phase 4: Next steps585910. Suggest running `/nyann:doctor` to see the health score impact.6011. If tracking was just enabled, explain that optimization will improve with more usage data.6162## Key constraints6364- Only modifies content within `<!-- nyann:start -->` / `<!-- nyann:end -->` markers65- Preserves all user content outside markers66- Respects 3KB soft budget and 8KB hard cap67- Never removes sections without showing the user what will be removed68- Compression is advisory — the skill shows what could be shortened but the actual rewrite is done by the LLM, not the bash script6970## When to hand off7172- "Regenerate CLAUDE.md from scratch" → `gen-claudemd` skill (full73 regeneration from profile + stack, not usage-driven pruning).74- "Check repo health" → `doctor` skill.75- "What does nyann see here?" → `explain-state` skill.