plandex-ai/plandex · error
error refreshing token: auth not loaded
Error message
error refreshing token: auth not loaded
What it means
RefreshInvalidToken re-verifies the user's email and re-signs-in to obtain a fresh token after an invalid/expired token response. It guards with `if Current == nil` because refreshing requires the stored email/host. Without loaded auth there is nothing to refresh, so it returns this error immediately.
Source
Thrown at app/cli/auth/auth.go:92
// still no org--exit now
term.OutputErrorAndExit("No org")
}
Current.OrgId = org.Id
Current.OrgName = org.Name
Current.IntegratedModelsMode = org.IntegratedModelsMode
err = writeCurrentAuth()
if err != nil {
term.OutputErrorAndExit("Error writing auth: %v", err)
}
}
}
func RefreshInvalidToken() error {
if Current == nil {
return fmt.Errorf("error refreshing token: auth not loaded")
}
res, err := verifyEmail(Current.Email, Current.Host)
if err != nil {
return fmt.Errorf("error verifying email: %v", err)
}
if res.hasAccount {
return signIn(Current.Email, res.pin, Current.Host)
} else {
host := Current.Host
if host == "" {
host = "Plandex Cloud"
}
term.OutputErrorAndExit("Account %s not found on %s", Current.Email, host)
}
View on GitHub (pinned to e2d772072e)
Solutions
- Ensure auth.MustResolveAuth ran before any request that can trigger refreshAuthIfNeeded
- Re-run sign-in to recreate auth.json and load Current
- Check disk state: fs.HomeAuthPath should exist and parse as shared.ClientAuth
- Fix initialization order in custom code so refresh is never called before auth load
Example fix
// before
err := auth.RefreshInvalidToken() // error refreshing token: auth not loaded
// after
if auth.Current == nil {
auth.MustResolveAuth(false)
}
err := auth.RefreshInvalidToken() Defensive patterns
Strategy: validation
Validate before calling
if auth.Current == nil {
return fmt.Errorf("cannot refresh token: no auth loaded; run sign-in first")
} Type guard
func canRefresh() bool { return auth.Current != nil && auth.Current.Email != "" } Try / catch
err := auth.RefreshInvalidToken()
if err != nil {
if strings.Contains(err.Error(), "auth not loaded") {
auth.MustResolveAuth(false)
err = auth.RefreshInvalidToken()
}
if err != nil { term.OutputErrorAndExit("%v", err) }
} Prevention
- Ensure auth load (MustResolveAuth) always precedes refresh logic
- Don't delete auth.json while the CLI is running
- In tests/embedding, stub or skip refresh when auth is intentionally unset
- Keep email/host populated in auth.json
When it happens
Trigger: refreshAuthIfNeeded calls RefreshInvalidToken after an API round trip reports an invalid token, but `Current` was never set (auth.json missing, load failed, or refresh path invoked before MustResolveAuth).
Common situations: Race or ordering bug where token refresh runs before auth load; auth.json deleted while the CLI is running; testing/embedding that calls refresh APIs directly without sign-in.
Related errors
- error refreshing auth: auth not loaded
- error decoding auth token: %v
- error parsing auth token: %v
- error loading accounts: %v
- error signing in to new account: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/ec89ec7bbb9c09ac.
Report an issue: GitHub.