#!/usr/bin/env python3 """ Claude.md Index Creator Creates or updates a master index of all claude.md files in a repository. Useful for understanding the documentation structure at a glance. Usage: python create_index.py [--output FILE] [--format FORMAT] Examples: python create_index.py /path/to/repo python create_index.py /path/to/repo --output CLAUDE_INDEX.md python create_index.py /path/to/repo --format tree """ import os import sys import argparse from pathlib import Path from typing import List, Dict import re def find_claude_md_files(root_path: Path) -> List[Path]: """Find all claude.md files, maintaining relative paths.""" claude_md_files = [] for dirpath, dirnames, filenames in os.walk(root_path): # Skip common ignored directories dirnames[:] = [d for d in dirnames if not d.startswith('.') and d not in { 'node_modules', '__pycache__', 'venv', 'env', 'dist', 'build' }] if 'claude.md' in filenames: full_path = Path(dirpath) / 'claude.md' claude_md_files.append(full_path) return sorted(claude_md_files) def extract_title_and_overview(file_path: Path) -> Dict[str, str]: """Extract the title and first line of overview from a claude.md file.""" try: with open(file_path, 'r') as f: content = f.read() lines = content.split('\n') # Extract title (first H1 header) title = None for line in lines: if line.startswith('# '): title = line[2:].strip() break # Extract first meaningful line after Overview section overview = None in_overview = False for line in lines: if re.match(r'^##?\s+(Overview|Purpose)', line, re.IGNORECASE): in_overview = True continue if in_overview: stripped = line.strip() # Skip empty lines and comments if stripped and not stripped.startswith('