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

Reuse existing Claude Code comment instead of creating a new comment when commits are pushed to PRs

Open shuo-alma opened this issue 1 year ago • 18 comments

Currently, when we configure claude code action using the auto review example, a new comment will be created by the claude code action when new commits are pushed to a PR. We will see many comments made by Claude Code instead of always updating the same comment when we push changes to a PR. It would be super helpful to add an option of always updating the same comment instead of creating new ones.

shuo-alma avatar Jun 26 '25 22:06 shuo-alma

I was just coming here to create the same request!

What I think is happening is that claude will always create an initial tracking comment. Then for a review, it creates a github review which will be posted as a new comment.

I found that the tracking comment will then later get updated and repeat a lot of information from the review as well. As a workaround I added:

disallowed_tools: "mcp__github_file_ops__update_claude_comment"

that way claude isn't allowed to update the tracking comment, but what would be ideal for me is that it wouldn't post it in the first place or perhaps so that it deletes it after. I can already see the status of the github action at the bottom of the PR page and can click there for more info if I need.

One idea is to expose this as an input option, so it's configurable?

michaeljherrmann avatar Jun 26 '25 22:06 michaeljherrmann

I had initially thought this is what the use_sticky_comment parameter is for, but notice that enabling the parameter doesn't effect behavior. I don't actually see where this parameter (which gets passed as an env variable to the entrypoint scripts) gets used directly. I agree though, this is something that is desperately needed, as comments tend to be very long and quickly clutter up a PR.

phclark avatar Jul 03 '25 13:07 phclark

This is indeed what use_sticky_comment is for. Are you not seeing that behavior?

ashwin-ant avatar Jul 03 '25 13:07 ashwin-ant

Ah it looks like there was a bug in the previous PR (#211). I have a fix out here: https://github.com/anthropics/claude-code-action/pull/226

ashwin-ant avatar Jul 03 '25 13:07 ashwin-ant

No, I'm not seeing it. Looking through the PR that added the parameter a few days ago, I think I see the issue:

useStickyComment: process.env.STICKY_COMMENT === "true",

should be:

useStickyComment: process.env.USE_STICKY_COMMENT === "true",

phclark avatar Jul 03 '25 13:07 phclark

This is indeed what use_sticky_comment is for. Are you not seeing that behavior?

@ashwin-ant In: src/github/operations/comments/create-initial.ts, I see: if ( context.inputs.useStickyComment && context.isPR && !isPullRequestEvent(context) )

Would !isPullRequestEvent prevent auto PR review workflows from reusing the initial comment? Not sure if I'm reading the code correctly

darenc9 avatar Jul 03 '25 14:07 darenc9

I updated that PR and tested it just now to make sure it works as expected. Will work on getting it into today's release.

ashwin-ant avatar Jul 03 '25 14:07 ashwin-ant

I'm not sure if useStickyComment fully solves what I'm hoping for though. My understanding is that useStickyComment will still create an initial comment and then claude will keep updating that one. However, I've instructed claude to use mcp__github__create_pending_pull_request_review and mcp__github__submit_pending_pull_request_review which would then post a separate review comment as well. What I would like is a way to not have that initial comment posted at all.

michaeljherrmann avatar Jul 12 '25 22:07 michaeljherrmann

if i do understand i see the the sticky_comment works only for claude[bot] Will it be possible to make it work for the GitHub [bot] also?

ranyhb avatar Jul 17 '25 13:07 ranyhb

I just ran into this mildly confusing behaviour myself :)

https://github.com/anthropics/claude-code-action/blob/main/src/github/operations/comments/create-initial.ts#L41-L49

It definitely looks like it'll re-use the comment IF:

  • the specific user ID matches the claude bot
  • or the user is a Bot with "claude" in its name
  • or the exact body matches

I would love if this turned into two overridable parameters:

  • bot_user_id (so for folks who do not use the official claude bot, they can use their own custom user id, or use the github actions user id .. or whatever they want) default: 209825114, the official claude user id
  • bot_user_name_fragment (ie the substring to match for the bot user) default: claude

This would not change the default behaviour, but it would open up a lot of flexibility with custom setups for this.

Thoughts?

piotrb avatar Jul 18 '25 18:07 piotrb

I just ran into this mildly confusing behaviour myself :)

https://github.com/anthropics/claude-code-action/blob/main/src/github/operations/comments/create-initial.ts#L41-L49

It definitely looks like it'll re-use the comment IF:

  • the specific user ID matches the claude bot
  • or the user is a Bot with "claude" in its name
  • or the exact body matches

I would love if this turned into two overridable parameters:

  • bot_user_id (so for folks who do not use the official claude bot, they can use their own custom user id, or use the github actions user id .. or whatever they want) default: 209825114, the official claude user id
  • bot_user_name_fragment (ie the substring to match for the bot user) default: claude

This would not change the default behaviour, but it would open up a lot of flexibility with custom setups for this.

Thoughts?

yup, this is the main issue, i saw it too, i think that @valorkin could elaborate and solve this because he is the one who added it ?

ranyhb avatar Jul 21 '25 09:07 ranyhb

I think I'm going to try a workaround of making a new private App with claude in its name .. this should make it match the second condition .. having config options would still be nice ;)

piotrb avatar Jul 21 '25 17:07 piotrb

@ashwin-ant i think the best use-case is to refer to the @trigger_pharse as the user who is performing the commeting.. @piotrb what do you think of that ?

ranyhb avatar Jul 23 '25 06:07 ranyhb

@ashwin-ant i think the best use-case is to refer to the @trigger_pharse as the user who is performing the commeting.. @piotrb what do you think of that ?

I'm not sure what you mean by @trigger_parse

piotrb avatar Jul 24 '25 01:07 piotrb

Oh as an update here, if you just create a new github app in your org and name it with claude in its name, that seems to work perfectly well to make the sticky comment behaviour work as expected

piotrb avatar Jul 31 '25 18:07 piotrb

not ideal if you're internally planning to call your app something that doesn't contain Claude in its name ;) .. but a valid workaround .. I would still really appreciate this being configurable

piotrb avatar Aug 05 '25 16:08 piotrb

I opened a simple PR to make those two hardcoded values not so hardcoded :)

I'm hoping this can get merged quickly, since I don't really want to maintain this fork :)

piotrb avatar Aug 05 '25 18:08 piotrb

still waiting for the merge :)

ranyhb avatar Aug 24 '25 08:08 ranyhb