Commit Update Pr
Commit, push, create or update a pull request, and watch CI until green
---
description: Commit, push, create or update a pull request, and watch CI until green
---
## Your task
Commit all staged/unstaged changes, push to remote, create or update the PR, then watch CI until it finishes and fix any failures.
**Arguments provided:** {{ arguments }}
### Steps to execute
1. **Check git status** to see what changes exist:
```bash
git status
git diff --stat
git diff --staged --stat
Check for existing PR for the current branch:
gh pr view --json number,title,url,state 2>/dev/null- If a PR exists and is OPEN, note its URL and number - we'll update it
- If no PR exists or it's closed/merged, we'll create a new one
Stage all changes (if there are unstaged changes):
git add -ACreate the commit following the commit message conventions:
- Run
git log --oneline -5to see recent commit style - Run
git diff --stagedto understand the changes - Write a concise commit message summarizing the changes
- Use the format:
git commit -m "$(cat <<'EOF' <commit message here> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> EOF )"
- Run
Push to remote:
git push -u origin HEADCreate or update the PR:
If a PR already exists:
- The push already updated the PR
- Note: "Updated existing PR:
"
If no PR exists:
- Create a new PR:
gh pr create --title "<title>" --body "$(cat <<'EOF' ## Summary <1-3 bullet points summarizing the changes> ## Test plan - [ ] <testing checklist items> --- Generated with [Claude Code](https://claude.com/claude-code) EOF )"
Watch CI and auto-fix failures — do NOT stop after pushing. Monitor the PR's checks until every check has a terminal status (pass, fail, skipped, cancelled), and fix any failures before handing back to the user.
a. Poll for status. After pushing, wait ~30s for CI to register, then:
gh pr checks <PR_NUMBER>The first column is the check name, the second is status (
pending,pass,fail,skipping,cancelled). Re-run this periodically. Do not chainsleepcommands to wait — preferrun_in_backgroundso you don't block, and poll by callinggh pr checksagain on a reasonable cadence (30–60s). Keep going until no check showspending.b. If everything passes: report success with the PR URL and stop.
c. If any check fails:
- Identify the failed job URL from the
gh pr checksoutput (third column). - Grab the failure logs with:
Extract thegh run view <RUN_ID> --log-failed 2>&1 | tail -200<RUN_ID>from the job URL (it's the numeric segment after/runs/). - Diagnose the root cause from the log. Distinguish between:
- A real regression introduced by this PR → fix it.
- A pre-existing failure on
mainunrelated to this PR → fix it if the scope is small and self-contained (like flaky test stabilization, SDK symbol guards, or missing imports). Confirm it's pre-existing by runninggit log main -- <failing-file>and checking whether the failing code was introduced before this branch. - A flaky/transient failure (network, timeout, resource availability) → retry by re-running the check with
gh run rerun <RUN_ID> --failed, then resume polling.
- Make the fix, then repeat from step 3 (stage → commit → push → watch). Keep the cycle running until CI is green. Use focused commit messages for each fix ("Fix
") rather than amending.
d. If a failure is outside your ability to fix (credentials, infra, permissions), report the failure clearly with a link and ask the user how to proceed rather than spinning indefinitely.
- Identify the failed job URL from the
Report the final result:
- Show the PR URL and whether it was created or updated
- Show every commit hash + message pushed during this session (the original plus any CI fix commits)
- Confirm CI is green, or explain exactly which checks failed and why if you had to stop early
Maintain Commit Update Pr?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[](https://getagentictools.com/loops/samuelclay-commit-update-pr?ref=badge)