{"record":{"id":"143b841f81ba423e","repo":"plandex-ai/plandex","slug":"auth-current-userid-is-empty-143b84","errorCode":null,"errorMessage":"auth.Current.UserId is empty","messagePattern":"auth\\.Current\\.UserId is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/models_sync.go","lineNumber":17,"sourceCode":"package lib\n\nimport (\n\t\"fmt\"\n\t\"plandex-cli/auth\"\n\t\"plandex-cli/term\"\n\n\t\"github.com/fatih/color\"\n)\n\nfunc PromptSyncModelsIfNeeded() error {\n\tvar changes []string\n\tvar onApprove []func() error\n\n\tuserId := auth.Current.UserId\n\tif userId == \"\" {\n\t\treturn fmt.Errorf(\"auth.Current.UserId is empty\")\n\t}\n\n\tcustomModelsPath := GetCustomModelsPath(userId)\n\n\tcustomModelsRes, err := CustomModelsCheckLocalChanges(customModelsPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error checking custom models: %v\", err)\n\t}\n\n\tif customModelsRes.HasLocalChanges {\n\t\tchanges = append(\n\t\t\tchanges,\n\t\t\tfmt.Sprintf(\"%s → %s\", color.New(term.ColorHiCyan, color.Bold).Sprint(\"Custom models\"), customModelsPath))\n\n\t\tonApprove = append(onApprove, SyncCustomModels)\n\t}\n\n\tdefaultModelSettingsRes, err := ModelSettingsCheckLocalChanges(DefaultModelSettingsPath)","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/models_sync.go#L1-L35","documentation":"PromptSyncModelsIfNeeded checks local model/config files for drift before a plan attempt. It requires an authenticated user and returns 'auth.Current.UserId is empty' when auth.Current has no UserId, i.e. the CLI is not logged in.","triggerScenarios":"Calling PromptSyncModelsIfNeeded (directly or via MustApplyPlanAttempt) before any `plandex auth` login, or after the stored auth state was cleared/corrupted so auth.Current.UserId is the empty string.","commonSituations":"Fresh machine or CI container without `plandex login`; auth cache deleted or overwritten; running commands in a different HOME so the auth file isn't found.","solutions":["Run `plandex login` / the auth flow to populate auth.Current.UserId","Verify the auth state file exists in the expected HomePlandexDir for the current HOME","In scripts/CI, add a login or auth-check step before plan commands"],"exampleFix":"// before\nerr := lib.MustApplyPlanAttempt(...)\n// after\nif lib/auth.Current.UserId == \"\" {\n\t// run login first\n}\nerr := lib.MustApplyPlanAttempt(...)","handlingStrategy":"type-guard","validationCode":"if auth.Current == nil || auth.Current.UserId == \"\" {\n\treturn fmt.Errorf(\"not authenticated: run plandex login before syncing models\")\n}","typeGuard":"func isLoggedIn() bool {\n\treturn auth.Current != nil && auth.Current.UserId != \"\"\n}","tryCatchPattern":"if err := lib.PromptSyncModelsIfNeeded(); err != nil {\n\tif strings.Contains(err.Error(), \"auth.Current.UserId is empty\") {\n\t\t// trigger interactive login flow, then retry\n\t}\n\treturn err\n}","preventionTips":["Always run the auth/login flow before plan commands in scripts","Check auth.Current.UserId early in your CLI entrypoint","In CI, provision auth state before invoking plan commands","Be aware HOME changes can hide the auth state file"],"tags":["go","auth","cli"],"backgroundTag":"not-authenticated","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}