github/copilot-sdk · error

failed to get SDK version

Error message

failed to get SDK version: %w

What it means

detectCLIVersion resolves the pinned Copilot CLI version by first reading the copilot-sdk module version from go.mod via getSDKVersion. If that sub-step fails, the error is wrapped as 'failed to get SDK version'. The SDK version is the prerequisite for fetching the CLI version from the SDK repo.

Solutions

  1. Run `go mod tidy` to add/repair the copilot-sdk requirement in go.mod
  2. Run `go get copilot-sdk@latest` (or the desired version) then retry the bundler
  3. Inspect the wrapped cause (%w) for the underlying `go list` failure and fix it
  4. Ensure you run the bundler from within the Go module that depends on copilot-sdk

Example fix

// before: bundler fails: failed to get SDK version ...
// after:
// $ go get github.com/github/copilot-sdk@latest
// $ go mod tidy
// $ bundler ./cmd/app
Defensive patterns

Strategy: retry

Validate before calling

out, err := exec.Command("go", "list", "-m", "-f", "{{.Version}}", "github.com/github/copilot-sdk").Output()
if err != nil || len(bytes.TrimSpace(out)) == 0 {
    return errors.New("copilot-sdk not resolvable; run go mod tidy")
}

Try / catch

if _, err := resolveCLIVersion(); err != nil {
    if strings.Contains(err.Error(), "failed to get SDK version") {
        exec.Command("go", "mod", "tidy").Run() // repair module state, then retry
    }
}

Prevention

When it happens

Trigger: Running the bundler in a project where `go list -m -f {{.Version}} github.com/.../copilot-sdk` fails: the module is absent from go.mod, the module cache/sum is inconsistent, or go cannot resolve the module.

Common situations: Forgetting to `go get` / `go mod tidy` the copilot-sdk dependency; working in a module outside the one that requires copilot-sdk; GOFLAGS/proxy issues breaking module resolution.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

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

			return defaultPackageName, fmt.Errorf("multiple packages %q and %q found in %q", packageName, file.Name.Name, dir)
		}
	}

	if packageName == "" {
		return defaultPackageName, fmt.Errorf("no Go package found in %q", dir)
	}
	return packageName, nil
}

// 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 {

View on GitHub (pinned to cd8cf15dc3)