{"record":{"id":"2fefca9501151a8e","repo":"can1357/oh-my-pi","slug":"github-cli-returned-an-unrecognized-repository-url","errorCode":null,"errorMessage":"GitHub CLI returned an unrecognized repository URL: ${url}","messagePattern":"GitHub CLI returned an unrecognized repository URL: (.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/gh-common.ts","lineNumber":226,"sourceCode":"\tconst leftRef = parseRepoRef(left);\n\tconst rightRef = parseRepoRef(right);\n\tif (effectiveHost(leftRef) !== effectiveHost(rightRef)) return false;\n\treturn leftRef.slug.toLowerCase() === rightRef.slug.toLowerCase();\n}\n\n/**\n * Ask `gh` which repository the checkout points at, as `[HOST/]OWNER/REPO`.\n *\n * `nameWithOwner` alone would drop the host, and `gh` resolves a host-less\n * `--repo` against `GH_HOST` (github.com by default) — so an enterprise\n * checkout would silently be looked up on github.com. The repo URL carries\n * the host `gh` itself resolved from the remote.\n */\nasync function resolveRepoFromCwd(cwd: string, signal?: AbortSignal): Promise<string> {\n\tconst url = requireNonEmpty(await github.text(cwd, [\"repo\", \"view\", \"--json\", \"url\", \"-q\", \".url\"], signal), \"repo\");\n\tconst repo = repoFromUrl(url);\n\tif (!repo) {\n\t\tthrow new ToolError(`GitHub CLI returned an unrecognized repository URL: ${url}`);\n\t}\n\treturn repo;\n}\n\nexport async function resolveGitHubRepo(\n\tcwd: string,\n\trepo: string | undefined,\n\trunRepo: string | undefined,\n\tsignal?: AbortSignal,\n): Promise<string> {\n\tif (repo && runRepo && !githubRepoSlugEquals(repo, runRepo)) {\n\t\tthrow new ToolError(\"run URL repository does not match the provided repo\");\n\t}\n\n\tif (repo) {\n\t\treturn repo;\n\t}\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/gh-common.ts#L208-L244","documentation":"resolveRepoFromCwd runs `gh repo view --json url -q .url` and parses the returned URL into an owner/name slug. If gh returns a URL that repoFromUrl cannot recognize, it throws this ToolError — meaning the GitHub CLI output is in an unexpected format (unusual host, enterprise remote, or gh misconfiguration).","triggerScenarios":"`gh repo view` succeeds in cwd but emits a URL that does not match expected github.com (or accepted host) patterns — e.g. a non-GitHub remote behind an enterprise proxy, a rewritten gh host alias, or a gh version producing a different URL shape.","commonSituations":"GitHub Enterprise with custom hostname not in gh's recognized hosts; gh authenticated against a different host; malformed git remote causing gh to echo an odd URL; older/newer gh CLI output format changes.","solutions":["Pass the repo explicitly (owner/name) instead of relying on cwd resolution.","Check `gh repo view --json url` output and `gh auth status`; fix the host with `gh auth login` for the right hostname.","Update (or pin) the gh CLI to a version producing standard https://host/owner/repo URLs.","Ensure the git remote origin points at a standard GitHub URL."],"exampleFix":"// before (relies on cwd resolution)\nconst repo = await resolveGitHubRepo(cwd);\n// after\nconst repo = await resolveGitHubRepo(cwd, \"owner/name\");","handlingStrategy":"try-catch","validationCode":"import { $ } from \"bun\";\nconst res = await $`gh repo view --json url -q .url`.cwd(cwd).quiet().nothrow();\nconst url = res.exitCode === 0 ? res.text().trim() : \"\";\nconst ok = /^https:\\/\\/[^/]+\\/[^/]+\\/[^/]+$/.test(url);\nif (!ok) repo = \"owner/name\"; // pass explicitly","typeGuard":null,"tryCatchPattern":"try {\n  repo = await resolveGitHubRepo(cwd);\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"unrecognized repository URL\")) {\n    repo = configuredDefaultRepo; // e.g. from config/env\n  } else throw err;\n}","preventionTips":["Pin/update the gh CLI and keep `gh auth status` valid for the right host.","Pass repo explicitly (owner/name) whenever the environment is not a standard github.com clone.","For GitHub Enterprise, confirm the host is recognized by gh (hosts.yml)."],"tags":["github","gh-cli","parsing","url"],"backgroundTag":"unexpected-cli-output","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}