{"record":{"id":"1138081c9723f742","repo":"plandex-ai/plandex","slug":"error-reading-accounts-json-v","errorCode":null,"errorMessage":"error reading accounts.json: %v","messagePattern":"error reading accounts\\.json: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/state.go","lineNumber":22,"sourceCode":"\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"plandex-cli/fs\"\n\n\tshared \"plandex-shared\"\n)\n\nvar Current *shared.ClientAuth\n\nfunc loadAccounts() ([]*shared.ClientAccount, error) {\n\tbytes, err := os.ReadFile(fs.HomeAccountsPath)\n\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\t// no accounts\n\t\t\treturn []*shared.ClientAccount{}, nil\n\t\t} else {\n\t\t\treturn nil, fmt.Errorf(\"error reading accounts.json: %v\", err)\n\t\t}\n\t}\n\n\tvar accounts []*shared.ClientAccount\n\terr = json.Unmarshal(bytes, &accounts)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error unmarshalling accounts.json: %v\", err)\n\t}\n\n\treturn accounts, nil\n}\n\nfunc setAuth(auth *shared.ClientAuth) error {\n\terr := storeAccount(&auth.ClientAccount)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error storing account: %v\", err)","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/state.go#L4-L40","documentation":"loadAccounts reads the CLI's accounts store at fs.HomeAccountsPath (~/.plandex/accounts.json). A missing file is handled gracefully (empty list), but any other read error — permission denied, path is a directory, I/O failure — is wrapped in this error and blocks sign-in and account storage.","triggerScenarios":"os.ReadFile(fs.HomeAccountsPath) fails with an error that is not os.IsNotExist — e.g. accounts.json exists but is unreadable due to permissions, or the path is a directory, or a disk I/O error occurs.","commonSituations":"~/.plandex owned by root after running with sudo; accounts.json replaced by a directory or symlink to an unreadable location; read-only or failing filesystem; overly restrictive file mode from a prior run (os.ModePerm writes).","solutions":["Check permissions on ~/.plandex/accounts.json (ls -la) and fix with chown/chmod","If the path is a directory or corrupt symlink, remove/replace it","Verify HOME is set correctly and points to a writable directory","Check disk health / free space if I/O errors persist"],"exampleFix":"// before\n$ sudo plandex-cli sign-in   # accounts.json now root-owned\nerror reading accounts.json: open ...: permission denied\n// after\n$ sudo chown -R $USER ~/.plandex\n$ plandex-cli sign-in","handlingStrategy":"validation","validationCode":"// check the accounts file is readable before auth flows\npath := fs.HomeAccountsPath\nif info, err := os.Stat(path); err == nil && info.IsDir() {\n    return fmt.Errorf(\"%s is a directory; remove it\", path)\n}\nf, err := os.OpenFile(path, os.O_RDONLY, 0)\nif err != nil && !os.IsNotExist(err) {\n    return fmt.Errorf(\"accounts.json unreadable: %v\", err)\n}\nf.Close()","typeGuard":"func accountsReadable(path string) bool {\n    f, err := os.Open(path)\n    if err != nil {\n        return os.IsNotExist(err)\n    }\n    f.Close()\n    return true\n}","tryCatchPattern":"accounts, err := loadAccounts()\nif err != nil {\n    if strings.Contains(err.Error(), \"error reading accounts.json\") {\n        // check/fix ~/.plandex permissions, then retry\n    }\n    return err\n}","preventionTips":["Never run the CLI under sudo (avoids root-owned ~/.plandex)","Keep HOME set to your writable user directory","Don't replace accounts.json with directories or odd symlinks","Watch disk health; read errors can indicate failing storage"],"tags":["filesystem","permissions","accounts-json"],"backgroundTag":"file-permission-denied","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"}