JSisques/branch-pr-preparer

Trigger: prepare branch and PR, open PR, abre un PR, prepara la rama. Prepare a feature branch and an approval-gated GitHub PR following branch-pr.

O que é branch-pr-preparer?

branch-pr-preparer is a Claude Code agent skill that trigger: prepare branch and PR, open PR, abre un PR, prepara la rama. Prepare a feature branch and an approval-gated GitHub PR following branch-pr.

Funciona com✓Claude Code✓Codex CLI~Cursor✓Gemini CLI✓OpenCode
npx skills add https://github.com/JSisques/skills/tree/HEAD/skills/branch-pr-preparer

Installed? Explore more Programação e Desenvolvimento skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Perguntar na sua IA favorita

Abre um novo chat com esta habilidade de agente já pré-carregada.

Documentação

Branch & PR Preparer

Description

This skill prepares a feature branch and opens a GitHub pull request by following the branch-pr skill. It writes a Conventional Commits title and a body with What, Why, and How tested sections, links the related issue, and adds no AI attribution anywhere. When the change is over 400 authored lines, it hands off to the chained-pr skill. It is approval-gated: it always shows a full draft first, and it runs git push or gh pr create only after the user explicitly approves that exact draft.

The skill exists so PRs are small, consistent, traceable to an issue, and never published without the human's decision.

Trigger

Activate this skill only when the user explicitly asks to prepare, open, create, or draft a pull request, or to prepare a branch for one. Examples:

  • "open a PR", "create a pull request", "prepare a PR for this", "draft the PR"
  • "push this branch and open a PR", "get this ready for review on GitHub"
  • "abre un PR", "prepara la rama y el PR"
  • /branch-pr or a direct reference to this skill by name

Do NOT activate for:

  • Reviewing an existing PR ("review PR #42"). Use a review skill instead.
  • Committing only ("commit this"), with no request for a branch or PR.
  • Questions about PRs ("how do PRs work?", "what's our PR convention?").
  • Writing review comments on someone else's PR.
  • Work that has no git repository or no GitHub remote. Report the blocker instead of activating.

Writing style

Load the natural-writing skill before drafting any text (if it is missing, install it with npx @jsisques/skills add natural-writing --agent <agent>, where <agent> is opencode, claude, codex, agents, or all). Without it, apply at least:

  • No invented facts; one concrete fact beats any adjective.
  • No em dashes (—) or en dashes (–).
  • No AI vocabulary: potenciar, impulsar, clave, crucial, apasionado, proactivo; delve, leverage, robust, seamless, showcase.
  • No formula rhythms: forced triplets, "no es X, es Y", staccato fragments, "¿El resultado?", trailing gerund analysis, generic closers.
  • Sentence-case Spanish headings, no emoji bullets, no chat residue ("Aquí tienes", "Espero que te sirva").

Instructions

Follow these steps in order. Do not skip a step, and do not reorder the approval gate.

1. Load the required skills

  1. Resolve branch-pr by registry name. Read .atl/skill-registry.md if it exists, otherwise search the configured skill roots (./skills, .agents/skills, ~/.claude/skills, ~/.config/opencode/skills, ~/.gemini/skills). Read its SKILL.md before acting. Its conventions override the generic defaults in this file wherever they conflict.
  2. Resolve chained-pr and work-unit-commits the same way. Load them only if step 4 or step 5 needs them.
  3. If branch-pr is not installed, say so in one line and continue with the defaults in this file.

2. Recover context (Engram)

  1. Call mem_current_project to resolve the project. If the result is ambiguous or doesn't match the workspace, follow the Engram session-start protocol and skip project-scoped reads until it's resolved.
  2. Call mem_search with the branch name, issue number, or feature keywords to find prior decisions: chain strategy, slice boundaries, PR conventions, and earlier drafts.
  3. Treat any memory marked needs_review as stale. Verify it against the current repo before you rely on it.

3. Inspect repository state (read-only)

Run these and keep the output bounded:

git rev-parse --show-toplevel
git status --short
git branch --show-current
git remote -v
git symbolic-ref refs/remotes/origin/HEAD   # default branch
git log --oneline <default>..HEAD
git diff --stat <default>...HEAD
gh auth status

