plandex-ai/plandex · error

error loading accounts: %v

Error message

error loading accounts: %v

What it means

storeAccount begins by loading existing accounts via loadAccounts and wraps any load failure in this error. This nests the underlying cause — either "error reading accounts.json" (unreadable file) or "error unmarshalling accounts.json" (corrupt JSON) — so the full chain appears in the message.

Source

Thrown at app/cli/auth/state.go:58

		return fmt.Errorf("error storing account: %v", err)
	}

	Current = auth

	err = writeCurrentAuth()

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

	return nil
}

func storeAccount(toStore *shared.ClientAccount) error {
	accounts, err := loadAccounts()

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

	found := false
	for i, account := range accounts {
		if account.UserId == toStore.UserId {
			accounts[i] = toStore
			found = true
			break
		}
	}

	if !found {
		accounts = append(accounts, toStore)
	}

	bytes, err := json.Marshal(accounts)

	if err != nil {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the nested cause: fix file permissions for read errors, or repair/delete the file for unmarshal errors
  2. Back up and remove ~/.plandex/accounts.json so it is recreated on next sign-in
  3. Validate the JSON (jq . accounts.json) if you want to preserve existing accounts
  4. Avoid running the CLI as root/sudo to prevent ownership mismatches

Example fix

// before
error storing account: error loading accounts: error unmarshalling accounts.json: invalid character 'x'
// after
$ mv ~/.plandex/accounts.json ~/.plandex/accounts.json.bak
$ plandex-cli sign-in   # recreates a valid store
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check the store loads cleanly before account writes
if b, err := os.ReadFile(fs.HomeAccountsPath); err == nil {
    var accounts []*shared.ClientAccount
    if err := json.Unmarshal(b, &accounts); err != nil {
        return fmt.Errorf("repair accounts.json before storing: %v", err)
    }
}

Try / catch

if err := setAuth(auth); err != nil {
    if strings.Contains(err.Error(), "error loading accounts") {
        // nested cause says read vs unmarshal: fix permissions or back up & delete the file
    }
    return err
}

Prevention

When it happens

Trigger: setAuth → storeAccount → loadAccounts; os.ReadFile on fs.HomeAccountsPath fails with a non-NotExist error, or the file's JSON fails to unmarshal into []*shared.ClientAccount.

Common situations: Corrupt or hand-edited accounts.json; permission problems on ~/.plandex (e.g. root-owned after sudo); truncated file from a previous crashed write; schema mismatch after a CLI version change.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


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