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 by gh issue create --web when the preview URL built from the provided title/body/metadata exceeds prShared.ValidURL's maximum length. Browsers and the Browse call cannot reliably handle arbitrarily long URLs, so gh refuses instead of opening a broken page.
Source
Thrown at pkg/cmd/issue/create/create.go:234
if opts.RecoverFile != "" {
err = prShared.FillFromJSON(opts.IO, opts.RecoverFile, &tb)
if err != nil {
err = fmt.Errorf("failed to recover input: %w", err)
return
}
}
tpl := prShared.NewTemplateManager(httpClient, baseRepo, opts.Prompter, opts.RootDirOverride, !opts.HasRepoOverride, false)
if opts.WebMode {
var openURL string
if opts.Title != "" || opts.Body != "" || tb.HasMetadata() {
openURL, err = generatePreviewURL(apiClient, baseRepo, tb, projectsV1Support)
if err != nil {
return
}
if !prShared.ValidURL(openURL) {
err = fmt.Errorf("cannot open in browser: maximum URL length exceeded")
return
}
} else if ok, _ := tpl.HasTemplates(); ok {
openURL = ghrepo.GenerateRepoURL(baseRepo, "issues/new/choose")
} else {
openURL = ghrepo.GenerateRepoURL(baseRepo, "issues/new")
}
if isTerminal {
fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
}
return opts.Browser.Browse(openURL)
}
if isTerminal {
fmt.Fprintf(opts.IO.ErrOut, "\nCreating issue in %s\n\n", ghrepo.FullName(baseRepo))
}
repo, err := api.IssueRepoInfo(apiClient, baseRepo)View on GitHub (pinned to 0eeec0b92e)
Solutions
- Shorten the body or reference an attached file instead of inlining it.
- Drop --web and create the issue directly: `gh issue create --title ... --body-file ...` (no URL length limit applies).
- If a browser flow is required, create with a short placeholder body, then edit the issue on github.com and paste the long content there.
Example fix
# before gh issue create --web --title "crash" --body "$(cat 5mb.log)" # gh: cannot open in browser: maximum URL length exceeded # after gh issue create --title "crash" --body-file 5mb.log
Defensive patterns
Strategy: validation
Validate before calling
// Keep the body under the URL budget when using --web:
const maxURLLen = 8219 // prShared.ValidURL bound
func fitsWebURL(title, body string, metaLen int) bool {
// URL-encoding roughly triples worst-case payloads; use a conservative check
return len(title)+len(body)+metaLen < maxURLLen/3
} Type guard
func validURL(u string) bool {
return len(u) < 8219
} Try / catch
if err := createRun(opts); err != nil {
if err.Error() == "cannot open in browser: maximum URL length exceeded" {
// retry without --web: create directly with --title/--body-file
}
} Prevention
- Avoid --web for bodies over a few KB; create directly and let gh POST the content.
- Attach large logs as files rather than inlining them into --body.
- In automation, prefer the non-web path unconditionally.
When it happens
Trigger: `gh issue create --web` with a very large --body (e.g. contents of a huge log pasted or `--body-file` of a large file) plus title/labels; generatePreviewURL encodes everything into query parameters and the result crosses the limit.
Common situations: Piping whole log files into --body, using --web with machine-generated diagnostics, or reusing a command line that worked until the body grew past the threshold.
Related errors
- not a valid agent session URL
- `--template` is not supported when using `--body` or `--body
- already locked
- issue was not found but GraphQL reported no error
- failed to recover input: %w
AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15).
Data as JSON: /api/errors/aaa6c1ee1452a565.
Report an issue: GitHub.