auto-close-duplicates wipes an issue's existing labels when closing it as a duplicate
closeIssueAsDuplicate in scripts/auto-close-duplicates.ts closes the issue with a PATCH /repos/{owner}/{repo}/issues/{number} that includes labels: ['duplicate']:
https://github.com/anthropics/claude-code/blob/dec92bc87ab6fe9c7be0fcba1f97966f902dd243/scripts/auto-close-duplicates.ts#L73-L82
On that endpoint the labels parameter will "replace the set of labels on this issue" (Update an issue), so every issue closed by the auto-close job loses its existing area/platform/triage labels and keeps only duplicate.
Suggested fix: keep the PATCH for state: 'closed' / state_reason: 'duplicate', and add the label with POST /repos/{owner}/{repo}/issues/{number}/labels ({ labels: ['duplicate'] }), which adds rather than replaces (Add labels to an issue). The workflow already grants issues: write.
A ready commit with this change (+8/−2): https://github.com/gypsy5oul/claude-code/commit/7b12a6f
I tried to open it as a PR, but PR creation is restricted on this repository, so I'm filing it here instead.
I put together a fix for this, but PR creation is restricted to collaborators here so I couldn't open one.
- Branch: https://github.com/aarochu/claude-code/tree/fix/auto-close-keep-labels
- Commit: https://github.com/aarochu/claude-code/commit/81abbc60917980bdfa12546e06fecf8709462aa8
It drops labels from the close PATCH and adds duplicate with POST /issues/{n}/labels afterwards, the same way scripts/sweep.ts already adds stale.
I checked it by running the actual script under bun against a stubbed GitHub API that follows the real label semantics (PATCH replaces, POST appends). An issue labelled bug, area:tui, platform:macos came out as just ["duplicate"] on main, and as ["bug", "area:tui", "platform:macos", "duplicate"] with the fix. The closing comment still gets posted, and tsc --noEmit passes.
To pick it up:
git fetch https://github.com/aarochu/claude-code.git fix/auto-close-keep-labels
git cherry-pick 81abbc6
The consolidated, tested fix for this is ready: 7151c1c on shuhuNB515/claude-code (raw patch).
What it changes for this issue specifically:
closeIssueAsDuplicate()no longer sendsPATCH /issues/{n}withlabels: ['duplicate'](which replaces the whole label set per the REST docs). It PATCHes onlystate/state_reason, then adds theduplicatelabel additively viaPOST /issues/{n}/labels.- Decision logic was extracted into pure functions (
shouldAutoClose,extractDuplicateIssueNumber,isDedupeComment) with 11 regression tests inscripts/auto-close-duplicates.test.ts.
The same commit also fixes #80506 (full pagination for comments/reactions) and #79146 (thumbs-down honored from any user), since all three touch the same close-duplicate code path.
Sharing as a patch link rather than a PR, since this repo hasn't had a fork PR created since August and PR creation is blocked for outside accounts. Happy to open a PR if that channel reopens.
Test run:
$ bun test scripts/auto-close-duplicates.test.ts
11 pass, 0 fail
A minimal fix for this is on serhiileniv/claude-code:fix/auto-close-preserve-labels (commit 7963eef, ~15 lines). It's shared as a branch because fork PR creation is currently blocked for outside accounts.
- Adds
duplicateviaPOST /issues/{n}/labels(additive), then PATCHes onlystate/state_reason. Labeling comes first on purpose: if the close fails, the issue stays open and the next run retries. Closing first could leave a closed issue with noduplicatelabel that is never revisited. - Skips pull requests in the
/issueslisting; they're never candidates and each cost a comments request.
Checked against a mock GitHub API: an issue labeled [bug, area:tui] ends with [duplicate] on main and [bug, area:tui, duplicate] on the branch.
This is independent of #80508 (pagination, #80506) and doesn't include the #79146 policy change, so each can be merged on its own.