{"record":{"id":"88c33573b6955895","repo":"plandex-ai/plandex","slug":"error-selecting-account-account-not-found","errorCode":null,"errorMessage":"error selecting account: account not found","messagePattern":"error selecting account: account not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/account.go","lineNumber":62,"sourceCode":"\n\tif selectedOpt == AddAccountOption {\n\t\terr := promptSignInNewAccount()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error prompting for sign in to new account: %v\", err)\n\t\t}\n\t\treturn nil\n\t}\n\n\tvar selected *shared.ClientAccount\n\tfor i, opt := range options {\n\t\tif selectedOpt == opt {\n\t\t\tselected = accounts[i]\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif selected == nil {\n\t\treturn fmt.Errorf(\"error selecting account: account not found\")\n\t}\n\n\tselectedAuth := *selected\n\n\tsetAuth(&shared.ClientAuth{\n\t\tClientAccount: selectedAuth,\n\t})\n\n\tterm.StartSpinner(\"\")\n\torgs, apiErr := apiClient.ListOrgs()\n\tterm.StopSpinner()\n\n\tif apiErr != nil {\n\t\treturn fmt.Errorf(\"error listing orgs: %v\", apiErr.Msg)\n\t}\n\n\torg, err := resolveOrgAuth(orgs, selectedAuth.IsLocalMode)\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/account.go#L44-L80","documentation":"SelectOrSignInOrCreate lists saved Plandex accounts and lets the user pick one interactively. After the user selects an option, the code maps the selected list entry back to its account by index. This error is thrown when no entry in the options list matches the string the user selected, so `selected` remains nil — meaning the account pointed to by the choice could not be found among the loaded accounts.","triggerScenarios":"The selected option string does not equal any generated `<UserName> <Email>` option (e.g. the accounts file changed between listing and selection, or options/accounts slices are out of sync because options includes the extra `Add another account` entry whose index maps past the accounts slice but that branch returns early).","commonSituations":"A stale or hand-edited accounts store on disk so rendered labels no longer match; running multiple Plandex CLI versions where the option label format changed; concurrent modification of ~/.plandex accounts while the picker is open.","solutions":["Re-run the command; if it persists, sign in fresh by choosing the 'Add another account' option so accounts are rebuilt from scratch.","Delete the local accounts file (e.g. under ~/.plandex) and re-authenticate to regenerate consistent account entries.","If developing, verify the loop at app/cli/auth/account.go:54 maps indices over `accounts` (not `options`) and that option labels are generated from the same slice order."],"exampleFix":"// before\nselected = accounts[i] // options index used directly; mismatch leaves selected nil\n// after\naccountsIdx := i // options includes trailing 'Add another account', accounts does not\nif accountsIdx < len(accounts) {\n    selected = accounts[accountsIdx]\n}","handlingStrategy":"validation","validationCode":"opts := buildOptions(accounts) // generate labels and accounts from the same slice\nidx := indexOf(opts, selectedOpt)\nif idx < 0 || idx >= len(accounts) {\n    return fmt.Errorf(\"unknown account option %q; re-run sign-in\", selectedOpt)\n}","typeGuard":"func accountForOption(opts []string, accounts []shared.ClientAccount, sel string) (*shared.ClientAccount, bool) {\n    for i, o := range opts {\n        if o == sel && i < len(accounts) {\n            return &accounts[i], true\n        }\n    }\n    return nil, false\n}","tryCatchPattern":"if err := auth.SelectOrSignInOrCreate(); err != nil {\n    if strings.Contains(err.Error(), \"account not found\") {\n        // clear stale account store and re-authenticate\n        os.RemoveAll(accountsPath())\n        return auth.SelectOrSignInOrCreate()\n    }\n    return err\n}","preventionTips":["Always generate option labels and the account list from the same slice so indices stay in sync.","Include a stable key (account ID) in options rather than relying on display strings.","Re-authenticate via 'Add another account' if the account picker ever shows stale entries."],"tags":["cli","auth","account-selection"],"backgroundTag":"account-not-found","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}