Open a pull request with create_pull_request
Open a pull request programmatically via GitHub’s GraphQL
createPullRequest mutation, without leaving your agent session.
Prerequisites
Section titled “Prerequisites”github-pull-requestsinstalled.- A head branch already pushed to the repository, with commits ahead of the base branch.
- Auth with write access to the target repository (
GITHUB_TOKENorghCLI login).
-
Identify the
owner,repo,baseRefName(e.g.main), andheadRefName(your pushed branch) for the PR. -
Call
create_pull_request:{"owner": "your-org","repo": "your-repo","title": "feat: add widget support","body": "Fixes #12","baseRefName": "main","headRefName": "feat/widget-support","draft": false}bodyanddraftare optional. If you want the merge to close an issue, writeFixes #N/Closes #Nintobodyyourself — the tool attaches no linkage or MIF frontmatter to the PR body on its own. -
Read the response:
{ number, url, nodeId }.
Verify it worked
Section titled “Verify it worked”Open url from the response, or call list_review_requests with the
returned number as pullNumber — a 200 response with an empty or populated
reviewer list confirms the PR exists.
- If a PR already exists for the same head ref, or
headRefNamedoes not exist, GitHub’s GraphQL rejection surfaces verbatim as agithub_api_error— there is no client-side pre-validation.