{"record":{"id":"a3e4e73911f489e6","repo":"plandex-ai/plandex","slug":"homeplandexdir-not-set","errorCode":null,"errorMessage":"HomePlandexDir not set","messagePattern":"HomePlandexDir not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/plans.go","lineNumber":16,"sourceCode":"package lib\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"plandex-cli/auth\"\n\t\"plandex-cli/fs\"\n\t\"plandex-cli/types\"\n\t\"sync\"\n)\n\nfunc WriteCurrentPlan(id string) error {\n\tif fs.HomePlandexDir == \"\" {\n\t\treturn fmt.Errorf(\"HomePlandexDir not set\")\n\t}\n\n\tif CurrentProjectId == \"\" || HomeCurrentPlanPath == \"\" {\n\t\treturn fmt.Errorf(\"no current project\")\n\t}\n\n\tvar currentPlanSettingsByAccount *types.CurrentPlanSettingsByAccount\n\n\tbytes, err := os.ReadFile(HomeCurrentPlanPath)\n\tif err == nil {\n\t\terr = json.Unmarshal(bytes, &currentPlanSettingsByAccount)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error unmarshalling current-plans-v2.json: %v\", err)\n\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"error checking if current-plans-v2.json exists: %v\", err)\n\t}\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/plans.go#L1-L34","documentation":"WriteCurrentPlan persists the current-plan pointer and returns 'HomePlandexDir not set' when the fs package's HomePlandexDir global is empty, meaning the Plandex home directory was never initialized for this process.","triggerScenarios":"Calling WriteCurrentPlan (via `cd` or `new`) before the CLI's fs initialization ran, or in an environment where the home directory resolution failed so fs.HomePlandexDir == \"\".","commonSituations":"HOME env var unset or empty (cron, CI, containers) so no ~/.plandex dir can be derived; calling library APIs without the CLI bootstrap; tests instantiating the package directly.","solutions":["Ensure HOME (or the equivalent) is set and writable so ~/.plandex can be created","Run the CLI's normal init/bootstrap path before calling WriteCurrentPlan","Run `plandex` once interactively to create HomePlandexDir, then retry","Check that no code path overwrites/resets fs.HomePlandexDir to empty"],"exampleFix":"// before\nHOME= plandex new myplan   # HomePlandexDir not set\n// after\nexport HOME=/home/user\nplandex new myplan","handlingStrategy":"validation","validationCode":"if os.Getenv(\"HOME\") == \"\" {\n\treturn fmt.Errorf(\"HOME must be set before using plandex\")\n}\nif err := os.MkdirAll(filepath.Join(os.Getenv(\"HOME\"), \".plandex\"), 0o755); err != nil {\n\treturn err\n}","typeGuard":"func plandexHomeReady() bool {\n\treturn fs.HomePlandexDir != \"\"\n}","tryCatchPattern":"if err := lib.WriteCurrentPlan(id); err != nil {\n\tif err.Error() == \"HomePlandexDir not set\" {\n\t\t// run CLI bootstrap/init, then retry\n\t}\n\treturn err\n}","preventionTips":["Always set HOME (or the plandex home env var) in CI/containers","Use the CLI's normal entrypoint so fs initialization runs","Create ~/.plandex with correct permissions before first run","Avoid calling lib functions without the bootstrap step in tests"],"tags":["go","config","env","initialization"],"backgroundTag":"missing-env-var","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"}