surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic ยท github.com/anthropics
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 <noreply@anthropic.com>
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | --- |
| 2 | -allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(gh issue comment:*) | |
| 2 | +allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(./scripts/comment-on-duplicates.sh:*) | |
| 3 | 3 | description: Find duplicate GitHub issues |
| 4 | 4 | --- |
| 5 | 5 | |
| @@ -11,28 +11,13 @@ | ||
| 11 | 11 | 2. Use an agent to view a Github issue, and ask the agent to return a summary of the issue |
| 12 | 12 | 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 |
| 13 | 13 | 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. |
| 14 | -5. Finally, comment back on the issue with a list of up to three duplicate issues (or zero, if there are no likely duplicates) | |
| 14 | +5. Finally, use the comment script to post duplicates: | |
| 15 | + ``` | |
| 16 | + ./scripts/comment-on-duplicates.sh --base-issue <issue-number> --potential-duplicates <dup1> <dup2> <dup3> | |
| 17 | + ``` | |
| 15 | 18 | |
| 16 | 19 | Notes (be sure to tell this to your agents, too): |
| 17 | 20 | |
| 18 | 21 | - Use `gh` to interact with Github, rather than web fetch |
| 19 | -- Do not use other tools, beyond `gh` (eg. don't use other MCP servers, file edit, etc.) | |
| 22 | +- Do not use other tools, beyond `gh` and the comment script (eg. don't use other MCP servers, file edit, etc.) | |
| 20 | 23 | - Make a todo list first |
| 21 | -- For your comment, follow the following format precisely (assuming for this example that you found 3 suspected duplicates): | |
| 22 | - | |
| 23 | ---- | |
| 24 | - | |
| 25 | -Found 3 possible duplicate issues: | |
| 26 | - | |
| 27 | -1. <link to issue> | |
| 28 | -2. <link to issue> | |
| 29 | -3. <link to issue> | |
| 30 | - | |
| 31 | -This issue will be automatically closed as a duplicate in 3 days. | |
| 32 | - | |
| 33 | -- If your issue is a duplicate, please close it and ๐ the existing issue instead | |
| 34 | -- To prevent auto-closure, add a comment or ๐ this comment | |
| 35 | - | |
| 36 | -๐ค Generated with [Claude Code](https://claude.ai/code) | |
| 37 | - | |
| 38 | ---- |
| @@ -1,0 +1,86 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +# | |
| 3 | +# Comments on a GitHub issue with a list of potential duplicates. | |
| 4 | +# Usage: ./comment-on-duplicates.sh --base-issue 123 --potential-duplicates 456 789 101 | |
| 5 | +# | |
| 6 | + | |
| 7 | +set -euo pipefail | |
| 8 | + | |
| 9 | +REPO="anthropics/claude-code" | |
| 10 | +BASE_ISSUE="" | |
| 11 | +DUPLICATES=() | |
| 12 | + | |
| 13 | +# Parse arguments | |
| 14 | +while [[ $# -gt 0 ]]; do | |
| 15 | + case $1 in | |
| 16 | + --base-issue) | |
| 17 | + BASE_ISSUE="$2" | |
| 18 | + shift 2 | |
| 19 | + ;; | |
| 20 | + --potential-duplicates) | |
| 21 | + shift | |
| 22 | + while [[ $# -gt 0 && ! "$1" =~ ^-- ]]; do | |
| 23 | + DUPLICATES+=("$1") | |
| 24 | + shift | |
| 25 | + done | |
| 26 | + ;; | |
| 27 | + *) | |
| 28 | + echo "Unknown option: $1" >&2 | |
| 29 | + exit 1 | |
| 30 | + ;; | |
| 31 | + esac | |
| 32 | +done | |
| 33 | + | |
| 34 | +# Validate base issue | |
| 35 | +if [[ -z "$BASE_ISSUE" ]]; then | |
| 36 | + echo "Error: --base-issue is required" >&2 | |
| 37 | + exit 1 | |
| 38 | +fi | |
| 39 | + | |
| 40 | +if ! [[ "$BASE_ISSUE" =~ ^[0-9]+$ ]]; then | |
| 41 | + echo "Error: --base-issue must be a number, got: $BASE_ISSUE" >&2 | |
| 42 | + exit 1 | |
| 43 | +fi | |
| 44 | + | |
| 45 | +# Validate duplicates | |
| 46 | +if [[ ${#DUPLICATES[@]} -eq 0 ]]; then | |
| 47 | + echo "Error: --potential-duplicates requires at least one issue number" >&2 | |
| 48 | + exit 1 | |
| 49 | +fi | |
| 50 | + | |
| 51 | +if [[ ${#DUPLICATES[@]} -gt 3 ]]; then | |
| 52 | + echo "Error: --potential-duplicates accepts at most 3 issues" >&2 | |
| 53 | + exit 1 | |
| 54 | +fi | |
| 55 | + | |
| 56 | +for dup in "${DUPLICATES[@]}"; do | |
| 57 | + if ! [[ "$dup" =~ ^[0-9]+$ ]]; then | |
| 58 | + echo "Error: duplicate issue must be a number, got: $dup" >&2 | |
| 59 | + exit 1 | |
| 60 | + fi | |
| 61 | +done | |
| 62 | + | |
| 63 | +# Build comment body | |
| 64 | +COUNT=${#DUPLICATES[@]} | |
| 65 | +if [[ $COUNT -eq 1 ]]; then | |
| 66 | + HEADER="Found 1 possible duplicate issue:" | |
| 67 | +else | |
| 68 | + HEADER="Found $COUNT possible duplicate issues:" | |
| 69 | +fi | |
| 70 | + | |
| 71 | +BODY="$HEADER"$'\n\n' | |
| 72 | +INDEX=1 | |
| 73 | +for dup in "${DUPLICATES[@]}"; do | |
| 74 | + BODY+="$INDEX. https://github.com/$REPO/issues/$dup"$'\n' | |
| 75 | + ((INDEX++)) | |
| 76 | +done | |
| 77 | + | |
| 78 | +BODY+=$'\n'"This issue will be automatically closed as a duplicate in 3 days."$'\n\n' | |
| 79 | +BODY+="- If your issue is a duplicate, please close it and ๐ the existing issue instead"$'\n' | |
| 80 | +BODY+="- To prevent auto-closure, add a comment or ๐ this comment"$'\n\n' | |
| 81 | +BODY+="๐ค Generated with [Claude Code](https://claude.ai/code)" | |
| 82 | + | |
| 83 | +# Post the comment | |
| 84 | +gh issue comment "$BASE_ISSUE" --repo "$REPO" --body "$BODY" | |
| 85 | + | |
| 86 | +echo "Posted duplicate comment on issue #$BASE_ISSUE" |