vibetunnel/.github/workflows/cleanup-claude-comments.yml
Peter Steinberger c24749458c Fix Claude bot creating multiple PR comments
- Add automatic cleanup of old Claude comments after each review
- Create reusable cleanup script that intelligently handles different comment types
- Keep only the most recent successful review visible
- Collapse (not delete) old reviews, errors, and status messages
- Add manual cleanup workflow that can be triggered or run on schedule
- Preserve comment history while keeping PRs readable

This solves the issue where Claude creates new comments instead of updating
existing ones, since the anthropics/claude-code-action@beta doesn't support
comment updates natively.
2025-06-28 15:22:05 +02:00

89 lines
No EOL
2.7 KiB
YAML

name: Cleanup Claude Comments
on:
# Manual trigger
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request number to clean up'
required: true
type: number
# Also run when PR is closed or merged
pull_request:
types: [closed]
# Run on a schedule to clean up old PRs
schedule:
- cron: '0 0 * * 0' # Weekly on Sunday
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout scripts
uses: actions/checkout@v4
with:
sparse-checkout: |
.github/scripts/cleanup-claude-comments.js
- name: Cleanup Claude comments on specific PR
if: github.event_name == 'workflow_dispatch'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const cleanup = require('./.github/scripts/cleanup-claude-comments.js');
// Override context for manual trigger
const customContext = {
...context,
issue: { number: ${{ github.event.inputs.pr_number }} }
};
await cleanup({ github, context: customContext, core });
- name: Cleanup Claude comments on closed PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const cleanup = require('./.github/scripts/cleanup-claude-comments.js');
await cleanup({ github, context, core });
- name: Cleanup Claude comments on all recent PRs
if: github.event_name == 'schedule'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const cleanup = require('./.github/scripts/cleanup-claude-comments.js');
// Get recent PRs
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
sort: 'updated',
direction: 'desc',
per_page: 50
});
for (const pr of prs) {
core.info(`Checking PR #${pr.number}: ${pr.title}`);
const customContext = {
...context,
issue: { number: pr.number }
};
try {
await cleanup({ github, context: customContext, core });
} catch (error) {
core.warning(`Failed to cleanup PR #${pr.number}: ${error.message}`);
}
}