Collect: the default branch, the current branch, uncommitted changes, commits ahead of the default branch, authored changed lines, and gh authentication status.

Handle these blockers before going further:

  • No GitHub remote or gh is not authenticated: stop and report the exact blocker. Do not try to authenticate on the user's behalf.
  • Uncommitted changes: ask one question: include them (commit them as a work unit), or leave them out. Then stop and wait.
  • No commits ahead of the default branch and a clean tree: report that there is nothing to open a PR for, and stop.

4. Prepare the feature branch

  1. If the current branch is the default branch, propose a branch name using the branch-pr convention. The default format is <type>/<issue>-<short-kebab-summary>, for example feat/123-export-csv. Create it locally with git switch -c <name>. Creating a local branch is allowed. Pushing it is not.
  2. If already on a feature branch, keep it. Do not rename it unless the user asks.
  3. Check that the commits follow Conventional Commits. If any don't, list them in the draft. Rewrite history only with explicit user approval.

5. Measure size and route

  1. Count authored changed lines (additions plus deletions) against the default branch. Exclude generated files: lockfiles, snapshots, build output, vendored code.
  2. 400 lines or fewer: continue to step 6 with a single PR.
  3. Over 400 lines: load chained-pr and hand the work off to it. Pass along the branch, the base, the line count, the commit list, and the linked issue. chained-pr owns slicing and chain strategy. This skill still applies its title, body, attribution, and approval rules to every PR in the chain.
  4. Never split, squash, or reorder commits without explicit approval.

6. Link the issue

  1. Look for an issue number in, in order: the user request, the branch name, the commit messages, and Engram memory.
  2. If none is found, ask one question: "Which issue does this PR resolve? (number, or 'none')". Then stop and wait.
  3. Use Closes #N when the PR fully resolves the issue, and Refs #N when it only partially addresses it.
  4. If the user answers "none", write No linked issue in the body and note it in the draft.

7. Build the draft

The title is a Conventional Commits header:

<type>(<optional-scope>): <imperative summary, lowercase, no trailing period>
  • Allowed types: feat, fix, refactor, perf, test, docs, build, ci, chore, revert.
  • Add ! after the type or scope, plus a BREAKING CHANGE: note in the body, only for real breaking changes.
  • Keep the title under 72 characters.

The body uses this exact structure:

## What
<1-5 bullets describing the concrete changes>

## Why
<motivation: the problem, user need, or bug root cause>

## How tested
<commands actually run and their observed results; manual steps if any>

## Linked issue
Closes #<N>
  • "How tested" lists only checks that were actually run, with their observed results. If nothing was run, write Not tested: <reason>. Never invent results.
  • Write all PR artifacts in English unless the user or the repo convention says otherwise.

8. Present the draft and stop

Show the user, in one message:

  • the branch name and its base
  • the authored line count and the route (single PR, or chained via chained-pr)
  • the commits included
  • the full title and body, exactly as they will be submitted
  • the exact commands that will run, for example:
    git push -u origin feat/123-export-csv
    gh pr create --base main --head feat/123-export-csv --title "..." --body-file <tmp-file>
    

Then ask one question: "Approve pushing and opening this PR? (yes / edit / no)". STOP and wait.

9. Act on the answer

  • Explicit approval ("yes", "go ahead", "approve", "dale", "sí"): run exactly the commands you showed. Pass the body with --body-file (a UTF-8 temp file outside the worktree) so formatting is preserved. Delete the temp file afterward. Report the PR URL from the gh output.
  • Edit request: apply the edits, show the full updated draft again, and ask again. Earlier approval never covers a changed draft.
  • Partial approval ("push but don't open the PR yet"): run only the approved part.
  • "no" or silence: do nothing remote. Keep the local branch and report its state.
  • Command failure (rejected push, gh error): report the exact error. Do not force-push, and do not retry with different flags without new approval.

10. Save to memory

