claude-code-action icon indicating copy to clipboard operation
claude-code-action copied to clipboard

Feature: Update PR comments rather than continuously adding

Open ruchernchong opened this issue 8 months ago • 19 comments

The current implementation caused Claude bot to keep adding more comments to the PR rather than editing the original comment if there is already one. This resulted in a very long PR page.

The proposed implementation is to edit the comment that the Claude bot has already created.

ruchernchong avatar May 23 '25 14:05 ruchernchong

+1

swarajban avatar May 23 '25 15:05 swarajban

Can you clarify what you mean here? The current behavior is set up to have Claude edit its own comment in place. What do you expect to be different?

ashwin-ant avatar May 28 '25 02:05 ashwin-ant

We setup a PR summarizer workflow and it also adds rather than updating the original comment. Here's our simple workflow:

name: Pull Request Summary
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  code-review:
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    runs-on: ubuntu-latest
    steps:
      # Check out the code to allow git diff operations
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Fetch full history for accurate diffs

      - name: Run Code Review with Claude
        id: code-review
        uses: anthropics/claude-code-action@main
        with:
          # Define the review focus areas
          direct_prompt: 'Summarize the changes in this pull request. Focus on the most important changes and the impact of the changes.'
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          timeout_minutes: '5'

Note we're using @main instead of @beta if that makes a difference

robert-dean avatar May 28 '25 12:05 robert-dean

We are seeing the same issue (but using @beta, not @main). The documentation says that Claude updates it's own comments but that has not been the case, it adds a new comment every time. Would love to know how to get it to update the original comment instead if that's possible.

jazmine-payscore avatar May 30 '25 20:05 jazmine-payscore

Can you clarify what you mean here? The current behavior is set up to have Claude edit its own comment in place. What do you expect to be different?

In our usecase, we let claude-code-actions to comment PR's feedback and walkthrough, and we invoke it's workflow when PR is opend and syncronized(=pushed new commit).

In our case, claude-code-actions will create new comment on each syncronized, and this behavior causes too many comments and a bit noisy...

Perhaps, I need some parameter to let claude-code-actions to handle it's job with the existing comment instead of creating new comment.

Shinyaigeek avatar Jun 16 '25 02:06 Shinyaigeek

While waiting for a fix, I've added a simple job that run before Claude to remove old comments:

jobs:
  delete-old-claude-comments:
    # Currently, the claude-code-action does not support updating its own comments.
    # https://github.com/anthropics/claude-code-action/issues/37
    name: Delete old Claude comments
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write

    steps:
      - name: Clean up old comments
        uses: actions/github-script@v7
        with:
          script: |
            const params = { issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo }
            const comments = await github.rest.issues.listComments(params);

            for (const comment of comments.data) {
              if (comment.user.login === 'claude[bot]') {
                await github.rest.issues.deleteComment({ ...params, comment_id: comment.id });
              }
            }

  claude-review:
    needs: delete-old-claude-comments
    name: Run anthropics/claude-code-action@beta
    # ...

ericmatte avatar Jun 17 '25 20:06 ericmatte

@ericmatte great suggestion! Ended up doing the same.

tokudu avatar Jun 27 '25 18:06 tokudu

@Shinyaigeek thanks, I didn't realize this was regarding the code review flow in particular. I think that makes this a bit more sensible.

If we had Claude post an actual PR review instead of just a comment, would you also feel like it's too noisy?

ashwin-ant avatar Jun 27 '25 18:06 ashwin-ant

Ran a company-wide beta of the PR review workflow last week and it got noisy fast.

Posting an actual PR review would be great, (especially with true line comments!) because github takes care of marking old reviews outdated. Cursor's bug bot posts multiple comments, but marks the old comments outdated. This feels like a good middle ground: GH's comment edit history isn't made for looking at drastically different versions.

dereklucas avatar Jul 01 '25 17:07 dereklucas

@ashwin-ant Sorry for late reply 🙇 As @dereklucas said, I feel it is a good middle ground to add PR review instead of comment!

More ideally, I believe the following would be beneficial:

  • The ability to execute commands by editing existing comprehensive comments.
  • Comments would only be made on the diff of newly added commits, taking into account previous Claude code comments (or reviews).
    • Perhaps this could be resolved at the user-level prompt.

Shinyaigeek avatar Jul 07 '25 08:07 Shinyaigeek

Update : For my use case, use_sticky_comment: true option works perfectly! Claude code is now able to update its own PR comment without needing me to setup anything else.

ericmatte avatar Jul 28 '25 16:07 ericmatte

Ditto to @ericmatte . use_sticky_comment: true works for me to resolve this issue as well.

cansin avatar Aug 06 '25 05:08 cansin

use_sticky_comment: true doesn't work anymore - the bot keeps adding new comments.

v1.0.13

parfentjev-inv avatar Oct 29 '25 08:10 parfentjev-inv

When using use_sticky_comment: true I'm seeing the bot continue to add comments instead of updating. It is very noisy.

sighup avatar Nov 13 '25 02:11 sighup

Same use_sticky_comment: true doesn't work as expected

yusukegoto avatar Nov 19 '25 09:11 yusukegoto

Any update on this?

swarajban avatar Nov 25 '25 20:11 swarajban

I spotted that the bot ID was not the one expected. Debugged with a command below to my private repo. gh api /repos/{owner}/{repo}/issues/{issue_number}/comments

    "user": {
      "login": "github-actions[bot]",
      "id": 41898xxx,

Or have I set my workflow in a bad way?? This could be a clue to resolve this issue.

It's likely this could help my case https://github.com/anthropics/claude-code-action/pull/651

yusukegoto avatar Nov 30 '25 15:11 yusukegoto

I spotted that the bot ID was not the one expected. Debugged with a command below to my private repo. gh api /repos/{owner}/{repo}/issues/{issue_number}/comments

    "user": {
      "login": "github-actions[bot]",
      "id": 41898xxx,

Or have I set my workflow in a bad way?? This could be a clue to resolve this issue.

It's likely this could help my case #651

Sorry, I resolved my issue. The configuration was wrong.

Giving the explicit github_token: ${ secrets.GITHUB_TOKEN }} caused the wrong comment authoer github actions instead of claude[bot] . Removing github_token worked. But there was one notice. A PR removing github_token failed with 401 error below. But ignore this error and merge the PR. Once the new workflow config is set in a repo, Claude started reviewing on the following PRs.

App token exchange failed: 401 Unauthorized - Workflow validation failed. The workflow file must exist and have identical content to the version on the repository's default branch. If you're seeing this on a PR when you first add a code review workflow file to your repository, this is normal and you should ignore this error.

yusukegoto avatar Nov 30 '25 16:11 yusukegoto

@Shinyaigeek thanks, I didn't realize this was regarding the code review flow in particular. I think that makes this a bit more sensible.

If we had Claude post an actual PR review instead of just a comment, would you also feel like it's too noisy?

@ashwin-ant I believe this is the right way to go. So people can respond and resolve as if they were facing a real PR review comment. So, is there a way to do this now?

wangyoucao577 avatar Jan 02 '26 12:01 wangyoucao577