You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given I have a branch checked out and have it pushed to the remote repo When I run pr create --json id,url,number, follow the prompts (interactive flow) Then A PR is created, and I see a JSON on stdout with the url, id and number fields of the created PR
Non-interactive flow
Given I have a branch checked out and have it pushed to the remote repo When I run pr create --json id,url,number --title foo --body bar 2>/dev/null | cat(non-interactive flow) Then I see a JSON on stdout with the url, id and number fields of the created PR
JQ support
Given I have a branch checked out and have it pushed to the remote repo …
IMO it would be a decent enhancement to gh pr create. However, historically, the team had reasons for dropping it (#6366, #11025). I believe there are complications around the implementation. For example, you can see the recent #11196 which is about adding the same --json option to gh issue create.
That said, I'm going to do what we did with #11196 and label this for an internal discussion. I'll keep you posted.
🤔 Seeing this pop up in #11558, I want to ask "How should the Unix principle apply to this idea?" as I'm unsure what the limit of gh pr create should be able to accomplish by itself.
I would vote for option 1 - omit template option. I'd like to hear from people that they want the template specifically before we make a fuss over the problems that adding it would cause.
Given I have a branch checked out and have it pushed to the remote repo When I run pr create --json id,url,number, follow the prompts (interactive flow) Then A PR is created, and I see a JSON on stdout with the url, id and number fields of the created PR
Non-interactive flow
Given I have a branch checked out and have it pushed to the remote repo When I run pr create --json id,url,number --title foo --body bar 2>/dev/null | cat(non-interactive flow) Then I see a JSON on stdout with the url, id and number fields of the created PR
JQ support
Given I have a branch checked out and have it pushed to the remote repo When I run pr create --json id,url,number --jq .number --title foo --body bar 2>/dev/null | cat Then I see the PR number is printed on stdout
Incompatible with --dry-run
When I run pr create --json id --dry-run Then I get an error message saying these options are mutually exclusive
Independent of --template
Given My repo has a PR template named pull_request_template.md When I run pr create --json id,url,number --template pull_request_template.md Then I see a JSON on stdout with the url, id and number fields of the created PR, AND the PR is created off of the given template
We need to create a new helper function to the cmdutil package that adds the two --json and --jq option to the given Cobra command instance. For now, it shouldn't also add the -q shorthand for --jq. This can be used as an example:
Make JSON flag validation aware of missing --template
Given a hydrated Cobra command, the checkJSONFlags function in cmdutil validates the combination of JSON-related options. Currently, it assumes the --template option is always part of the JSON options group. This needs to be changed, because in our case of pr create the --template option is not part of the JSON options. Basically, we need to modify the implementation to trickle down the exclusion/inclusion of the --template option to checkJSONFlags.
3. pkg/cmd/pr/create/create.go
Add the JSON-related options
We should use the newly created function to add --json and --jq options to pr create. As an example, look at the pr view command's way of doing this (below). However, since we're not going to support all api.PullRequest fields, the fields argument should be replaced with a local slice, including id, url, and number.
funcsubmitPR(optsCreateOptions, ctxCreateContext, state shared.IssueMetadataState, projectV1Support gh.ProjectsV1Support) error {
Note
The api.PullRequest type already implements everything needed to export a nice JSON. So, you wouldn't need to reimplement the JSON marshalling override.
Bail out if --json is used with --dry-run
These options cannot be used together, so we should add a validation check in the cmd.RunE assignment, around here:
Hi! I noticed #12622 was closed. I’d like to pick this up and open a fresh PR for #11247, following the acceptance criteria above. Is that still welcome?
Activity
babakks commentedon Jul 9, 2025
Hi @dukeofgaming, and thanks for your suggestion! 🙏
IMO it would be a decent enhancement to
gh pr create. However, historically, the team had reasons for dropping it (#6366, #11025). I believe there are complications around the implementation. For example, you can see the recent #11196 which is about adding the same--jsonoption togh issue create.That said, I'm going to do what we did with #11196 and label this for an internal discussion. I'll keep you posted.
[-]Add --json and --jq to gh pr create[/-][+]Add `--json` and `--jq` to `gh pr create`[/+]--jsonand--jqSupport togh pr create#11558 as a duplicate of this issueandyfeller commentedon Oct 8, 2025
🤔 Seeing this pop up in #11558, I want to ask "How should the Unix principle apply to this idea?" as I'm unsure what the limit of
gh pr createshould be able to accomplish by itself.BagToad commentedon Nov 10, 2025
Marking this as triaged since @babakks and I think this is a good feature to investigate more deeply.
1 remaining item
BagToad commentedon Jan 30, 2026
@babakks oof good catch.
I would vote for option 1 - omit template option. I'd like to hear from people that they want the template specifically before we make a fuss over the problems that adding it would cause.
babakks commentedon Feb 4, 2026
Fair enough. Here's the A/C for this issue.
Acceptance Criteria
Interactive flow
Given I have a branch checked out and have it pushed to the remote repo
When I run
pr create --json id,url,number, follow the prompts (interactive flow)Then A PR is created, and I see a JSON on stdout with the
url,idandnumberfields of the created PRNon-interactive flow
Given I have a branch checked out and have it pushed to the remote repo
When I run
pr create --json id,url,number --title foo --body bar 2>/dev/null | cat(non-interactive flow)Then I see a JSON on stdout with the
url,idandnumberfields of the created PRJQ support
Given I have a branch checked out and have it pushed to the remote repo
When I run
pr create --json id,url,number --jq .number --title foo --body bar 2>/dev/null | catThen I see the PR number is printed on stdout
Incompatible with
--dry-runWhen I run
pr create --json id --dry-runThen I get an error message saying these options are mutually exclusive
Independent of
--templateGiven My repo has a PR template named
pull_request_template.mdWhen I run
pr create --json id,url,number --template pull_request_template.mdThen I see a JSON on stdout with the
url,idandnumberfields of the created PR, AND the PR is created off of the given templatebabakks commentedon Feb 4, 2026
This is for anyone who's going to work on this. The above comment lists the acceptance criteria that the PR must satisfy.
Here are the places that we need to modify/improve. I didn't cover the test files, but any new/changed behaviour must accompany relevant tests.
1.
api/queries_pr.goAdd the
numberfield to the mutation in theapi.CreatePullRequestfunction:cli/api/queries_pr.go
Lines 531 to 539 in af4dad0
2.
pkg/cmdutil/json_flags.goA new helper to add
--jsonand--jqoptionsWe need to create a new helper function to the
cmdutilpackage that adds the two--jsonand--jqoption to the given Cobra command instance. For now, it shouldn't also add the-qshorthand for--jq. This can be used as an example:cli/pkg/cmdutil/json_flags.go
Line 35 in 150834b
Make JSON flag validation aware of missing
--templateGiven a hydrated Cobra command, the
checkJSONFlagsfunction incmdutilvalidates the combination of JSON-related options. Currently, it assumes the--templateoption is always part of the JSON options group. This needs to be changed, because in our case ofpr createthe--templateoption is not part of the JSON options. Basically, we need to modify the implementation to trickle down the exclusion/inclusion of the--templateoption tocheckJSONFlags.3.
pkg/cmd/pr/create/create.goAdd the JSON-related options
We should use the newly created function to add
--jsonand--jqoptions topr create. As an example, look at thepr viewcommand's way of doing this (below). However, since we're not going to support allapi.PullRequestfields, the fields argument should be replaced with a local slice, includingid,url, andnumber.cli/pkg/cmd/pr/view/view.go
Lines 79 to 80 in af4dad0
The final JSON export should happen at the end of the
submitPRfunction:cli/pkg/cmd/pr/create/create.go
Line 1001 in af4dad0
Note
The
api.PullRequesttype already implements everything needed to export a nice JSON. So, you wouldn't need to reimplement the JSON marshalling override.Bail out if
--jsonis used with--dry-runThese options cannot be used together, so we should add a validation check in the
cmd.RunEassignment, around here:cli/pkg/cmd/pr/create/create.go
Lines 328 to 330 in af4dad0
babakks commentedon Feb 10, 2026
@yuvrajangadsingh, thanks for your interest, but there's already a PR for this waiting for review (See #12622).
yuvrajangadsingh commentedon Feb 10, 2026
@babakks Ah, didn't notice #12622 — thanks for the heads up! I'll back off on this one.
feat(pr create): add --json and --jq flags for structured output
feat(pr-create): add --json and --jq flags for structured output
natsu0529 commentedon Jul 6, 2026
Hi! I noticed #12622 was closed. I’d like to pick this up and open a fresh PR for #11247, following the acceptance criteria above. Is that still welcome?
feat(pr create): add --json and --jq flags for machine-readable output
LeonxLJX commentedon Aug 27, 2026
Hi! I'd like to work on this issue. Please let me know if I can be assigned. Thanks!
LeonxLJX commentedon Sep 1, 2026
Hi! I'd like to add
--jsonand--jqtogh pr create. Plan: implement the flags, add tests. May I be assigned?