PROACTIVE SAVE TRIGGERS: call mem_save without being asked when any of these happen:

  • A PR was opened. Save the URL, branch, base, title, and linked issue.
  • A chain strategy or slice boundaries were decided through chained-pr.
  • The user set a PR convention or preference, such as a branch naming rule, a title scope, or "always draft PRs".
  • The user declined a push or PR. Save the branch state so the next session can resume.
  • A gotcha came up, such as a protected branch, required checks, a gh auth problem, or a repo-specific template that overrode the defaults.

Use type: decision or pattern for conventions and type: config for repo setup findings. Use a stable topic_key, for example pr/<repo>/<branch> or conventions/pr. Content format: What / Why / Where / Learned. Save before you write the final reply. The final reply always contains the full outcome, because a memory save is not a reply.

Rules

  • MUST NOT run git push, gh pr create, gh pr edit, gh pr merge, or any other remote-mutating command before the user explicitly approves the exact draft shown.
  • MUST show a new draft and get a new approval after any change to the title, body, branch, base, or commit set.
  • MUST NOT add AI attribution anywhere: no Co-Authored-By trailers, no "Generated with ...", no AI mentions, no robot emoji. This applies to commits, PR titles, and PR bodies.
  • MUST use a Conventional Commits title.
  • MUST include the What, Why, How tested, and Linked issue sections, in that order.
  • MUST delegate to chained-pr when authored changed lines exceed 400. Never open a single PR over 400 lines unless the user explicitly chooses an exception after seeing the count.
  • MUST NOT merge PRs, force-push, rewrite history, delete branches, or change repo settings.
  • MUST NOT fabricate test results, issue numbers, or line counts.
  • MUST NOT commit secrets or local config (.env, credentials, settings.local.json). Warn the user if any are staged.
  • MUST NOT authenticate gh, change git config, or use credentials that haven't been explicitly authorized.
  • Ask at most one question at a time, then stop and wait.
  • A repository PR template (.github/pull_request_template.md) or a branch-pr convention takes precedence over these defaults. Still keep the What, Why, and How tested content and the issue link inside it.

Examples

Example 1: Small feature, approved

User: "Open a PR for the CSV export."

  1. The agent loads branch-pr, sees it's on main with 2 commits ahead, and finds issue #123 in a commit message.
  2. It creates feat/123-csv-export locally. The count is 180 authored lines, so it's a single PR.
  3. It shows the draft:
    Title: feat(export): add CSV export for reports
    
    ## What
    - Add `ExportCsvUseCase` and CSV serializer
    - Add "Export CSV" action to the reports toolbar
    
    ## Why
    Users need to analyze report data in spreadsheets (#123).
    
    ## How tested
    - `npm test -- export` → 14 passed
    - Manual: exported a 500-row report and opened it in LibreOffice
    
    ## Linked issue
    Closes #123
    
    Commands: git push -u origin feat/123-csv-export, then gh pr create --base main ... "Approve pushing and opening this PR? (yes / edit / no)"
  4. User: "yes". The agent pushes, creates the PR, reports the URL, and saves pr/app/feat-123-csv-export to Engram.

Example 2: Over 400 lines, handed to chained-pr

User: "Prepare the PR for the auth refactor."

The diff is 1,140 authored lines (lockfile excluded). The agent reports: "1,140 lines exceeds the 400-line budget, so I'm handing off to chained-pr." chained-pr asks one question about the chain strategy (stacked-to-main or a feature-branch chain). Each resulting PR gets its own Conventional title, What/Why/How tested body, and issue link. Every draft is shown, and nothing is pushed until the user approves it.

Example 3: No issue found

There is no issue number in the request, the branch name, the commits, or memory. The agent asks: "Which issue does this PR resolve? (number, or 'none')" and stops. User: "none". The body says No linked issue, and the draft notes it.

Example 4: Draft edited after approval was requested

User: "Change the scope to reports and say it's a draft PR." The agent updates the title to feat(reports): ..., adds --draft to the gh pr create command, shows the full draft again, and asks for approval again. It does not reuse the earlier "yes".

Example 5: Push rejected

The user approves, but git push fails with "protected branch hook declined". The agent reports the exact error, does not force-push or retry, and saves the gotcha (type: config) to Engram.

Example 6: False activation avoided

User: "Review PR #87 for me." This is a review, not PR creation, so this skill does not activate and the review skill handles it.

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Habilidades Relacionadas