can1357/oh-my-pi · error · ToolError

origin remote is unavailable for this repository.

Error message

origin remote is unavailable for this repository.

What it means

ensurePrRemoteWithRepo, for same-repository PRs, reuses the `origin` remote URL as the clone/worktree source. If `repository.remoteUrl("origin")` returns null — no origin remote is configured — it throws this ToolError because there is no URL to fetch the PR from.

Source

Thrown at packages/coding-agent/src/tools/gh-pr-checkout.ts:154

export async function ensurePrRemote(
	repoRoot: string,
	data: GhPrViewData,
	signal?: AbortSignal,
): Promise<{ name: string; url: string }> {
	return ensurePrRemoteWithRepo(repoRoot, data, vcs.requireGit(repoRoot), signal);
}

async function ensurePrRemoteWithRepo(
	repoRoot: string,
	data: GhPrViewData,
	repository: VcsGitRepo,
	signal?: AbortSignal,
): Promise<{ name: string; url: string }> {
	if (!data.isCrossRepository) {
		const originUrl = await repository.remoteUrl("origin", signal);
		if (!originUrl) {
			throw new ToolError("origin remote is unavailable for this repository.");
		}

		return {
			name: "origin",
			url: originUrl,
		};
	}

	const headRepository = requireNonEmpty(data.headRepository?.nameWithOwner, "head repository");
	const pullRepo = parsePullRequestUrl(data.url).repo;
	const pullHost = pullRepo ? parseRepoRef(pullRepo).host : undefined;
	const repoSummary = await github.json<GhRepoViewData>(
		repoRoot,
		["repo", "view", formatRepoRef(pullHost, headRepository), "--json", GH_REPO_CLONE_FIELDS.join(",")],
		signal,
		{ repoProvided: true },
	);
	const originUrl = await repository.remoteUrl("origin", signal);

View on GitHub (pinned to 9690622007)

Solutions

  1. Add the origin remote: `git remote add origin <https or ssh GitHub URL>` and retry.
  2. Point the checkout at the correct existing remote by configuring/renaming it to origin (`git remote rename upstream origin`).
  3. If it's a cross-repo PR, ensure headRepository metadata is correct so the fork URL path is taken instead of the origin path.

Example fix

# before
$ git remote -v   # (empty or only 'upstream')
# after
$ git remote add origin https://github.com/owner/repo.git
$ git fetch origin
Defensive patterns

Strategy: validation

Validate before calling

import { $ } from "bun";
const remote = await $`git remote get-url origin`.cwd(cwd).quiet().nothrow();
if (remote.exitCode !== 0) {
  throw new Error("origin remote missing; add it before PR checkout");
}

Try / catch

try {
  await checkoutPullRequest({ cwd, pr });
} catch (err) {
  if (err instanceof ToolError && err.message.includes("origin remote is unavailable")) {
    await $`git remote add origin https://github.com/owner/repo.git`.cwd(cwd);
    // retry checkout
  } else throw err;
}

Prevention

When it happens

Trigger: checkoutPullRequest on a PR whose head is in the same repository, in a repo that has no `origin` remote (cloned from a local path, added as a secondary remote with another name, or initialized locally).

Common situations: Repo initialized locally (git init) then PR opened after pushing via a differently named remote; remotes renamed so origin is missing; sparse CI checkouts that strip remotes.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/fddb5480e84b8086. Report an issue: GitHub.