claude-md-optimizer
npx machina-cli add skill smith-horn/product-builder-starter/claude-md-optimizer --openclawClaude MD Optimizer
Behavioral Classification: Guided Decision (ASK, THEN EXECUTE)
This skill analyzes CLAUDE.md files and proposes optimizations using progressive disclosure patterns. It NEVER makes destructive changes without explicit user approval. Always present the plan, get confirmation, then execute.
Quick Start
Phase 1: Analyze
- Read CLAUDE.md and count total lines
- Parse into sections and categorize each:
- Essential - Required for every session (build commands, test patterns, security rules)
- Reference - Needed occasionally (architecture docs, API references, troubleshooting)
- Redundant - Duplicates existing docs or overly verbose
Phase 2: Detect Constraints
- Check
.gitattributesforfilter=git-crypt diff=git-cryptpatterns - Identify encrypted paths (docs/, .claude/, etc.)
- Find safe unencrypted directory for sub-documents (prefer project root or subdirs)
- Scan for CI machine-readable dependencies (see constraints.md)
Phase 3: Plan
Present categorization table to user:
| Section | Lines | Category | Target | Rationale |
|---------|-------|----------|--------|-----------|
| Docker Commands | 45 | Reference | docker-guide.md | Used <10% of sessions |
| CI Health | 120 | Reference | ci-reference.md | Detailed reference rarely needed |
| Git-Crypt Setup | 30 | Essential | Keep inline | Unlock instructions (chicken-and-egg) |
Wait for user approval before proceeding.
Phase 4: Review
User confirms:
- Categorization is correct
- Sub-document names make sense
- Essential content remains inline
- Safe directory for sub-docs identified
Phase 5: Execute
- Create sub-documents in safe directory (verbatim extraction, NO summarization)
- Rewrite CLAUDE.md with Sub-Documentation Table at top
- Replace extracted sections with progressive disclosure links
- Preserve all Essential content inline
Phase 6: Validate
- Count lines before/after, report reduction percentage
- Diff all extracted content to verify zero information loss
- Confirm encryption constraints respected
- Present validation report to user
Sub-Documentation
| Document | Description |
|---|---|
| analysis.md | Content categorization methodology and heuristics |
| patterns.md | Progressive disclosure patterns and templates |
| constraints.md | Encryption detection and safe path selection |
| validation.md | Before/after diffing and information loss verification |
Essential Rules
Safety First
- ALWAYS present the plan before making changes
- NEVER make destructive edits without explicit user approval
- ALWAYS validate zero information loss after optimization
Content Preservation
- NEVER summarize or paraphrase content — verbatim extraction only
- ALWAYS keep encryption unlock instructions in main file (chicken-and-egg problem)
- ALWAYS keep security rules, test file patterns, behavioral reminders inline
- NEVER move content that is consulted in >50% of sessions
- ALWAYS keep content that CI scripts parse via regex (see CI Machine-Readable Content below)
Encryption Safety
- Sub-documents MUST be in unencrypted directories
- Check
.gitattributesforfilter=git-cryptpatterns - If entire project is encrypted, warn user and recommend decrypted subdirectory
CI Machine-Readable Content
- CI audit scripts may use regex to scan CLAUDE.md for specific literal strings
- ALWAYS scan for scripts that
readFileSync('CLAUDE.md')orgrepCLAUDE.md - Common patterns: deploy commands, function lists, config references
- Content matched by CI regex MUST remain in CLAUDE.md — extraction breaks CI
- See constraints.md for detection methodology
Progressive Disclosure
- Use Sub-Documentation Table pattern at top of rewritten CLAUDE.md
- Link to sub-docs using relative paths (e.g.,
[Docker Guide](./docker-guide.md)) - Preserve section headers with brief summary + link
- Target: >50% line reduction with zero information loss
Quick Reference
Content Tiers
| Tier | Criteria | Action |
|---|---|---|
| Essential | Used every session, unlocks workflow, defines behavior | Keep inline |
| Reference | Used occasionally, detailed specs, troubleshooting | Extract to sub-doc |
| Redundant | Duplicates existing docs, overly verbose, historical | Extract or remove |
Sub-Document Naming
- Use kebab-case domain names:
docker-guide.md,ci-reference.md,api-docs.md - Group related content:
troubleshooting/native-modules.md - Avoid generic names:
reference.md,docs.md
Progressive Disclosure Patterns
- Sub-Documentation Table - Links to extracted domains (use at top of CLAUDE.md)
- Quick-Reference+Link - Inline summary with "See X for details" link
- Compressed Table+Link - Condensed table with full version in sub-doc
- Summary+Link - Brief paragraph + link to comprehensive guide
Target Metrics
- Line reduction: >50% from original
- Information loss: 0% (verified via diff)
- Essential content: Remains inline
- Session impact: Minimal friction for common tasks
Example Output
Before: 850 lines After: 320 lines (62% reduction)
Extracted:
docker-guide.md(Docker commands and troubleshooting)ci-reference.md(CI health requirements and branch protection)deployment-guide.md(Deployment commands and configuration)troubleshooting.md(Diagnostic procedures consolidated)
Preserved inline:
- Encryption unlock instructions
- Security rules (secret handling, API keys)
- Test file patterns
- Build commands
- Behavioral reminders
Validation Checklist
- All extracted content is byte-for-byte identical (verified via diff)
- Sub-documents are in unencrypted directory
- Essential content remains inline
- Sub-Documentation Table is at top of rewritten CLAUDE.md
- All relative links work
- User approved the plan before execution
- Line reduction >50%
- No chicken-and-egg problems (encryption, authentication)
- CI scripts that regex-scan CLAUDE.md still pass (see CI Machine-Readable Content)
Error Handling
Entire project is encrypted: Warn user, suggest creating docs/claude/ or similar unencrypted subdirectory.
User rejects plan: Ask for feedback, iterate on categorization.
Information loss detected: Abort optimization, present diff to user, do not commit changes.
Ambiguous categorization: Default to Essential (keep inline), ask user to review.
Execution Context Requirements
This skill performs Write operations (creating sub-documents) and Edit operations (rewriting CLAUDE.md) during Phase 5.
Execution mode: This skill runs in the main conversation context (not via Task subagent dispatch). If invoked via a Task subagent, foreground execution is required for Write/Edit operations.
Required tools: Read, Write, Edit, Grep, Glob
Fallback: If Write/Edit tools are unavailable, present all sub-document content and the rewritten CLAUDE.md as text output for the user to save manually.
Reference: Subagent Tool Permissions
Notes
- This skill is project-agnostic and works with any CLAUDE.md file
- Always read the full CLAUDE.md before categorizing (context matters)
- Encryption constraints are project-specific, always check
.gitattributes - Validation is mandatory, never skip Phase 6
Source
git clone https://github.com/smith-horn/product-builder-starter/blob/main/skills/claude-md-optimizer/SKILL.mdView on GitHub Overview
Claude-md-optimizer analyzes oversized CLAUDE.md files and improves readability by classifying sections into Essential, Reference, and Redundant. It detects encryption constraints, creates verbatim sub-documents in a safe directory, and rewrites the main file with a Sub-Documentation Table. Changes are never destructive without explicit user approval.
How This Skill Works
The workflow follows six phases: Analyze, Detect Constraints, Plan, Review, Execute, and Validate. It preserves Essential content inline, identifies sub-documents for non-essential material, and uses a Sub-Documentation Table at the top of CLAUDE.md. Execution occurs only after user confirmation and includes validation of information loss and reduction.
When to Use It
- CLAUDE.md is too long and needs reduction
- You want to apply progressive disclosure to reveal content progressively
- You need to create sub-documents for non-essential sections while preserving essentials
- You must respect encryption constraints and store sub-documents in a safe directory
- You want a validation report showing line-count reductions and zero information loss
Quick Start
- Step 1: Analyze CLAUDE.md, count lines, and categorize sections into Essential, Reference, and Redundant
- Step 2: Detect constraints (encryption paths, .gitattributes patterns) and identify a safe sub-document directory
- Step 3: With user approval, create sub-documents, rewrite CLAUDE.md with a Sub-Documentation Table, and replace sections with progressive disclosure links
Best Practices
- Always present a plan and obtain explicit user approval before making changes
- Categorize content as Essential, Reference, or Redundant and keep Essential inline
- Place sub-documents in an unencrypted, safe directory and check encryption constraints
- Preserve CI machine-readable content and regex-based references during extraction
- Validate zero information loss and report the reduction percentage after optimization
Example Use Cases
- Large CLAUDE.md in an open-source project is optimized to reduce noise while preserving core instructions
- Internal corporate docs with encrypted sections are restructured into safe sub-docs with a top-level index
- Pre-release CLAUDE.md is rewritten to include a Sub-Documentation Table for quick navigation
- CI/CD docs are reorganized to separate essential tests and reference guidance without altering critical flows
- Compliance-related CLAUDE.md is preserved verbatim where needed and disclosed progressively
Frequently Asked Questions
Related Skills
sql-optimization
chaterm/terminal-skills
SQL 优化与调优
tuning
chaterm/terminal-skills
--- name: tuning description: 系统调优 version: 1.0.0 author: terminal-skills tags: [performance, tuning, sysctl, kernel, optimization] --- # 系统调优 ## 概述 内核参数、文件系统、网络优化技能。 ## 内核参数调优 ### 内存管理 ```bash # /etc/sysctl.d/99-memory.conf # 减少交换倾向 vm.swappiness = 10 # 脏页刷新 vm.dirty_ratio = 20 vm.dirty_backg
anthropics/skills
Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.
smart-sourcing
athola/claude-night-market
balancing accuracy with token efficiency.
doc-consolidation
athola/claude-night-market
'Merges valuable content into permanent documentation, then deletes source
performance-optimization
JanSzewczyk/claude-plugins
Performance optimization patterns for Next.js applications. Covers bundle analysis, React rendering optimization, database query optimization, Core Web Vitals, image optimization, and caching strategies.