{"record":{"id":"ec76618722ce478a","repo":"plandex-ai/plandex","slug":"error-writing-auth-v-ec7661","errorCode":null,"errorMessage":"error writing auth: %v","messagePattern":"error writing auth: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/state.go","lineNumber":48,"sourceCode":"\t\treturn nil, fmt.Errorf(\"error unmarshalling accounts.json: %v\", err)\n\t}\n\n\treturn accounts, nil\n}\n\nfunc setAuth(auth *shared.ClientAuth) error {\n\terr := storeAccount(&auth.ClientAccount)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error storing account: %v\", err)\n\t}\n\n\tCurrent = auth\n\n\terr = writeCurrentAuth()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing auth: %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc storeAccount(toStore *shared.ClientAccount) error {\n\taccounts, err := loadAccounts()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error loading accounts: %v\", err)\n\t}\n\n\tfound := false\n\tfor i, account := range accounts {\n\t\tif account.UserId == toStore.UserId {\n\t\t\taccounts[i] = toStore\n\t\t\tfound = true\n\t\t\tbreak","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/state.go#L30-L66","documentation":"After storing the account, setAuth writes the full current auth (token etc.) to fs.HomeAuthPath via writeCurrentAuth, wrapping any failure in this error. The account was saved but the session auth file could not be written, so sign-in is not persisted. Note writeCurrentAuth also emits this prefix for \"auth not loaded\" and marshal failures.","triggerScenarios":"setAuth calls writeCurrentAuth after setting Current; os.WriteFile(fs.HomeAuthPath, ...) fails — permission denied, read-only filesystem, disk full — or (rarely) marshal of Current fails.","commonSituations":"~/.plandex/auth.json root-owned after sudo usage; read-only HOME (containers, immutable images); disk full; HOME unset or pointing somewhere unwritable.","solutions":["Fix ownership/permissions on ~/.plandex and the auth file (chown/chmod)","Ensure HOME is set to a writable directory","Free disk space if ENOSPC","Sign in again once the filesystem issue is resolved"],"exampleFix":"// before\nerror writing auth: open ~/.plandex/auth.json: read-only file system\n// after\n$ export HOME=/home/user   # point HOME at a writable dir\n$ plandex-cli sign-in","handlingStrategy":"try-catch","validationCode":"// confirm the auth file location is writable before sign-in\nif err := os.WriteFile(fs.HomeAuthPath+\".wtest\", []byte(\"\"), 0o600); err != nil {\n    return fmt.Errorf(\"auth file not writable: %v\", err)\n}\nos.Remove(fs.HomeAuthPath + \".wtest\")","typeGuard":null,"tryCatchPattern":"if err := setAuth(auth); err != nil {\n    if strings.Contains(err.Error(), \"error writing auth\") {\n        // fix ~/.plandex permissions / HOME / disk, then sign in again\n    }\n    return err\n}","preventionTips":["Ensure HOME points to a writable directory (watch containers/read-only images)","Avoid sudo runs that root-own auth.json","Keep disk space available for token refreshes","Re-authenticate promptly if sign-in persistence failed"],"tags":["filesystem","auth-persistence","write-failure"],"backgroundTag":"file-write-failed","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"}