Sync Best Practices #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Best Practices | |
| on: | |
| schedule: | |
| - cron: "0 0 * * 0" # Every Sunday at midnight UTC | |
| workflow_dispatch: # Manual trigger | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Fetch latest docs | |
| run: | | |
| mkdir -p /tmp/docs-sync | |
| # Fetch machine-readable docs (no HTML parsing needed) | |
| # llms.txt is explicitly published by Anthropic for programmatic consumption | |
| HTTP_CODE=$(curl -sL -w "%{http_code}" "https://code.claude.com/docs/llms.txt" \ | |
| -o /tmp/docs-sync/llms.txt) | |
| if [ "$HTTP_CODE" != "200" ]; then | |
| echo "WARNING: llms.txt returned HTTP $HTTP_CODE — trying fallback URLs" | |
| # Fallback: try llms-full.txt | |
| curl -sL "https://code.claude.com/docs/llms-full.txt" \ | |
| -o /tmp/docs-sync/llms-full.txt 2>/dev/null || true | |
| fi | |
| # Also fetch full docs if available (larger, more detailed) | |
| curl -sL "https://code.claude.com/docs/llms-full.txt" \ | |
| -o /tmp/docs-sync/llms-full.txt 2>/dev/null || true | |
| # Generate a digest of CLAUDE.md-related topics from clean text | |
| cat /tmp/docs-sync/llms*.txt 2>/dev/null | \ | |
| grep -iE "CLAUDE\.md|CLAUDE\.local|token|hierarchy|memory|best practice|context|optimization|rules/|@import" | \ | |
| sort -u > /tmp/docs-sync/digest.txt | |
| echo "Fetched $(wc -l < /tmp/docs-sync/digest.txt) relevant lines from Anthropic docs" | |
| - name: Check for new content | |
| id: check | |
| run: | | |
| REFERENCE="skills/please-optimize-my-claude/references/best-practices.md" | |
| DIGEST="/tmp/docs-sync/digest.txt" | |
| if [ ! -s "$DIGEST" ]; then | |
| echo "No content fetched — skipping" | |
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| # Check if digest has lines NOT already covered in best-practices.md | |
| NEW_LINES=$(grep -cvFf "$REFERENCE" "$DIGEST" 2>/dev/null || echo "0") | |
| if [ "$NEW_LINES" -gt "5" ]; then | |
| echo "Found $NEW_LINES new lines not in current reference" | |
| echo "has_changes=true" >> "$GITHUB_OUTPUT" | |
| # Save digest for PR body | |
| cp "$DIGEST" /tmp/docs-sync/new-content.txt | |
| else | |
| echo "No significant new content found" | |
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Append new findings | |
| if: steps.check.outputs.has_changes == 'true' | |
| run: | | |
| REFERENCE="skills/please-optimize-my-claude/references/best-practices.md" | |
| # Add a sync marker with date | |
| echo "" >> "$REFERENCE" | |
| echo "<!-- SYNC: $(date -u '+%Y-%m-%d') -->" >> "$REFERENCE" | |
| echo "" >> "$REFERENCE" | |
| echo "### Recent Findings ($(date -u '+%Y-%m-%d'))" >> "$REFERENCE" | |
| echo "" >> "$REFERENCE" | |
| echo "The following topics were detected in updated Anthropic documentation. Review and integrate manually:" >> "$REFERENCE" | |
| echo "" >> "$REFERENCE" | |
| # Append new content as a review block | |
| head -30 /tmp/docs-sync/new-content.txt | sed 's/^/- /' >> "$REFERENCE" | |
| - name: Create PR | |
| if: steps.check.outputs.has_changes == 'true' | |
| run: | | |
| BRANCH="automated/sync-best-practices-$(date +%Y-%m-%d)" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Check if PR already exists | |
| EXISTING=$(gh pr list --base main --head "$BRANCH" --state open --json number --jq '.[0].number' 2>/dev/null || echo "") | |
| git checkout -B "$BRANCH" | |
| git add -A | |
| git commit -m "chore: sync best practices reference [auto]" | |
| git push --force-with-lease origin "$BRANCH" | |
| if [ -n "$EXISTING" ]; then | |
| gh pr comment "$EXISTING" --body "Updated with latest sync ($(date -u '+%Y-%m-%d %H:%M UTC'))." | |
| else | |
| gh pr create \ | |
| --title "chore: sync best practices reference [auto]" \ | |
| --body "$(cat <<'BODY' | |
| ## Summary | |
| Automated weekly sync detected new content in Anthropic's CLAUDE.md documentation. | |
| **Action required:** Review the appended findings in `references/best-practices.md` and either: | |
| - Integrate relevant updates into the structured sections above | |
| - Remove the "Recent Findings" block if nothing is new | |
| This PR was auto-generated by the sync-best-practices workflow. | |
| BODY | |
| )" \ | |
| --base main \ | |
| --head "$BRANCH" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |