spacehub

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

feat: Add comment-on-duplicates script for safer duplicate handlingBrowse files
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>
Boris Cherny authored on Jan 7, 2026 parent 817e8c1 ยท commit d74241394971
2 changed files+92 -21compared with 817e8c1
M.claude/commands/dedupe.md
Ascripts/comment-on-duplicates.sh
@@ -1,5 +1,5 @@
11 ---
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:*)
33 description: Find duplicate GitHub issues
44 ---
55
@@ -11,28 +11,13 @@
1111 2. Use an agent to view a Github issue, and ask the agent to return a summary of the issue
1212 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
1313 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+ ```
1518
1619 Notes (be sure to tell this to your agents, too):
1720
1821 - 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.)
2023 - 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"