Update PR
Important
- NEVER push to main. Never checkout main. Never modify main. Only push the current feature branch. If on main, stop immediately.
- NEVER force push. If a push is rejected after rebase, tell the user to run the force push manually outside Claude Code (supply-chain-guard blocks it).
- Auto-commit is the default. If there are uncommitted changes, commit them automatically. Do not ask, do not stop.
- Commits use
Co-Authored-By — PR descriptions do NOT.
Instructions
Step 1: Validate Branch
- Run
git branch --show-current.
- If the branch is
main or master, STOP. Tell the user: "You're on main. Check out a feature branch first."
Step 2: Refresh Project Docs
- Run
git diff origin/main...HEAD --name-only and git diff --name-only to understand all changes in this branch + uncommitted work.
- Check which of these files exist at the project root:
CLAUDE.md, TASKS.md, SESSION.md, ARCHITECTURE.md.
- For each file that exists, read it and update based on what changed:
- CLAUDE.md: Add new patterns, dependencies, or workflow notes introduced this branch. Remove stale instructions that no longer apply.
- TASKS.md: Mark completed tasks as done. Add any new tasks discovered during the session.
- SESSION.md: Overwrite with a concise summary of what was done this session (what changed, decisions made, blockers hit).
- ARCHITECTURE.md: Update only if structural changes were made (new modules, changed data flow, new integrations).
- Skip any file where nothing meaningful changed. Don't touch files that don't exist — never create them.
Step 3: Auto-Commit
- Run
git status --short.
- If the working tree is clean (no output), skip to Step 4 (Rebase).
- If there are changes:
a. Review the list of changed/untracked files. Skip any that look like secrets (
.env, *.pem, credentials, tokens).
b. Stage relevant files by name — do NOT use git add -A or git add ..
c. Read the staged diff to understand what changed.
d. Generate a concise commit message (imperative mood, focused on why not what).
e. Commit with the Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> trailer.
f. Report: "Committed: ( files)"
Step 4: Rebase on Main
- Run
git fetch origin main.
- Run
git rebase origin/main.
- If conflicts occur, STOP. List conflicting files. Tell the user to resolve (
git rebase --continue or git rebase --abort).
Step 5: Push to Remote
- Run
git push -u origin <branch-name>.
- If rejected (non-fast-forward — typical after rebasing a previously-pushed branch):
- Do NOT attempt force push.
- Tell the user: "Push rejected — rebase rewrote history. Run this manually:
git push --force-with-lease origin <branch>"
- STOP.
Step 6: Gather Context
Run these in parallel:
git log origin/main..HEAD --format="%h %s" --reverse — commit list since branching.
git diff origin/main...HEAD --stat — file-level diffstat.
git log origin/main..HEAD --format="%b" --reverse — commit bodies for detail.
gh pr view --json number,title,url,state 2>/dev/null — check for existing open PR.
Analyze the commits to understand the overall change.
Step 7a: Update Existing PR
If gh pr view found an open PR:
- Generate an updated title (under 70 characters) reflecting ALL commits, not just the latest.
- Generate a PR body using the format below. Incorporate the argument context if provided.
- Run
gh pr edit <number> --title "<title>" --body "$(cat <<'EOF' ... EOF)".
- Report: "PR #N updated: "
Step 7b: Create New PR
If no open PR exists for this branch:
- Generate a title (under 70 characters) from the full commit history.
- Generate a body using the format below. Incorporate the argument context if provided.
- Run
gh pr create --base main --title "<title>" --body "$(cat <<'EOF' ... EOF)".
- Report: "PR created: "
PR Description Format
## What & Why
<1-3 sentences: what changed and why it matters. Lead with impact, not implementation.>
## Changes
- <structural change 1 — what component/layer was affected>
- <structural change 2>
## Blast Radius
- <what systems/workflows this touches>
- <downstream effects or dependencies affected>
## Test Plan
- [ ] <concrete verification step>
Rules for the PR body
- What & Why: One breath. No "This PR..." openers.
- Changes: Structural, not per-commit. Group related commits logically.
- Blast Radius: Think like an operator. What could break?
- Test Plan: Actionable. Not "it works."
- No "Generated by Claude" or "Co-Authored-By" lines in PR descriptions.
Error Handling
- On main/master: Stop. Tell user to create a feature branch.
- Rebase conflicts: Stop. List files. Provide resolve/abort commands.
- Push rejected: Stop. Provide manual force-push command.
- gh not authenticated: Tell user to run
gh auth login.
- No commits ahead of main: Tell user branch is up to date with main, nothing to PR.
- PR already merged/closed: Tell user. Offer to create a new PR if there are new commits.
1---2name: update-pr3description: Auto-commit dirty working tree, push feature branch, and create or update the GitHub PR with an auto-generated description. One command to go from uncommitted changes to an up-to-date PR. Use when user says 'update my PR', 'update the PR', 'push and update PR', 'refresh PR', 'sync my PR', 'create a PR', 'open a PR', 'push my changes', 'get my PR up to date', 'rebase and push', 'push to the PR', 'PR update', or 'ship it'. Do NOT use for reviewing PRs, reading PR comments, or merging PRs.4---56# Update PR78## Important910- **NEVER push to main.** Never checkout main. Never modify main. Only push the current feature branch. If on main, stop immediately.11- **NEVER force push.** If a push is rejected after rebase, tell the user to run the force push manually outside Claude Code (supply-chain-guard blocks it).12- **Auto-commit is the default.** If there are uncommitted changes, commit them automatically. Do not ask, do not stop.13- Commits use `Co-Authored-By` — PR descriptions do NOT.1415## Instructions1617### Step 1: Validate Branch18191. Run `git branch --show-current`.202. If the branch is `main` or `master`, STOP. Tell the user: "You're on main. Check out a feature branch first."2122### Step 2: Refresh Project Docs23241. Run `git diff origin/main...HEAD --name-only` and `git diff --name-only` to understand all changes in this branch + uncommitted work.252. Check which of these files exist at the project root: `CLAUDE.md`, `TASKS.md`, `SESSION.md`, `ARCHITECTURE.md`.263. For each file that exists, read it and update based on what changed:27 - **CLAUDE.md**: Add new patterns, dependencies, or workflow notes introduced this branch. Remove stale instructions that no longer apply.28 - **TASKS.md**: Mark completed tasks as done. Add any new tasks discovered during the session.29 - **SESSION.md**: Overwrite with a concise summary of what was done this session (what changed, decisions made, blockers hit).30 - **ARCHITECTURE.md**: Update only if structural changes were made (new modules, changed data flow, new integrations).314. Skip any file where nothing meaningful changed. Don't touch files that don't exist — never create them.3233### Step 3: Auto-Commit34351. Run `git status --short`.362. If the working tree is clean (no output), skip to Step 4 (Rebase).373. If there are changes:38 a. Review the list of changed/untracked files. Skip any that look like secrets (`.env`, `*.pem`, credentials, tokens).39 b. Stage relevant files by name — do NOT use `git add -A` or `git add .`.40 c. Read the staged diff to understand what changed.41 d. Generate a concise commit message (imperative mood, focused on why not what).42 e. Commit with the `Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>` trailer.43 f. Report: "Committed: <message> (<N> files)"4445### Step 4: Rebase on Main46471. Run `git fetch origin main`.482. Run `git rebase origin/main`.493. If conflicts occur, STOP. List conflicting files. Tell the user to resolve (`git rebase --continue` or `git rebase --abort`).5051### Step 5: Push to Remote52531. Run `git push -u origin <branch-name>`.542. If rejected (non-fast-forward — typical after rebasing a previously-pushed branch):55 - Do NOT attempt force push.56 - Tell the user: "Push rejected — rebase rewrote history. Run this manually: `git push --force-with-lease origin <branch>`"57 - STOP.5859### Step 6: Gather Context6061Run these in parallel:62631. `git log origin/main..HEAD --format="%h %s" --reverse` — commit list since branching.642. `git diff origin/main...HEAD --stat` — file-level diffstat.653. `git log origin/main..HEAD --format="%b" --reverse` — commit bodies for detail.664. `gh pr view --json number,title,url,state 2>/dev/null` — check for existing open PR.6768Analyze the commits to understand the overall change.6970### Step 7a: Update Existing PR7172If `gh pr view` found an open PR:73741. Generate an updated title (under 70 characters) reflecting ALL commits, not just the latest.752. Generate a PR body using the format below. Incorporate the argument context if provided.763. Run `gh pr edit <number> --title "<title>" --body "$(cat <<'EOF' ... EOF)"`.774. Report: "PR #N updated: <url>"7879### Step 7b: Create New PR8081If no open PR exists for this branch:82831. Generate a title (under 70 characters) from the full commit history.842. Generate a body using the format below. Incorporate the argument context if provided.853. Run `gh pr create --base main --title "<title>" --body "$(cat <<'EOF' ... EOF)"`.864. Report: "PR created: <url>"8788## PR Description Format8990```markdown91## What & Why9293<1-3 sentences: what changed and why it matters. Lead with impact, not implementation.>9495## Changes9697- <structural change 1 — what component/layer was affected>98- <structural change 2>99100## Blast Radius101102- <what systems/workflows this touches>103- <downstream effects or dependencies affected>104105## Test Plan106107- [ ] <concrete verification step>108```109110### Rules for the PR body111112- **What & Why**: One breath. No "This PR..." openers.113- **Changes**: Structural, not per-commit. Group related commits logically.114- **Blast Radius**: Think like an operator. What could break?115- **Test Plan**: Actionable. Not "it works."116- No "Generated by Claude" or "Co-Authored-By" lines in PR descriptions.117118## Error Handling1191201. **On main/master**: Stop. Tell user to create a feature branch.1212. **Rebase conflicts**: Stop. List files. Provide resolve/abort commands.1223. **Push rejected**: Stop. Provide manual force-push command.1234. **gh not authenticated**: Tell user to run `gh auth login`.1245. **No commits ahead of main**: Tell user branch is up to date with main, nothing to PR.1256. **PR already merged/closed**: Tell user. Offer to create a new PR if there are new commits.