From d74241394971b2882688ac82e0b27908dc37ad33 Mon Sep 17 00:00:00 2001 From: Boris Cherny Date: Tue, 6 Jan 2026 18:46:12 -0800 Subject: [PATCH] feat: Add comment-on-duplicates script for safer duplicate handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `gh issue comment:*` permission with a constrained script that: - Only accepts validated issue numbers - Enforces max 3 duplicates - Uses a fixed comment format - Prevents arbitrary comment content injection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .claude/commands/dedupe.md | 27 +++------- scripts/comment-on-duplicates.sh | 86 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 21 deletions(-) create mode 100755 scripts/comment-on-duplicates.sh diff --git a/.claude/commands/dedupe.md b/.claude/commands/dedupe.md index c41f2727..6641b5d8 100644 --- a/.claude/commands/dedupe.md +++ b/.claude/commands/dedupe.md @@ -1,5 +1,5 @@ --- -allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(gh issue comment:*) +allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(./scripts/comment-on-duplicates.sh:*) description: Find duplicate GitHub issues --- @@ -11,28 +11,13 @@ To do this, follow these steps precisely: 2. Use an agent to view a Github issue, and ask the agent to return a summary of the issue 3. Then, launch 5 parallel agents to search Github for duplicates of this issue, using diverse keywords and search approaches, using the summary from #1 4. Next, feed the results from #1 and #2 into another agent, so that it can filter out false positives, that are likely not actually duplicates of the original issue. If there are no duplicates remaining, do not proceed. -5. Finally, comment back on the issue with a list of up to three duplicate issues (or zero, if there are no likely duplicates) +5. Finally, use the comment script to post duplicates: + ``` + ./scripts/comment-on-duplicates.sh --base-issue --potential-duplicates + ``` Notes (be sure to tell this to your agents, too): - Use `gh` to interact with Github, rather than web fetch -- Do not use other tools, beyond `gh` (eg. don't use other MCP servers, file edit, etc.) +- Do not use other tools, beyond `gh` and the comment script (eg. don't use other MCP servers, file edit, etc.) - Make a todo list first -- For your comment, follow the following format precisely (assuming for this example that you found 3 suspected duplicates): - ---- - -Found 3 possible duplicate issues: - -1. -2. -3. - -This issue will be automatically closed as a duplicate in 3 days. - -- If your issue is a duplicate, please close it and 👍 the existing issue instead -- To prevent auto-closure, add a comment or 👎 this comment - -🤖 Generated with [Claude Code](https://claude.ai/code) - ---- diff --git a/scripts/comment-on-duplicates.sh b/scripts/comment-on-duplicates.sh new file mode 100755 index 00000000..3a057203 --- /dev/null +++ b/scripts/comment-on-duplicates.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# +# Comments on a GitHub issue with a list of potential duplicates. +# Usage: ./comment-on-duplicates.sh --base-issue 123 --potential-duplicates 456 789 101 +# + +set -euo pipefail + +REPO="anthropics/claude-code" +BASE_ISSUE="" +DUPLICATES=() + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --base-issue) + BASE_ISSUE="$2" + shift 2 + ;; + --potential-duplicates) + shift + while [[ $# -gt 0 && ! "$1" =~ ^-- ]]; do + DUPLICATES+=("$1") + shift + done + ;; + *) + echo "Unknown option: $1" >&2 + exit 1 + ;; + esac +done + +# Validate base issue +if [[ -z "$BASE_ISSUE" ]]; then + echo "Error: --base-issue is required" >&2 + exit 1 +fi + +if ! [[ "$BASE_ISSUE" =~ ^[0-9]+$ ]]; then + echo "Error: --base-issue must be a number, got: $BASE_ISSUE" >&2 + exit 1 +fi + +# Validate duplicates +if [[ ${#DUPLICATES[@]} -eq 0 ]]; then + echo "Error: --potential-duplicates requires at least one issue number" >&2 + exit 1 +fi + +if [[ ${#DUPLICATES[@]} -gt 3 ]]; then + echo "Error: --potential-duplicates accepts at most 3 issues" >&2 + exit 1 +fi + +for dup in "${DUPLICATES[@]}"; do + if ! [[ "$dup" =~ ^[0-9]+$ ]]; then + echo "Error: duplicate issue must be a number, got: $dup" >&2 + exit 1 + fi +done + +# Build comment body +COUNT=${#DUPLICATES[@]} +if [[ $COUNT -eq 1 ]]; then + HEADER="Found 1 possible duplicate issue:" +else + HEADER="Found $COUNT possible duplicate issues:" +fi + +BODY="$HEADER"$'\n\n' +INDEX=1 +for dup in "${DUPLICATES[@]}"; do + BODY+="$INDEX. https://github.com/$REPO/issues/$dup"$'\n' + ((INDEX++)) +done + +BODY+=$'\n'"This issue will be automatically closed as a duplicate in 3 days."$'\n\n' +BODY+="- If your issue is a duplicate, please close it and 👍 the existing issue instead"$'\n' +BODY+="- To prevent auto-closure, add a comment or 👎 this comment"$'\n\n' +BODY+="🤖 Generated with [Claude Code](https://claude.ai/code)" + +# Post the comment +gh issue comment "$BASE_ISSUE" --repo "$REPO" --body "$BODY" + +echo "Posted duplicate comment on issue #$BASE_ISSUE"