genai-pr
v0.5.0
Published
AI-powered PR description generator using Claude Code, Cursor CLI, or Codex CLI
Downloads
654
Maintainers
Readme
genai-pr
AI-powered PR description generator using Claude Code, Cursor CLI, or Codex CLI.
Read in other languages: 한국어
Features
- AI-powered PR descriptions - Generate PR title and body using Claude Code, Cursor CLI, or Codex CLI
- Template-based - Built-in templates (feature, bugfix) + custom project templates
- Existing PR support - Regenerate descriptions for existing PRs via
--url - Multi-language support - Generate titles and body in English or Korean
- Interactive workflow - Review, provide feedback, edit in editor, and refine before creating
- GitHub CLI integration - Creates PRs directly via
gh pr create - Auto-merge setup - Optionally enable auto-merge after PR creation, with a choice of merge method (rebase / squash / merge)
- Pre-flight checks - Validate remote branch state (missing remote, unpushed commits, no diff) before calling the AI, so no tokens are wasted on PRs that can't be created
How It Works
flowchart TD
A[Start: genai-pr] --> B{PR URL provided?}
B -->|Yes| C[Fetch PR info via gh CLI]
B -->|No| PF[Pre-flight checks]
PF -->|fail| PFX[Abort with guidance]
PF -->|pass| D[Collect remote Git data]
C --> E[Get commits, diff, changed files]
D --> F[git diff origin/base..origin/head + git log]
E --> G[Select Template]
F --> G
G --> H[Build AI Prompt]
H --> I{Select Provider}
I -->|Claude Code| J[Claude Code CLI]
I -->|Cursor CLI| K[Cursor CLI]
I -->|Codex CLI| K2[Codex CLI]
J --> L[Parse JSON Response]
K --> M[Parse Delimiter Response]
K2 --> M
L --> N[Display PR Preview]
M --> N
N --> O{User Action}
O -->|y| P[Create/Update PR via gh]
O -->|n| Q[Cancel]
O -->|f| R[Get Feedback]
O -->|e| S[Edit in $EDITOR]
R --> H
S --> N
P --> U{Enable auto-merge?}
U -->|Yes| V[Select merge method<br/>rebase / squash / merge]
U -->|No| T[Done]
V --> W[gh pr merge --auto]
W --> T[Done]Prerequisites
You need at least one of these AI CLI tools installed:
- Claude Code CLI - Anthropic's official CLI (command:
claude) - Cursor Agent CLI - Cursor's agent CLI (command:
agent) - OpenAI Codex CLI - OpenAI's Codex CLI (command:
codex)
Additionally, the GitHub CLI (gh) must be installed and authenticated.
Providers
Each provider can be referenced by its canonical name or short alias:
| Canonical | Short Alias | Underlying CLI |
|-----------|-------------|----------------|
| claude-code | claude | claude |
| cursor-cli | cursor | agent |
| codex-cli | codex | codex |
Installation
# Global installation
npm install -g genai-pr
# Or use directly with npx (no installation required)
npx genai-pr claudeUsage
Generate PR Description
# Canonical names
genai-pr claude-code
genai-pr cursor-cli
genai-pr codex-cli
# Short aliases (equivalent)
genai-pr claude
genai-pr cursor
genai-pr codex
# One-liner with options
genai-pr claude -t feature -b main
# Specify head and base branches
genai-pr claude --branch feature/AUTH-123 --base develop
# Create as draft PR
genai-pr claude --draft
# Preview without creating PR
genai-pr claude --dry-run
# With specific model
genai-pr claude --model sonnet
genai-pr cursor --model claude-4.5-sonnet
genai-pr codex --model gpt-5.4Regenerate Existing PR Description
# Update an existing PR's title and body
genai-pr claude --url https://github.com/owner/repo/pull/15Authentication
# Login
genai-pr login claude
genai-pr login cursor
genai-pr login codex
# Check status
genai-pr status claude
genai-pr status cursor
genai-pr status codexList Supported Models
genai-pr models claude
genai-pr models cursor
genai-pr models codexList Available Templates
# List built-in and project templates
genai-pr templates
# Include custom template directory
genai-pr templates --template-dir ./my-templatesPre-flight Checks
Before calling the AI, genai-pr validates the remote state of your branch so that it doesn't waste AI tokens on a PR that can't actually be created. These checks only run in the local-branch mode (not in --url mode) and apply even with --dry-run.
| # | Check | Failure message | Exit |
|---|-------|-----------------|------|
| 1 | origin/<head> exists | Remote branch 'origin/<head>' does not exist. Push your branch first: git push -u origin <head> | 1 |
| 2 | local <head> SHA == origin/<head> SHA | Local branch '<head>' is out of sync with 'origin/<head>': N unpushed commit(s) on local / M commit(s) on remote not in local. Push or pull to sync before creating a PR. | 1 |
| 3 | origin/<base>..origin/<head> has commits | No commits between origin/<base> and origin/<head> | 0 |
Because the diff and commit log are sourced from the remote refs (origin/<base>..origin/<head>), the AI always sees the exact content that will end up in the PR.
Interactive Options
After generating the PR description, you'll see an interactive menu:
| Option | Description |
|--------|-------------|
| [y] | Create PR (or Update PR when using --url) |
| [n] | Cancel |
| [f] | Provide feedback to regenerate |
| [e] | Edit in external editor ($EDITOR) |
Auto-merge
After the PR is created (or updated), you'll be asked:
? Enable auto-merge? (y/N)If you answer y, you'll be prompted to pick a merge method:
| Method | Behavior | When to use |
|--------|----------|-------------|
| rebase (default) | Replay each commit onto the base branch. All individual commits are preserved as a linear history. | You want each commit from the feature branch to remain visible on the base branch (e.g. carefully split commits). |
| squash | Combine all commits in the PR into a single commit on the base branch. | You don't care about intermediate commits and prefer a single summary commit. |
| merge | Create a merge commit that joins the PR branch into the base branch, preserving all commits and the branch structure. | You want to keep both individual commits and the branch history. |
The selected method is executed via gh pr merge --auto --<method>. The PR will be merged automatically once all required checks pass.
Note: This requires "Allow auto-merge" to be enabled in the repository settings (
Settings → General → Pull Requests). If it's disabled,ghwill report an error and auto-merge won't be configured.
Options
| Option | Description | Default |
|--------|-------------|---------|
| -t, --template <name> | PR template to use | interactive selection |
| -b, --base <branch> | Base/target branch | main |
| --branch <branch> | Head/source branch | current branch |
| -m, --model <model> | Model to use | haiku (Claude) / claude-4.5-sonnet (Cursor) / gpt-5.4 (Codex) |
| --lang <lang> | Set both title and body language (en|ko) | - |
| --title-lang <lang> | Language for PR title | en |
| --body-lang <lang> | Language for PR body | ko |
| --template-dir <path> | Custom template directory | - |
| --draft | Create as draft PR | false |
| --dry-run | Preview without creating PR | false |
| --url <url> | Existing PR URL to regenerate | - |
Built-in Templates
feature
## Summary
## Changes
## Test Planbugfix
## Summary
## Root Cause
## Fix
## Test PlanCustom Templates
Templates are loaded with the following priority:
--template-dir <path>- Custom directory (highest priority).github/PR_TEMPLATE/- Project-level templates- Built-in templates (feature, bugfix)
Create a .md file in any of these locations. The filename (without extension) becomes the template name.
Configuration
| Setting | Default | Description |
|---------|---------|-------------|
| maxInputSize | 50000 | Maximum AI input size in bytes |
| maxDiffSize | 30000 | Maximum diff size in bytes |
| timeout | 120000 | AI request timeout in ms |
Requirements
- Node.js >= 18.0.0
- Git repository
- GitHub CLI (
gh) installed and authenticated - Claude Code CLI, Cursor CLI, or Codex CLI installed and authenticated
License
MIT
