Skip to content

Conversation

@KimKyuHoi
Copy link

Summary

Fixes #731

This PR implements automatic deduplication of inline comments to prevent Claude from creating multiple separate comment threads on the same line during successive PR reviews.

Problem

When Claude Code Action reviews a PR multiple times (e.g., on each push via synchronized event), it would create duplicate inline comment threads on the same line instead of consolidating feedback in existing threads. This resulted in cluttered PRs with multiple separate threads saying the same thing.

Solution

Implemented auto-deduplication at the tool level:

  1. Added in_reply_to parameter to create_inline_comment tool

    • Allows manual thread replies when needed
    • Optional parameter for flexibility
  2. Automatic duplicate prevention logic

    • Before creating a new inline comment, the tool checks if a comment already exists on that line
    • If found, automatically converts the new comment to a reply in the existing thread
    • Only checks root comments (not replies) to find the thread starter
    • Logs deduplication actions to console for visibility
  3. Updated prompts

    • Informed Claude that duplicate prevention happens automatically
    • Simplified instructions - no manual workflow needed

Changes

Files Modified

  • src/mcp/github-inline-comment-server.ts: Added in_reply_to parameter and auto-deduplication logic
  • src/create-prompt/index.ts: Updated prompt instructions for both default and simple modes

How It Works

// Claude attempts to create an inline comment on line 10
create_inline_comment({ path: "src/index.ts", line: 10, body: "Use const" })

// Tool automatically:
// 1. Queries existing comments on the PR
// 2. Finds existing comment on line 10
// 3. Sets in_reply_to to the existing comment's ID
// 4. Creates reply instead of new thread
// Console: "Auto-deduplication: Found existing comment 123 on src/index.ts:10..."

Test Plan

-  All existing tests pass (632 tests)
-  TypeScript type checking passes
-  Code formatting verified

Manual Testing Scenario

1. Trigger Claude review on a PR
2. Claude creates inline comments
3. Push new changes (without fixing issues)
4. Trigger Claude review again
5. Expected: Claude replies to existing threads instead of creating duplicates
6. Verify: Console logs show "Auto-deduplication" messages

Benefits

- Cleaner PRs: Consolidated feedback in single threads
- Better UX: No duplicate threads cluttering the review
- Automatic: Works without Claude needing to manually check for duplicates
- Non-invasive: No test changes needed, minimal code changes

@KimKyuHoi
Copy link
Author

Refactoring

Extracted core deduplication logic into inline-comment-utils.ts for better testability:

  • findExistingRootComment(): Finds existing root comment on the same path/line
  • resolveInReplyTo(): Determines whether to reply to existing thread or create new one

Unit Tests

image

Added 17 unit tests with 100% coverage for inline-comment-utils.ts:

  • Root comment detection (skips replies, matches by line or original_line)
  • Reply resolution (explicit vs auto-detected)
  • Real-world scenarios (first review, second review dedup, different file/line)

@KimKyuHoi
Copy link
Author

@tombakerjr
@dltn
@ashwin-ant

Hello guys!
if you have time, would you be able to do a code review? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add ability to reply to existing inline comment threads

1 participant