CLAUDE.md Automation System
This document describes the Hybrid Approach for automating CLAUDE.md updates, ensuring it stays synchronized with the projectβs current state.
Overview
The automation system uses multiple layers to keep CLAUDE.md current:
- Template-based foundation for structure and consistency
- Smart scripts for dynamic content generation
- GitHub Actions for scheduled and event-driven updates
- Git hooks for immediate updates on significant changes
Architecture
CLAUDE.md Automation System
βββ CLAUDE.template.md # Template with auto-generated sections
βββ scripts/
β βββ claude_md_updater.py # Core updater script
β βββ install-git-hooks.sh # Git hooks installer
β βββ manage-git-hooks.sh # Hook management utility
βββ .github/workflows/
β βββ update-claude-md.yml # Automated updates via GitHub Actions
βββ .git/hooks/ # Local git hooks (installed)
βββ post-commit # Auto-update after commits
βββ pre-push # Validate before pushing
Components
1. Template System (CLAUDE.template.md
)
The template contains static content plus auto-generated sections marked with:
<!-- AUTO-GENERATED:SECTION_NAME -->
Content gets replaced here automatically
<!-- /AUTO-GENERATED:SECTION_NAME -->
Auto-generated sections:
DEPENDENCIES
- Dependencies from pyproject.tomlARCHITECTURE
- Current project file structureCOMMANDS
- Available commands and toolsCOMPLETED
- Implementation status based on project analysisRECENT
- Recent development focus from commit analysis
2. Smart Updater Script (scripts/claude_md_updater.py
)
Features:
- Analyzes project structure to generate architecture diagrams
- Extracts dependencies from
pyproject.toml
- Discovers available commands and tools
- Analyzes recent commits for development themes
- Updates only changed sections to minimize noise
Usage:
# Update all sections
python scripts/claude_md_updater.py
# Force update even if no changes detected
python scripts/claude_md_updater.py --force
# Update specific section only
python scripts/claude_md_updater.py --section deps
3. GitHub Actions Workflow (.github/workflows/update-claude-md.yml
)
Triggers:
- Push to main branch affecting key files (
src/
,tests/
,pyproject.toml
, etc.) - Weekly schedule (Sundays at 6 AM UTC)
- Manual workflow dispatch
Process:
- Checks out repository with full history
- Runs the updater script
- Commits and pushes changes if CLAUDE.md was updated
- Creates detailed summary of changes
4. Git Hooks
post-commit hook:
- Triggers after commits affecting significant files
- Auto-updates CLAUDE.md and amends the commit
- Provides immediate feedback on changes
pre-push hook:
- Validates CLAUDE.md sync before pushing
- Auto-commits updates if needed
- Ensures remote repository always has current CLAUDE.md
Setup
Initial Setup
- Install the system:
# Install git hooks ./scripts/install-git-hooks.sh # Test the updater python scripts/claude_md_updater.py
- Dependencies:
pip install toml # For pyproject.toml parsing
Hook Management
# Check hook status
./scripts/manage-git-hooks.sh status
# Remove hooks
./scripts/manage-git-hooks.sh remove
# Reinstall hooks
./scripts/manage-git-hooks.sh install
# Test updater
./scripts/manage-git-hooks.sh test
How It Works
Automatic Updates
- On commit (if changes affect
src/
,tests/
,pyproject.toml
, or workflows):git commit -m "feat: add new feature" β post-commit hook triggers β CLAUDE.md updated automatically β commit amended to include changes
- On push (validation):
git push β pre-push hook validates CLAUDE.md sync β auto-commits updates if needed β push continues with current CLAUDE.md
- Via GitHub Actions (weekly or on significant changes):
Weekly schedule or push to main β workflow runs updater script β commits and pushes changes β creates summary of updates
Manual Updates
# Update all sections
python scripts/claude_md_updater.py
# Force update (ignore change detection)
python scripts/claude_md_updater.py --force
# Update specific section
python scripts/claude_md_updater.py --section arch
What Gets Updated Automatically
Dependencies Section
- Extracts from
pyproject.toml
- Categorizes by purpose (Core, Development, Testing, etc.)
- Detects Jekyll, GitHub Actions, and container support
Architecture Section
- Generates ASCII tree of project structure
- Includes file comments for important files
- Focuses on key directories (
src/
,tests/
,docs/
, etc.) - Excludes noise (caches, temporary files)
Commands Section
- Discovers available scripts and tools
- Categorizes by purpose (Testing, Development, etc.)
- Includes common development workflows
Implementation Status
- Analyzes project to detect completed features
- Checks for key files to determine phase completion
- Updates automatically as project evolves
Recent Development Focus
- Analyzes commits from last 30 days
- Extracts development themes and achievements
- Identifies lessons learned from commit messages
- Updates monthly with current focus areas
Customization
Adding New Auto-Generated Sections
- In template (
CLAUDE.template.md
):<!-- AUTO-GENERATED:NEWSECTION --> Default content here <!-- /AUTO-GENERATED:NEWSECTION -->
- In updater script (
scripts/claude_md_updater.py
):def _update_newsection_section(self, content: str) -> str: new_content = self._generate_new_section_content() return self._replace_auto_generated_section(content, "NEWSECTION", new_content)
- Add to update pipeline:
def update_all_sections(self): # ... existing updates template_content = self._update_newsection_section(template_content)
Modifying Update Triggers
Git hooks (local development):
Edit the file patterns in .git/hooks/post-commit
:
if echo "$CHANGED_FILES" | grep -E "(src/|tests/|your-pattern)" > /dev/null; then
GitHub Actions (CI/CD):
Edit .github/workflows/update-claude-md.yml
:
paths:
- 'src/**'
- 'tests/**'
- 'your-new-pattern/**'
Troubleshooting
Common Issues
1. Updater script fails:
# Check dependencies
pip install toml
# Run with error output
python scripts/claude_md_updater.py --force
2. Git hooks not triggering:
# Check hook installation
./scripts/manage-git-hooks.sh status
# Reinstall hooks
./scripts/manage-git-hooks.sh install
3. Duplicates in dependencies:
- Edit
_extract_dependencies()
method to deduplicate - Common cause: multiple similar dependency entries
4. GitHub Actions workflow fails:
# Check workflow logs in GitHub Actions tab
# Common cause: Missing toml dependency or permission issues
Debug Mode
# Add debug output to updater script
python scripts/claude_md_updater.py --force 2>&1 | tee debug.log
# Check git hook execution
echo "Debug output" >> .git/hooks/post-commit
Benefits
β
Always current: CLAUDE.md stays synchronized with project state
β
Multiple triggers: Immediate (hooks), scheduled (Actions), and manual updates
β
Low maintenance: Template-based approach reduces manual editing
β
Smart updates: Only updates sections that actually changed
β
Comprehensive: Covers dependencies, architecture, commands, and status
β
Transparent: Clear commit messages and summaries of changes
Maintenance
Weekly Tasks
- Review GitHub Actions summary for update patterns
- Check for any failed automated updates
Monthly Tasks
- Review and update template content for static sections
- Verify automation is capturing new project developments
- Update hook triggers if project structure changes significantly
As Needed
- Add new auto-generated sections for evolving project needs
- Customize commit analysis patterns for better theme detection
- Adjust update frequency based on development velocity
This automation system ensures CLAUDE.md remains an accurate, up-to-date guide for Claude Code while minimizing manual maintenance overhead.