[BUG] scripts/edit-issue-labels.sh crashes with unbound variable under Bash < 4.4 and exits silently on empty arguments

Status Open
Maintainer reply None cached
Activity 2 comments · opened Oct 11, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

What's Wrong?

scripts/edit-issue-labels.sh runs with set -euo pipefail.

  1. Unbound variable crash on Bash < 4.4:

Under Bash < 4.4 (including macOS stock /bin/bash 3.2), expanding an empty array with "${arr[@]}" under set -u raises arr[@]: unbound variable and exits with code 1.
In scripts/edit-issue-labels.sh, this happens whenever the script is executed with only --add-label or only --remove-label:

  • When called with only --add-label (the exact invocation recommended in .claude/commands/triage-issue.md line 54: ./scripts/edit-issue-labels.sh --add-label "label1" --add-label "label2"), REMOVE_LABELS is empty, and line 56 crashes with:

REMOVE_LABELS[@]: unbound variable

  • When called with only --remove-label (the invocation recommended in .claude/commands/triage-issue.md lines 60 & 62: ./scripts/edit-issue-labels.sh --remove-label "stale"), ADD_LABELS is empty, and line 49 crashes with:

ADD_LABELS[@]: unbound variable

  • Similarly, FILTERED_ADD and FILTERED_REMOVE crash at lines 69 and 73 when only adding or only removing labels.
  1. Silent exit on empty arguments:

When invoked with no arguments (lines 40-42):

if [[ ${#ADD_LABELS[@]} -eq 0 && ${#REMOVE_LABELS[@]} -eq 0 ]]; then
  exit 1
fi

The script terminates with exit code 1 without printing any message to stdout or stderr.

  1. Unchecked parameter bounds:

In the argument parsing loop, if --add-label or --remove-label is missing a trailing argument, shift 2 fails out of bounds.

What Should Happen?

  1. Empty array expansions should be guarded with ${arr[@]+"${arr[@]}"} so the script works reliably on macOS stock Bash 3.2 as well as Bash 4/5.
  2. Invoking the script without arguments should print a helpful error message to stderr (Error: at least one --add-label or --remove-label argument is required) before exiting 1.
  3. Missing argument parameters should be checked before shifting.

Steps to Reproduce

Run under macOS /bin/bash (3.2.57):

export GITHUB_EVENT_PATH=$(mktemp)
echo '{"issue": {"number": 123}}' > "$GITHUB_EVENT_PATH"

# Repro 1: Only add-label (crashes at line 56/60)
/bin/bash scripts/edit-issue-labels.sh --add-label bug
# Output: scripts/edit-issue-labels.sh: line 60: REMOVE_LABELS[@]: unbound variable

# Repro 2: Only remove-label (crashes at line 49/53)
/bin/bash scripts/edit-issue-labels.sh --remove-label stale
# Output: scripts/edit-issue-labels.sh: line 53: ADD_LABELS[@]: unbound variable

# Repro 3: No arguments (silent exit 1)
/bin/bash scripts/edit-issue-labels.sh; echo "Exit: $?"
# Output: Exit: 1 (no stderr)

Fix Available

A tested fix is available on my fork:

Maintainers can cherry-pick with:

git fetch https://github.com/Saauf/claude-code.git fix/edit-issue-labels-empty-arrays
git cherry-pick 3a4005abc438f744327ef7dd39b386001ecc678a

Verification completed:

  • Verified all 7 test cases under stock macOS /bin/bash (3.2.57) and Bash 5.
  • bash -n scripts/edit-issue-labels.sh passed cleanly.
  • git diff --check passed cleanly.

Platform

Anthropic API

Operating System

macOS / All

Terminal/Shell

Terminal.app (macOS)

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