Get the FREE Ultimate OpenClaw Setup Guide →
npx machina-cli add skill smith-horn/product-builder-starter/claude-md-optimizer --openclaw
Files (1)
SKILL.md
7.9 KB

Claude 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

  1. Read CLAUDE.md and count total lines
  2. 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

  1. Check .gitattributes for filter=git-crypt diff=git-crypt patterns
  2. Identify encrypted paths (docs/, .claude/, etc.)
  3. Find safe unencrypted directory for sub-documents (prefer project root or subdirs)
  4. 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

  1. Create sub-documents in safe directory (verbatim extraction, NO summarization)
  2. Rewrite CLAUDE.md with Sub-Documentation Table at top
  3. Replace extracted sections with progressive disclosure links
  4. Preserve all Essential content inline

Phase 6: Validate

  1. Count lines before/after, report reduction percentage
  2. Diff all extracted content to verify zero information loss
  3. Confirm encryption constraints respected
  4. Present validation report to user

Sub-Documentation

DocumentDescription
analysis.mdContent categorization methodology and heuristics
patterns.mdProgressive disclosure patterns and templates
constraints.mdEncryption detection and safe path selection
validation.mdBefore/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 .gitattributes for filter=git-crypt patterns
  • 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') or grep CLAUDE.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

TierCriteriaAction
EssentialUsed every session, unlocks workflow, defines behaviorKeep inline
ReferenceUsed occasionally, detailed specs, troubleshootingExtract to sub-doc
RedundantDuplicates existing docs, overly verbose, historicalExtract 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

  1. Sub-Documentation Table - Links to extracted domains (use at top of CLAUDE.md)
  2. Quick-Reference+Link - Inline summary with "See X for details" link
  3. Compressed Table+Link - Condensed table with full version in sub-doc
  4. 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

  1. Step 1: Analyze CLAUDE.md, count lines, and categorize sections into Essential, Reference, and Redundant
  2. Step 2: Detect constraints (encryption paths, .gitattributes patterns) and identify a safe sub-document directory
  3. 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

Add this skill to your agents

Related Skills

Sponsor this space

Reach thousands of developers