plandex-ai/plandex · error

error selecting org: %v

Error message

error selecting org: %v

What it means

When the account belongs to more than one org, resolveOrgAuth runs selectOrg, an interactive picker over the org list. Any failure from selectOrg is wrapped as this error. It means the user's org could not be determined because selection failed.

Source

Thrown at app/cli/auth/org.go:32

	if len(orgs) == 0 {
		if isLocalMode {
			org, err = createOrg(isLocalMode)
		} else {
			org, err = promptNoOrgs()
		}

		if err != nil {
			return nil, fmt.Errorf("error prompting no orgs: %v", err)
		}

	} else if len(orgs) == 1 {
		org = orgs[0]
	} else {
		org, err = selectOrg(orgs, isLocalMode)

		if err != nil {
			return nil, fmt.Errorf("error selecting org: %v", err)
		}
	}

	return org, nil
}

func promptNoOrgs() (*shared.Org, error) {
	fmt.Println("🧐 You don't have access to any orgs yet.\n\nTo join an existing org, ask an admin to either invite you directly or give your whole email domain access.\n\nOtherwise, you can go ahead and create a new org.")

	shouldCreate, err := term.ConfirmYesNo("Create a new org now?")

	if err != nil {
		return nil, fmt.Errorf("error prompting create org: %v", err)
	}

	if shouldCreate {
		return createOrg(false)
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Run interactively and complete the org picker once; the choice is persisted to auth.json
  2. Reduce ambiguity: leave/remove extra orgs, or ensure only one org membership if automation is needed
  3. Check the wrapped inner error — if it's an API error, verify the selected org still exists and you have access
  4. For CI, pre-select the org by running the picker manually before headless runs

Example fix

// before
CI run with 2 orgs -> selectOrg EOF -> error selecting org
// after
# locally: plandex command, choose org (persisted in auth.json)
# then rerun the command in CI with the same HOME
Defensive patterns

Strategy: validation

Validate before calling

orgs, err := apiClient.ListOrgs()
if err == nil && len(orgs) > 1 && !term.IsTerminal(os.Stdin.Fd()) {
	return fmt.Errorf("multiple orgs require interactive selection; select an org first in a TTY")
}

Type guard

func needsInteractiveSelection(orgs []*shared.Org) bool { return len(orgs) > 1 && !term.IsTerminal(os.Stdin.Fd()) }

Try / catch

org, err := resolveOrgAuth(orgs, isLocalMode)
if err != nil {
	if strings.Contains(err.Error(), "selecting org") {
		fmt.Fprintln(os.Stderr, "Org selection failed; run once interactively to choose and persist an org.", err)
		os.Exit(1)
	}
	return err
}

Prevention

When it happens

Trigger: len(orgs) > 1 and selectOrg fails — the interactive selection prompt errors (non-TTY stdin/EOF, interrupted input) or the org selection API call inside selectOrg returns an ApiError.

Common situations: Multi-org user running the CLI in CI/non-interactive environments; Ctrl-C or piped stdin during the picker; server error while setting the chosen org as current; stale org list with a deleted org chosen.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/c5314c717d5582ac. Report an issue: GitHub.