Autonomous CI fix loop with background monitoring and retry logic. Runs up to 10 fix-commit-push-wait cycles until CI passes or max retries reached.
/plugin marketplace add iamladi/cautious-computing-machine--github-plugin/plugin install github@cautious-computing-machineThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Orchestrates autonomous CI repair: analyze → fix → commit → push → monitor → repeat until success.
This skill is invoked when:
/fix-ci --loop or /fix-ci --auto| Setting | Value | Description |
|---|---|---|
| max_attempts | 10 | Maximum fix iterations |
| poll_interval | 60 | Seconds between CI status checks |
| ci_start_timeout | 120 | Seconds to wait for CI run to start |
| ci_run_timeout | 1800 | Max seconds to wait for CI completion (30 min) |
Get context and validate:
BRANCH=$(git branch --show-current)
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null || echo "unknown")
Safety checks:
if [[ "$BRANCH" == "main" || "$BRANCH" == "master" ]]; then
echo "Cannot run autonomous fixes on $BRANCH"
echo "Create a feature branch: git checkout -b fix/ci-errors"
# STOP - do not proceed
fi
if [[ -n $(git status --porcelain) ]]; then
echo "Stashing uncommitted changes..."
git stash push -m "pre-ci-fix-loop-$(date +%Y%m%d_%H%M%S)"
fi
Initialize state:
attempt = 1
max_attempts = 10
last_errors = []
history = []
started_at = now
For each attempt from 1 to 10:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CI Fix Loop - Attempt ${attempt}/${max_attempts}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Branch: ${branch}
Repository: ${repo}
Get most recent failed run:
RUN_ID=$(gh run list --branch "$BRANCH" --limit 5 --json databaseId,conclusion \
--jq '[.[] | select(.conclusion == "failure")][0].databaseId')
if [ -z "$RUN_ID" ]; then
echo "No failed runs found - checking if CI is passing..."
# May already be fixed, verify
fi
Fetch logs for failed jobs:
FAILED_JOBS=$(gh run view $RUN_ID --json jobs --jq '.jobs[] | select(.conclusion == "failure") | .databaseId')
for JOB_ID in $FAILED_JOBS; do
gh api repos/${REPO}/actions/jobs/${JOB_ID}/logs > /tmp/ci-logs-${JOB_ID}.txt 2>/dev/null || true
done
Invoke the ci-log-analyzer agent:
Compare current errors with previous attempt:
if current_errors == last_errors AND attempt > 1:
# Same errors after fix attempt = likely unfixable
consecutive_same_errors += 1
if consecutive_same_errors >= 2:
echo "Same errors detected after 2 fix attempts - aborting"
echo "These errors may require manual intervention"
# STOP - exit loop with failure report
fi
if current_errors is empty:
# No errors found - CI might be passing
# Skip to monitoring phase
Invoke the ci-error-fixer agent with error list:
Track results:
errors_fixed = count of successfully fixed errors
errors_flagged = count of errors needing manual review
Stage and commit changes:
git add .
# Create descriptive commit message
git commit -m "fix(ci): automated fix attempt ${attempt}
Errors addressed:
- ${error_summary_list}
Attempt ${attempt} of ${max_attempts} (ci-fix-loop)"
Push to trigger CI:
PUSH_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
git push origin ${BRANCH}
Poll until new run appears (max 2 minutes):
TIMEOUT=120
START=$(date +%s)
while true; do
RUN_JSON=$(gh run list --branch "$BRANCH" --limit 1 --json databaseId,status,createdAt)
CREATED=$(echo "$RUN_JSON" | jq -r '.[0].createdAt')
# Check if this run was created after our push
if [[ "$CREATED" > "$PUSH_TIME" ]]; then
NEW_RUN_ID=$(echo "$RUN_JSON" | jq -r '.[0].databaseId')
echo "CI run started: $NEW_RUN_ID"
break
fi
ELAPSED=$(($(date +%s) - START))
if [ $ELAPSED -gt $TIMEOUT ]; then
echo "Warning: No CI run started after ${TIMEOUT}s"
echo "Check if workflows are enabled for this branch"
break
fi
sleep 5
done
Spawn the ci-monitor agent with run_in_background: true:
The monitor will:
gh run list every 60 secondsSUCCESS|RUN_ID, FAILURE|RUN_ID, CANCELLED|RUN_ID, or TIMEOUT|RUN_IDWait for monitor result using TaskOutput tool.
Parse monitor output:
case "$RESULT" in
SUCCESS*)
# CI passed! Exit loop with success
;;
FAILURE*)
# CI still failing - continue to next attempt
;;
CANCELLED*)
# Run was cancelled - warn and exit
echo "CI run was cancelled externally"
# EXIT with warning
;;
TIMEOUT*)
# Exceeded 30 min wait
echo "CI run timed out after 30 minutes"
# Ask if should continue waiting or abort
;;
esac
history.append({
attempt: attempt,
errors_found: len(current_errors),
errors_fixed: errors_fixed,
errors_flagged: errors_flagged,
run_id: run_id,
result: conclusion,
duration: attempt_duration
})
last_errors = current_errors
attempt += 1
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CI Fix Loop Complete
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Result: [SUCCESS|FAILURE] after ${attempts} attempt(s)
Summary:
Total time: ${total_duration}
Commits created: ${commit_count}
Errors fixed: ${total_errors_fixed}
History:
For each entry in history:
Attempt ${n}: Found ${errors_found} errors, fixed ${fixed} → ${result}
If FAILURE:
Remaining Issues (require manual intervention):
- ${file}:${line} - ${message}
Type: ${type}
Suggested next steps:
1. Review errors above
2. Check CI logs: gh run view ${last_run_id} --log-failed
3. Fix manually and push
If SUCCESS:
CI is now passing!
Next steps:
1. Review automated commits: git log --oneline -${commit_count}
2. Squash if desired: git rebase -i HEAD~${commit_count}
3. Create PR: /github:create-pr
gh commands 3 times with 5s backoffecho "Upstream changes detected"
echo "Pull and retry: git pull --rebase && /fix-ci --loop"
gh run watchEstimated per iteration:
Key optimizations:
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.