github/copilot-sdk · error

failed to fetch CLI version

Error message

failed to fetch CLI version: %w

What it means

After resolving the SDK version, detectCLIVersion fetches package.json from the SDK repo at that version to read the pinned copilotCliVersion. Failure of that network fetch is wrapped as 'failed to fetch CLI version'. The CLI version pin lives in the repo's package.json, not in go.mod.

Solutions

  1. Check network connectivity / proxy settings (HTTPS_PROXY) and retry
  2. Verify the SDK version from go.mod has a corresponding release/tag in the SDK repo
  3. Run `go get` to move to a released copilot-sdk version whose tag exists
  4. If rate-limited, wait or set a GITHUB_TOKEN if supported, then retry

Example fix

// before: failed to fetch CLI version: failed to fetch package.json: 404 Not Found
// after: pin a released SDK version
// before go.mod: copilot-sdk v0.0.0-dev
// after go.mod: copilot-sdk v0.5.0
Defensive patterns

Strategy: retry

Validate before calling

ver, err := exec.Command("go", "list", "-m", "-f", "{{.Version}}", sdkModule).Output()
if err == nil {
    ref := strings.TrimSpace(string(ver))
    resp, err := http.Head(fmt.Sprintf(packageJSONURLFmt, ref))
    if err != nil || resp.StatusCode != 200 {
        log.Printf("package.json unreachable for %s; use a released SDK version", ref)
    }
}

Try / catch

cli, err := detectCLIVersion()
if err != nil {
    if strings.Contains(err.Error(), "failed to fetch CLI version") {
        // fall back to a locally installed copilot CLI or retry with backoff
    }
}

Prevention

When it happens

Trigger: fetchCLIVersionFromRepo returns an error because the GitHub HTTP request fails, returns a non-200 status, or package.json cannot be parsed; this is re-wrapped by detectCLIVersion.

Common situations: Offline or behind a corporate proxy blocking raw.githubusercontent.com; the resolved SDK version has no matching git tag (misaligned release); GitHub rate limiting or outage.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/ecb2a49d610f7408. Report an issue: GitHub.

Appendix: source

Thrown at go/cmd/bundler/main.go:277

}

// detectCLIVersion detects the CLI version by:
// 1. Running "go list -m" to get the copilot-sdk version from the user's go.mod
// 2. Fetching package.json from the SDK repo at that version
// 3. Extracting the pinned Copilot CLI version from it
func detectCLIVersion() (string, error) {
	// Get the SDK version from the user's go.mod
	sdkVersion, err := getSDKVersion()
	if err != nil {
		return "", fmt.Errorf("failed to get SDK version: %w", err)
	}

	fmt.Printf("Found copilot-sdk %s in go.mod\n", sdkVersion)

	// Fetch package.json from the SDK repo at that version
	cliVersion, err := fetchCLIVersionFromRepo(sdkVersion)
	if err != nil {
		return "", fmt.Errorf("failed to fetch CLI version: %w", err)
	}

	return cliVersion, nil
}

// getSDKVersion runs "go list -m" to get the copilot-sdk version from go.mod
func getSDKVersion() (string, error) {
	cmd := exec.Command("go", "list", "-m", "-f", "{{.Version}}", sdkModule)
	output, err := cmd.Output()
	if err != nil {
		if exitErr, ok := err.(*exec.ExitError); ok {
			return "", fmt.Errorf("go list failed: %s", string(exitErr.Stderr))
		}
		return "", err
	}

	version := strings.TrimSpace(string(output))
	if version == "" {

View on GitHub (pinned to cd8cf15dc3)