plandex-ai/plandex · error
error refreshing auth: auth not loaded
Error message
error refreshing auth: auth not loaded
What it means
RefreshAuth reloads the current org session and updates stored org metadata. It guards with `if Current == nil` because refresh requires the loaded auth context. If auth was never loaded (auth.json missing or load failed) it returns this error.
Source
Thrown at app/cli/auth/auth.go:116
}
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)
}
return nil
}
func RefreshAuth() error {
if Current == nil {
return fmt.Errorf("error refreshing auth: auth not loaded")
}
org, apiErr := apiClient.GetOrgSession()
if apiErr != nil {
return fmt.Errorf("error getting org session: %v", apiErr.Msg)
}
Current.OrgName = org.Name
Current.OrgIsTrial = org.IsTrial
Current.IntegratedModelsMode = org.IntegratedModelsMode
err := writeCurrentAuth()
if err != nil {
return fmt.Errorf("error writing auth: %v", err)
}
View on GitHub (pinned to e2d772072e)
Solutions
- Ensure auth.MustResolveAuth completes before requests that can trigger refreshAuthIfNeeded
- Re-run sign-in to recreate auth.json and set Current
- Verify fs.HomeAuthPath exists, is readable, and unmarshals into shared.ClientAuth
Example fix
// before
org, apiErr := apiClient.GetOrgSession() // via RefreshAuth: auth not loaded
// after
if auth.Current == nil {
auth.MustResolveAuth(true)
}
org, apiErr := apiClient.GetOrgSession() Defensive patterns
Strategy: validation
Validate before calling
if auth.Current == nil {
return fmt.Errorf("cannot refresh auth: run sign-in first")
} Type guard
func hasAuth() bool { return auth.Current != nil && auth.Current.OrgId != "" } Try / catch
if err := auth.RefreshAuth(); err != nil {
if strings.Contains(err.Error(), "auth not loaded") {
auth.MustResolveAuth(true)
} else {
term.OutputErrorAndExit("%v", err)
}
} Prevention
- Initialize auth at CLI startup before any request
- Don't remove or corrupt auth.json mid-session
- Guard embedded refresh calls with a Current != nil check
- Log auth load failures so Current==nil states are caught early
When it happens
Trigger: refreshAuthIfNeeded calls RefreshAuth after a request, but `Current` is nil — MustResolveAuth never ran, auth.json was deleted, or an earlier unmarshal failure left Current unset.
Common situations: Auth file removed while CLI is running; invoking refresh logic from embedded/tests without sign-in; ordering bug in custom startup code.
Related errors
- error getting org session: %v
- error refreshing token: auth not loaded
- auth.Current.UserId is empty
- no authenticated user
- no token
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/6887deec7837e7c9.
Report an issue: GitHub.