{"record":{"id":"acb70c939dc7dd52","repo":"cli/cli","slug":"cannot-open-in-browser-maximum-url-length-exceede-acb70c","errorCode":null,"errorMessage":"cannot open in browser: maximum URL length exceeded","messagePattern":"cannot open in browser: maximum URL length exceeded","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pr/create/create.go","lineNumber":456,"sourceCode":"\n\tif opts.WebMode {\n\t\tif !(opts.Autofill || opts.FillFirst) {\n\t\t\tstate.Title = opts.Title\n\t\t\tstate.Body = opts.Body\n\t\t}\n\t\tif opts.Template != \"\" {\n\t\t\tstate.Template = opts.Template\n\t\t}\n\t\terr = handlePush(*opts, *ctx)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\topenURL, err = generateCompareURL(*ctx, *state, projectsV1Support)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif !shared.ValidURL(openURL) {\n\t\t\terr = fmt.Errorf(\"cannot open in browser: maximum URL length exceeded\")\n\t\t\treturn err\n\t\t}\n\t\treturn previewPR(*opts, openURL)\n\t}\n\n\tif opts.TitleProvided {\n\t\tstate.Title = opts.Title\n\t}\n\n\tif opts.BodyProvided {\n\t\tstate.Body = opts.Body\n\t}\n\n\texistingPR, _, err := opts.Finder.Find(shared.FindOptions{\n\t\tSelector:   ctx.PRRefs.QualifiedHeadRef(),\n\t\tBaseBranch: ctx.PRRefs.BaseRef(),\n\t\tStates:     []string{\"OPEN\"},\n\t\tFields:     []string{\"url\"},","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/pkg/cmd/pr/create/create.go#L438-L474","documentation":"Thrown in the --web flow of `gh pr create`: after generateCompareURL builds the compare URL, shared.ValidURL rejects it (roughly the 8k-character URL limit) because the prefilled title/body query parameters make the URL too long for a browser request. Prevented before previewPR opens anything.","triggerScenarios":"`gh pr create --web` (or fallback web mode) where state.Title plus state.Body (e.g. a large --body, a template, or recover-file content) exceed the maximum URL length when percent-encoded into the compare URL's query string.","commonSituations":"Passing a huge --body from a file; long ISSUE_TEMPLATE bodies; CHANGELOG-derived PR descriptions; automation injecting release notes into --web mode.","solutions":["Shorten the body: use a shorter --body and add detail after creation, or `--body-file` with a concise summary for web mode.","Drop --web and create directly: `gh pr create --title ... --body-file ...` (no URL length constraint).","Reference a template or linked doc instead of inlining huge content in the prefilled form."],"exampleFix":"# before\ngh pr create --web --title \"Release\" --body-file HUGE_NOTES.md\n# error: cannot open in browser: maximum URL length exceeded\n\n# after\ngh pr create --title \"Release\" --body-file HUGE_NOTES.md","handlingStrategy":"validation","validationCode":"# keep --web URLs within browser limits; estimate encoded length\nlen=$(python3 - <<EOF\nimport urllib.parse, sys\nprint(len(urllib.parse.quote(sys.argv[1] + sys.argv[2])))\nEOF\n \"$TITLE\" \"$BODY\")\n[ \"$len\" -lt 7000 ] || { echo 'payload too long for --web; dropping --web' >&2; exec gh pr create --title \"$TITLE\" --body \"$BODY\"; }\ngh pr create --web --title \"$TITLE\" --body \"$BODY\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid --web for large bodies; create directly with --body-file.","Link to a doc or template instead of inlining huge text into the compare URL.","Remember only the prefilled query params cause the overflow, not the compare path itself."],"tags":["url","pr-create","web","validation"],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}