Monitor tool and run_in_background Bash exit 1 spuriously when polling `gh` in a loop

Resolved 💬 1 comment Opened Apr 30, 2026 by juanmiguelbesada Closed May 31, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported
  • [x] This is a single bug

What's Wrong?

When using the Monitor tool or Bash with run_in_background: true to poll gh run view in a loop, the script exits with code 1 even though all individual commands succeed when run interactively.

What Should Happen?

The loop should run until the condition is met and exit 0.

Steps to Reproduce

  1. Ask Claude to monitor a GitHub Actions run using the Monitor tool or run_in_background
  2. Claude generates a poll loop like:
while true; do
  result=$(gh run view 12345678 --json status,conclusion 2>/dev/null)
  status=$(echo "$result" | jq -r .status)
  echo "status=$status"
  [ "$status" = "completed" ] && break
  sleep 30
done
  1. Script exits immediately with exit code 1

Verification that individual commands work fine when run interactively:

  • gh run view 12345678 --json status,conclusion → exit 0
  • echo '...' | jq -r .status → exit 0

Error Messages / Logs

Monitor "..." script failed (exit 1)
Background command "..." failed with exit code 1

Workaround

Wrapping in explicit bash -c '...' resolves the issue:

bash -c '
while true; do
  out=$(gh run view 12345678 --json status,conclusion 2>/dev/null)
  status=$(echo "$out" | jq -r .status 2>/dev/null)
  echo "status=$status"
  if [ "$status" = "completed" ]; then break; fi
  sleep 30
done
'

Suspected Causes

  1. Shell env difference between interactive session and Monitor/background task subprocess
  2. Emoji in job name (e.g. 📦 Build) from gh run view --json jobs output causing multibyte character parsing issues in the subprocess env

Environment

  • Claude model: Claude Sonnet 4.6
  • Claude Code version: latest
  • API platform: Anthropic API
  • OS: macOS
  • Shell: zsh

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