| name | create-pr |
| description | Creates a GitHub pull request following project conventions. Use when the user asks to create a PR, submit changes for review, or open a pull request. Handles commit analysis, branch management, and PR creation using the gh CLI tool. |
| argument-hint | [draft] [ja] |
Create Pull Request
Create a well-structured GitHub pull request.
Quick Start
/create-pr
/create-pr draft
/create-pr ja
/create-pr draft ja
Argument Handling
Parse $ARGUMENTS for the following flags (order-independent):
draft → create the PR as a draft
ja → write the PR title and body in Japanese. Only apply when ja is explicitly present in $ARGUMENTS — never infer from conversation language or user locale
Prerequisites Check
Verify clean working directory:
git status
If there are uncommitted changes, ask the user whether to:
- Commit them as part of this PR
- Stash them temporarily
- Discard them (with caution)
Gather Context
1. Identify the current branch
git branch --show-current
Ensure you're not on main or master. If so, ask the user to create or switch to a feature branch.
2. Find the base branch
git remote show origin | rg "HEAD branch"
3. Analyze recent commits
git log origin/main..HEAD --oneline --no-decorate
4. Review the diff
git diff origin/main..HEAD --stat
Information Gathering
Gather the following from commits, branch name, and changed files:
- Summary: What changes are being made and why?
- References: Related issues, PRs, or external links. Look for patterns like
#123, fixes #123, or closes #123 in commit messages and branch names (e.g., fix/issue-123).
If the summary is unclear from context, ask the user to describe the changes.
Branch Management
Before creating the PR:
-
Rebase on latest main (if needed):
git fetch origin
git rebase origin/main
-
Push changes:
git push origin HEAD
If the branch was rebased:
git push origin HEAD --force-with-lease
Create the Pull Request
PR Body Format
First, check if a PR template exists in the repository:
cat .github/pull_request_template.md 2>/dev/null || echo "NO_TEMPLATE"
- If a template exists: Read and fill in its sections based on the gathered context. Follow the template structure strictly.
- If no template exists: Use the following default format:
## Summary
<Concise description of the changes and their purpose>
## References
- <Related issues (e.g., closes #123), PRs, or external links>
- <If none, use "n/a">
Write in English by default. Only write in Japanese when ja was explicitly passed in $ARGUMENTS. Do NOT infer the language from the user's conversation language — always default to English. If the project's CLAUDE.md has a Language section, follow its rules.
Example: if $ARGUMENTS is empty or contains only draft, write in English regardless of what language the user is speaking.
Create PR with gh CLI
Write the PR body to a temporary file using the Write tool:
- File path:
/tmp/pr-body-<random>.md (use a short random suffix, e.g. 6 alphanumeric chars, to avoid conflicts across parallel sessions)
Then create the PR referencing the file:
gh pr create --title "PR_TITLE" --body-file /tmp/pr-body-<random>.md --base main
- If
draft was passed in $ARGUMENTS, add the --draft flag
Post-Creation
After creating the PR:
- Display the PR URL so the user can review it
- Suggest next steps if applicable:
- Add reviewers:
gh pr edit --add-reviewer USERNAME
- Add labels:
gh pr edit --add-label "bug"
- Clean up the temporary file:
rm /tmp/pr-body-<random>.md
Error Handling
- No commits ahead of main: Ask if the user meant to work on a different branch
- Branch not pushed: Push first with
git push -u origin HEAD
- PR already exists: Show existing PR with
gh pr view, ask if they want to update it
- Merge conflicts: Guide user through resolving conflicts or rebasing