| name | create-pr |
| description | Commits relevant local changes, pushes a focused branch, and opens a draft pull request on the current GitHub repository using the project's PR template (single or multi-template). Use when the user runs /create-pr. |
| license | Unlicense OR MIT |
| compatibility | Requires git and the GitHub CLI (gh) authenticated to the target repository, plus network access. |
Create PR
Instructions
Explicit permission to commit relevant changes, push the branch, and open a draft pull request.
Steps
-
Inspect the repository:
git status --short --branch
git diff
git diff --staged
git log --oneline -5
-
If there is nothing to commit, stop.
-
Resolve the base branch from the remote default (do not hardcode main):
BASE_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
-
If the current branch is the base branch, create a focused branch first. Use the issue number or a change summary; ask when ambiguous.
-
Stage only relevant files. Exclude secrets and unrelated local changes.
-
Commit with a concise Conventional Commit message passed via HEREDOC:
- Subject format:
type(scope): summary.
- Use one of:
feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert.
- Pick the narrowest accurate scope; omit the scope only when no meaningful scope exists.
- Use imperative mood, lowercase the summary after the type/scope, and do not end the subject with a period.
-
Push with upstream tracking when needed: git push -u origin HEAD.
-
Resolve the PR template:
- Search
.github/pull_request_template.md and .github/PULL_REQUEST_TEMPLATE/.
- Read
.github/pull_request_template.md, or pick the matching template under .github/PULL_REQUEST_TEMPLATE/ when multiple templates are discovered.
- Absence protocol: after the template search finds no PR template, state that no project PR template was found and use a minimal structure: Summary, Testing, Linked issues.
- Fill the template faithfully and preserve its structure.
-
Open as a draft via GraphQL first:
gh api graphql \
-f query='mutation($repositoryId:ID!, $base:String!, $head:String!, $title:String!, $body:String!) {
createPullRequest(input: {
repositoryId: $repositoryId,
baseRefName: $base,
headRefName: $head,
title: $title,
body: $body,
draft: true
}) {
pullRequest { url number }
}
}' \
-F repositoryId="$REPOSITORY_ID" \
-f base="$BASE_BRANCH" \
-f head="$HEAD_BRANCH" \
-f title="$PR_TITLE" \
-f body="$PR_BODY"
-
If GraphQL is rate-limited or unavailable, fall back to REST as a draft:
gh api "repos/$OWNER/$REPO/pulls" \
-f title="$PR_TITLE" \
-f head="$HEAD_BRANCH" \
-f base="$BASE_BRANCH" \
-f body="$PR_BODY" \
-F draft=true \
--jq '.html_url'
-
Return the PR URL.
Do not skip git hooks or verification unless the user explicitly asks.