Issue Automation Scripts
Overview
This area owns repository maintenance scripts under scripts/** plus the Windows devcontainer helper under Script/**. Most of the scripts/ files automate GitHub issue triage for anthropics/claude-code using either Bun scripts that call the GitHub REST API directly or shell scripts that wrap the gh CLI.
The lifecycle system is centered on scripts/issue-lifecycle.ts, which defines the labels, timeout windows, close reasons, nudge copy, and STALE_UPVOTE_THRESHOLD. scripts/sweep.ts imports that table for a scheduled-style sweep: it reads GITHUB_REPOSITORY_OWNER, GITHUB_REPOSITORY_NAME, and GITHUB_TOKEN, marks old inactive open issues as stale, then closes issues whose lifecycle labels have aged past their configured timeout. The sweep skips pull requests, locked issues, assigned issues during stale marking, issues with at least 10 +1 reactions, and issues with non-bot comments after the lifecycle label was applied. In non-dry-run mode it posts a closure comment pointing users to the new-issue chooser and patches the issue closed with state_reason: "not_planned"; --dry-run only logs intended label/close actions.
scripts/lifecycle-comment.ts is the companion one-issue comment script for label application workflows. It reads GITHUB_REPOSITORY, LABEL, ISSUE_NUMBER, and GITHUB_TOKEN, looks up the label in scripts/issue-lifecycle.ts, and posts the matching nudge plus the timeout warning to the issue. Unknown labels are ignored, so workflows can call it for multiple label events without hard failing on non-lifecycle labels.
Duplicate detection has three scripts with a comment-format contract. scripts/comment-on-duplicates.sh reads the base issue number from GITHUB_EVENT_PATH (.issue.number or manual .inputs.issue_number), accepts one to three numeric --potential-duplicates, validates that the base and duplicate issues exist in the hard-coded anthropics/claude-code repo, and posts a bot comment containing Found ... possible duplicate issue(s), issue URLs, a 3-day auto-close notice, and instructions to comment or thumbs-down to prevent closure. scripts/auto-close-duplicates.ts scans open issues older than three days, finds bot comments whose bodies contain both Found and possible duplicate, waits until the latest such comment is at least three days old, skips if any later comment exists or if the issue author reacted -1 to the duplicate comment, extracts the first duplicate issue number from either #123 or a GitHub issue URL, and closes the issue with state_reason: 'duplicate' plus a duplicate label and explanatory comment. scripts/backfill-duplicate-comments.ts backfills old issues by scanning issue numbers between MIN_ISSUE_NUMBER and MAX_ISSUE_NUMBER (default 1 to <4050), skipping issues that already have a duplicate-detection bot comment, and dispatching .github/…/claude-dedupe-issues.yml for candidates. It defaults to dry run unless DRY_RUN=false and requires a token with repo/actions permissions.
scripts/edit-issue-labels.sh is a safer issue-label editor for workflows. It binds the issue number to GITHUB_EVENT_PATH instead of trusting a free-form argument, supports repeated --add-label and --remove-label, filters requested labels against gh label list --limit 500, and only calls gh issue edit if at least one requested label exists in the repository. scripts/gh.sh is a restricted GitHub CLI wrapper for read-oriented workflow use: it requires GH_REPO or GITHUB_REPOSITORY in owner/repo form, sets GH_HOST=github.com, permits only issue view, issue list, search issues, and label list, permits only --comments, --state, --limit, and --label, rejects repo:, org:, and user: qualifiers in search queries, and scopes searches with --repo.
Script/run_devcontainer_claude_code.ps1 is separate from issue automation but covered by the assigned Script/** glob. It is a Windows PowerShell helper that validates a -Backend docker|podman argument, checks the selected backend and devcontainer CLI, initializes/starts a Podman machine named claudeVM when requested, runs devcontainer up --workspace-folder . (with --docker-path podman for Podman), locates the running container by the devcontainer.local_folder label for the current directory, then runs claude followed by an interactive zsh shell inside the container.
Coverage / routing
This doc owns:
scripts/**Script/**
Route changes here when they affect GitHub issue duplicate handling, lifecycle labels/comments/closing, issue-label helper scripts, the restricted GitHub CLI wrapper, sweep behavior, or the covered Windows devcontainer script.
Coupling
- If a lifecycle label, timeout, or message changes in scripts/issue-lifecycle.ts, verify both scripts/sweep.ts and scripts/lifecycle-comment.ts: the sweep uses the shared
daysandreasonto close issues, while lifecycle comments use the sharednudgeanddaysto tell users when closure will happen. - If the duplicate-detection comment text changes in scripts/comment-on-duplicates.sh, update the parsers in scripts/auto-close-duplicates.ts and scripts/backfill-duplicate-comments.ts; both detect candidate comments by looking for body substrings
Foundandpossible duplicatefrom a bot user, not by a structured marker. - If the duplicate comment's issue-link format changes in scripts/comment-on-duplicates.sh, verify
extractDuplicateIssueNumberin scripts/auto-close-duplicates.ts; closure depends on extracting the duplicate target from either a#123reference or agithub.com/.../issues/123URL. - If workflows change how issue numbers are passed, verify scripts/comment-on-duplicates.sh and scripts/edit-issue-labels.sh; both intentionally read the issue number from
GITHUB_EVENT_PATH(.issue.numberor.inputs.issue_number) rather than accepting an issue-number argument. - If repository targeting becomes configurable, check for hard-coded
anthropics/claude-codein scripts/comment-on-duplicates.sh and defaults in scripts/auto-close-duplicates.ts and scripts/backfill-duplicate-comments.ts; the lifecycle scripts already use GitHub repository environment variables. - If allowed
ghoperations need to expand, update scripts/gh.sh deliberately: it enforces an allowlist for subcommands, flags, and search qualifiers, while scripts/edit-issue-labels.sh and scripts/comment-on-duplicates.sh callghdirectly for mutating operations. - If the devcontainer label or startup command changes, verify
Script/run_devcontainer_claude_code.ps1; it finds the container bydevcontainer.local_folder=$currentFolderafter runningdevcontainer up, then assumeszshandclaudeexist inside the container.
Risks
- scripts/auto-close-duplicates.ts, scripts/comment-on-duplicates.sh, and scripts/backfill-duplicate-comments.ts share an implicit duplicate-comment format. If a bot comment contains
Foundandpossible duplicatefor another reason, or if the canonical duplicate comment stops using those words, issues may be skipped or closed incorrectly. The path history includes fixes for duplicate extraction and duplicate closure behavior (370a97d,1cc90e9,4a04589), so treat this format as fragile. - scripts/sweep.ts closes lifecycle-labeled issues automatically. If the human-activity guard regresses, issues can close despite user follow-up; this exact bug class appears in history as
1718a57 Fix issues being auto-closed despite human activity (#26360). Preserve the comments-after-label check when changing close logic. - scripts/gh.sh exists to constrain GitHub CLI access after a security fix removed overly broad
gh apipermissions (0b86fdb). If new workflows bypass this wrapper or add broad subcommands/flags to it, re-check whether queries and mutations remain repository-scoped and minimally privileged.