Goal: Reduce CLAUDE.md from ~64KB (1,500 lines) to below 40k tokens while maintaining agent effectiveness
Architecture: Progressive disclosure pattern - keep essential project context and trigger tables in CLAUDE.md, externalize detailed documentation to /docs/claude-reference/ files that agents load on-demand
Tech Stack: Markdown, git worktrees, progressive disclosure patterns
File Size: 64KB, 1,500 lines, ~7,500 words Estimated Tokens: ~40-50k tokens (needs verification) Target: < 40k tokens (20-30% reduction required)
Largest Sections (candidates for externalization):
- GitHub Actions Automation: 180 lines (1191-1371)
- Observability and Monitoring: 151 lines (719-870)
- Advanced Orchestration Patterns: 139 lines (580-719)
- Hooks for Quality Assurance and Policy Enforcement: 134 lines (72-206)
- Compliance and Regulatory Alignment: 92 lines (206-298)
- Quick Reference: 88 lines (1103-1191)
- Enhanced Documentation References: 84 lines (1390-1474)
- Skills Development Standards: 77 lines (870-947)
Research Findings:
- 50-90% token reduction achievable with progressive disclosure
- Skills-based approach: 85-90% reduction per conversation
- Keep CLAUDE.md at 150-500 lines for optimal performance
- U-shaped attention pattern: beginning/end content processed best
- @ file references are NOT lazy-loaded (avoid them)
Verification Strategy:
-
Token Count Verification
- Measure current token count of CLAUDE.md using Claude API or approximation
- After optimization, verify token count is < 40k
- Document reduction percentage
-
Functionality Verification
- Verify all internal links work correctly
- Ensure external reference files are created
- Check that all workflows mentioned in docs are still accessible
- Verify Skills remain discoverable
-
Completeness Verification
- Ensure no content is lost (all content either in CLAUDE.md or externalized)
- Verify core principles and project standards remain clear
- Check that common workflows are still easily discoverable
-
Agent Performance Testing
- Test that agents can still find orchestration patterns
- Verify compliance guidance remains accessible
- Check that Skills discovery works
- Ensure hooks documentation is findable
NOTE: I will verify all references work before finalizing the optimization.
Step 1: Create reference documentation directory
mkdir -p docs/claude-referenceStep 2: Backup current CLAUDE.md
cp CLAUDE.md CLAUDE.md.backupStep 3: Measure current token count (estimate)
# Approximate: word count * 1.3 = token count
wc -w CLAUDE.md
# Document baselineStep 4: Create GitHub Actions reference document
- Extract "GitHub Actions Automation" section (180 lines)
- Create
docs/claude-reference/github-actions.md - Replace section with 3-5 line summary + link
- Estimated savings: ~175 lines
Step 5: Create Advanced Orchestration reference
- Extract "Advanced Orchestration Patterns" section (139 lines)
- Create
docs/claude-reference/advanced-orchestration.md - Replace with summary table + link to existing doc (it already references
docs/best-practices/15-Advanced-Orchestration-Patterns.md) - Estimated savings: ~130 lines
Step 6: Create Observability reference
- Extract "Observability and Monitoring" section (151 lines)
- Create
docs/claude-reference/observability.md - Replace with 5-10 line summary + link
- Estimated savings: ~140 lines
Step 7: Create Hooks reference
- Extract "Hooks for Quality Assurance and Policy Enforcement" section (134 lines)
- Create
docs/claude-reference/hooks-overview.md - Replace with 10-15 line summary + link (already references
docs/best-practices/05-Testing-and-Quality-Assurance.md) - Estimated savings: ~120 lines
Step 8: Create Compliance reference
- Extract "Compliance and Regulatory Alignment" section (92 lines)
- Create
docs/claude-reference/compliance.md - Replace with 5-10 line summary + link
- Estimated savings: ~85 lines
Step 9: Consolidate Skills documentation
- "Skills Development Standards" section already references templates
- Compress to just trigger table + link to
docs/best-practices/08-Claude-Skills-Guide.md - Estimated savings: ~60 lines
Step 10: Streamline Quick Reference
- "Quick Reference" section has redundant examples
- Keep only command list, move workflow examples to separate doc
- Create
docs/claude-reference/workflow-examples.md - Estimated savings: ~50 lines
Step 11: Compress Enhanced Documentation References
- Section lists documents that have been enhanced
- Replace with simple bullet list + links to actual docs
- Estimated savings: ~70 lines
Step 12: Compress code examples
- Replace verbose bash/python examples with minimal versions
- Link to full examples in reference docs
- Estimated savings: ~50 lines
Step 13: Consolidate redundant sections
- Identify overlapping content between sections
- Merge or cross-reference
- Estimated savings: ~30 lines
Step 14: Apply progressive disclosure to Command/Agent standards
- Keep trigger tables and essential patterns
- Move detailed specifications to references
- Estimated savings: ~40 lines
Step 15: Verify all internal links work
# Check for broken internal references
grep -n '\[.*\](.*\.md' CLAUDE.md
# Manually verify each link resolves correctlyStep 16: Verify external reference files exist
# List all reference docs that should exist
ls -lh docs/claude-reference/Step 17: Measure final token count
wc -w CLAUDE.md
# Calculate: words * 1.3 = estimated tokens
# Verify < 40kStep 18: Test agent accessibility
- Verify Skills are discoverable
- Check orchestration patterns are findable
- Ensure compliance guidance is accessible
- Test hooks documentation is reachable
Step 19: Update CHANGELOG.md
- Document optimization changes
- List externalized sections
- Note token reduction achieved
Step 20: Create optimization summary
- Document before/after metrics
- List all new reference files created
- Provide migration notes if needed
Conservative Estimate:
- Current: ~40-50k tokens
- Externalized content: ~800 lines
- Remaining: ~700 lines
- Target: ~28k tokens (30-40% reduction)
- Result: Below 40k threshold ✓
Optimistic Estimate:
- Additional compression: ~100 lines
- Remaining: ~600 lines
- Target: ~24k tokens (50% reduction)
- Result: Significantly below threshold ✓
Edge Case 1: Circular References
- Risk: External docs reference CLAUDE.md which references external docs
- Mitigation: Ensure reference hierarchy is one-way (CLAUDE.md → references only)
Edge Case 2: Lost Context
- Risk: Critical information becomes harder to find
- Mitigation: Keep comprehensive table of contents and clear links
Edge Case 3: Agent Performance Degradation
- Risk: Agents struggle to find information
- Mitigation: Test common workflows after optimization, adjust if needed
Edge Case 4: Broken Links
- Risk: Internal references break during reorganization
- Mitigation: Verify all links before committing (Step 15)
Edge Case 5: Documentation Drift
- Risk: Externalized docs become stale
- Mitigation: Add references to maintenance schedule
Edge Case 6: @ Reference Confusion
- Risk: Users might add @ references expecting lazy loading
- Mitigation: Add note in CLAUDE.md about NOT using @ for references
Question 1: Should we preserve ALL content or is some truly redundant?
- Context: Some sections like "Enhanced Documentation References" are meta-documentation about past integration work
- Recommendation: Archive historical integration notes, keep only current state
Question 2: How aggressive should compression be?
- Context: Could go minimal (150-300 lines) or moderate (500-700 lines)
- Recommendation: Target 500-600 lines for balance between brevity and usability
Question 3: Should external references use relative or absolute paths?
- Context: Git worktrees may affect path resolution
- Recommendation: Use relative paths from repository root:
docs/claude-reference/
Question 4: Should we create a Skills-based system for loading these references?
- Context: Could create Skills that load specific reference docs on demand
- Recommendation: Phase 2 work - start with simple links, evolve to Skills if needed
Question 5: Should the optimization be versioned?
- Context: Major restructuring might break existing workflows
- Recommendation: Yes - bump CLAUDE.md to version 3.1.0 with clear changelog
Behavior Testing:
- Agent can discover available Skills from CLAUDE.md
- Agent can find orchestration patterns through references
- Agent can access compliance guidelines through links
- Agent can locate hooks documentation through references
- Common workflows remain accessible within 1-2 steps
Verification Testing:
- All internal markdown links resolve correctly
- All reference files exist in documented locations
- Token count is < 40k (verified via word count * 1.3)
- No content is lost (diff between CLAUDE.md.backup externalized files)
- File size reduced by 30-50%
- Progressive Disclosure Pattern: Keep trigger tables and summaries, externalize details
- Directory Structure:
/docs/claude-reference/for optimization-specific docs - Link Format: Use relative paths without @ prefix to avoid eager loading
- Content Preservation: All content preserved, just reorganized
- Version Bump: 3.0.0 → 3.1.0 (minor version for non-breaking optimization)
- Backward Compatibility: All existing references still work via links
- U-Shaped Attention: Place most critical context at beginning and end
- External References: 6-8 new reference files in
/docs/claude-reference/ - Maintenance: Add reference files to documentation maintenance scan
- Validation: Verify links before commit, test agent accessibility after
-
Preservation vs Deletion: Should we preserve ALL content including meta-documentation about past integrations, or archive some historical notes?
-
Compression Level: How minimal should CLAUDE.md be? Target 150-300 lines (aggressive) or 500-700 lines (moderate)?
-
Skills Evolution: Should we create Skills for loading reference docs on-demand, or start with simple markdown links?
-
Version Numbering: Is 3.0.0 → 3.1.0 appropriate for this optimization, or should it be 3.0.0 → 4.0.0 for major restructuring?
-
Metrics Collection: Should we add instrumentation to track which reference docs are accessed most frequently for future optimization?