cli/cli · error

cannot open in browser: maximum URL length exceeded

Error message

cannot open in browser: maximum URL length exceeded

What it means

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.

Source

Thrown at pkg/cmd/pr/create/create.go:456

	if opts.WebMode {
		if !(opts.Autofill || opts.FillFirst) {
			state.Title = opts.Title
			state.Body = opts.Body
		}
		if opts.Template != "" {
			state.Template = opts.Template
		}
		err = handlePush(*opts, *ctx)
		if err != nil {
			return err
		}
		openURL, err = generateCompareURL(*ctx, *state, projectsV1Support)
		if err != nil {
			return err
		}
		if !shared.ValidURL(openURL) {
			err = fmt.Errorf("cannot open in browser: maximum URL length exceeded")
			return err
		}
		return previewPR(*opts, openURL)
	}

	if opts.TitleProvided {
		state.Title = opts.Title
	}

	if opts.BodyProvided {
		state.Body = opts.Body
	}

	existingPR, _, err := opts.Finder.Find(shared.FindOptions{
		Selector:   ctx.PRRefs.QualifiedHeadRef(),
		BaseBranch: ctx.PRRefs.BaseRef(),
		States:     []string{"OPEN"},
		Fields:     []string{"url"},

View on GitHub (pinned to 0eeec0b92e)

Solutions

  1. Shorten the body: use a shorter --body and add detail after creation, or `--body-file` with a concise summary for web mode.
  2. Drop --web and create directly: `gh pr create --title ... --body-file ...` (no URL length constraint).
  3. Reference a template or linked doc instead of inlining huge content in the prefilled form.

Example fix

# before
gh pr create --web --title "Release" --body-file HUGE_NOTES.md
# error: cannot open in browser: maximum URL length exceeded

# after
gh pr create --title "Release" --body-file HUGE_NOTES.md
Defensive patterns

Strategy: validation

Validate before calling

# keep --web URLs within browser limits; estimate encoded length
len=$(python3 - <<EOF
import urllib.parse, sys
print(len(urllib.parse.quote(sys.argv[1] + sys.argv[2])))
EOF
 "$TITLE" "$BODY")
[ "$len" -lt 7000 ] || { echo 'payload too long for --web; dropping --web' >&2; exec gh pr create --title "$TITLE" --body "$BODY"; }
gh pr create --web --title "$TITLE" --body "$BODY"

Prevention

When it happens

Trigger: `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.

Common situations: Passing a huge --body from a file; long ISSUE_TEMPLATE bodies; CHANGELOG-derived PR descriptions; automation injecting release notes into --web mode.

Related errors


AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15). Data as JSON: /api/errors/acb70c939dc7dd52. Report an issue: GitHub.