{"record":{"id":"1c7159625b85f437","repo":"plandex-ai/plandex","slug":"error-setting-auth-header-auth-not-loaded","errorCode":null,"errorMessage":"error setting auth header: auth not loaded","messagePattern":"error setting auth header: auth not loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/api.go","lineNumber":22,"sourceCode":"\t\"encoding/base64\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"plandex-cli/types\"\n\t\"plandex-cli/version\"\n\n\tshared \"plandex-shared\"\n)\n\nvar apiClient types.ApiClient\n\nfunc SetApiClient(client types.ApiClient) {\n\tapiClient = client\n}\n\nfunc SetAuthHeader(req *http.Request) error {\n\tif Current == nil {\n\t\treturn fmt.Errorf(\"error setting auth header: auth not loaded\")\n\t}\n\thash := Current.ToHash()\n\n\tauthHeader := shared.AuthHeader{\n\t\tToken: Current.Token,\n\t\tOrgId: Current.OrgId,\n\t\tHash:  hash,\n\t}\n\n\tbytes, err := json.Marshal(authHeader)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling auth header: %v\", err)\n\t}\n\n\t// base64 encode\n\ttoken := base64.URLEncoding.EncodeToString(bytes)\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/api.go#L4-L40","documentation":"SetAuthHeader attaches a base64-encoded JSON auth header (token, org id, hash) to an outgoing HTTP request. It returns this error when the package-level `Current` *shared.ClientAuth is nil, i.e. no auth was ever loaded (MustResolveAuth never ran or auth.json is missing/failed to load). It is a fail-fast guard against sending unauthenticated requests.","triggerScenarios":"RoundTrip invokes SetAuthHeader before any call to auth.MustResolveAuth/initial sign-in has populated `Current`; auth.json does not exist at fs.HomeAuthPath; or a previous unmarshal failure left Current nil.","commonSituations":"Users running the CLI before `plandex sign in`; a wiped or unreadable HOME directory so auth.json is missing; a corrupted auth.json that failed to unmarshal earlier in the startup path; embedding code that calls the API client directly without initializing auth.","solutions":["Run the CLI's sign-in flow (e.g. `plandex sign in`) so auth.json is created and `Current` is set","Ensure auth.MustResolveAuth (or equivalent initialization) is called before any API request","Check that fs.HomeAuthPath exists and is readable (correct HOME, permissions)","If embedding the client, call auth.SetApiClient and complete auth resolution before issuing requests"],"exampleFix":"// before\nclient.Do(req) // -> error setting auth header: auth not loaded\n// after\nif auth.Current == nil {\n\tterm.OutputErrorAndExit(\"Not signed in — run `plandex sign in` first\")\n}\nclient.Do(req)","handlingStrategy":"validation","validationCode":"if auth.Current == nil {\n\treturn fmt.Errorf(\"not signed in: run `plandex sign in` before issuing API requests\")\n}","typeGuard":"func authLoaded() bool { return auth.Current != nil }","tryCatchPattern":"if err := auth.SetAuthHeader(req); err != nil {\n\tif strings.Contains(err.Error(), \"auth not loaded\") {\n\t\t// fall back to interactive sign-in then retry\n\t\tauth.MustResolveAuth(true)\n\t\treturn auth.SetAuthHeader(req)\n\t}\n\treturn err\n}","preventionTips":["Always run the sign-in flow before the first API call","Check auth.json exists at fs.HomeAuthPath during startup","Call auth.MustResolveAuth once at CLI entry, not lazily","When embedding, call auth.SetApiClient and complete auth resolution first"],"tags":["auth","http","initialization"],"backgroundTag":"auth-not-loaded","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"}