{"record":{"id":"d509c058e3e5eed9","repo":"plandex-ai/plandex","slug":"no-current-plan-d509c0","errorCode":null,"errorMessage":"no current plan","messagePattern":"no current plan","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/plans.go","lineNumber":110,"sourceCode":"\t\treturn fmt.Errorf(\"error writing current plan: %v\", err)\n\t}\n\n\tCurrentPlanId = \"\"\n\n\treturn nil\n}\n\nfunc WriteCurrentBranch(branch 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\tif CurrentPlanId == \"\" {\n\t\treturn fmt.Errorf(\"no current plan\")\n\t}\n\n\tdir := filepath.Join(fs.HomePlandexDir, CurrentProjectId, CurrentPlanId)\n\n\terr := os.MkdirAll(dir, os.ModePerm)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating plan dir: %v\", err)\n\t}\n\n\tpath := filepath.Join(dir, \"settings-v2.json\")\n\n\tvar settingsByAccount *types.PlanSettingsByAccount\n\n\tbytes, err := os.ReadFile(path)\n\tif err == nil {\n\t\terr = json.Unmarshal(bytes, &settingsByAccount)\n\t\tif err != nil {","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/plans.go#L92-L128","documentation":"WriteCurrentBranch needs a plan id (CurrentPlanId) to locate the per-plan settings directory under ~/.plandex/<projectId>/<planId>. When the current-plan global is empty — no plan is checked out for this account — the branch cannot be attributed to any plan, so it returns 'no current plan'.","triggerScenarios":"Calling WriteCurrentBranch via checkout/new/MustLoadCurrentPlan when lib.CurrentPlanId == '' — i.e. ClearCurrentPlan was run, the plan context was never loaded, or current-plans-v2.json has no entry for auth.Current.UserId.","commonSituations":"Running 'plandex checkout <branch>' before ever selecting/creating a plan; switching accounts (settings are keyed by user id) so the new account has no current plan; a state file reset by upgrading CLI versions that moved from the old current-plan file to current-plans-v2.json.","solutions":["Create or select a plan first (plandex new <plan> or equivalent) so WriteCurrentPlan sets CurrentPlanId, then switch branches.","Re-select the current plan for the logged-in account so the settings file gains an entry for auth.Current.UserId.","In tests, set lib.CurrentPlanId to a valid plan id before calling WriteCurrentBranch."],"exampleFix":"// before\nlib.WriteCurrentBranch(\"feature\") // error: no current plan\n\n// after\nlib.WriteCurrentPlan(planId) // sets CurrentPlanId\nlib.WriteCurrentBranch(\"feature\")","handlingStrategy":"validation","validationCode":"if lib.CurrentPlanId == \"\" {\n    return fmt.Errorf(\"no plan selected; run `plandex new` first\")\n}\nerr := lib.WriteCurrentBranch(branch)","typeGuard":"func hasCurrentPlan() bool { return lib.CurrentPlanId != \"\" }","tryCatchPattern":null,"preventionTips":["Gate branch-switching commands behind a current-plan check in the command layer.","Remember settings are keyed by auth.Current.UserId — verify a current plan exists for the logged-in account.","After ClearCurrentPlan, avoid branch operations until a plan is selected again."],"tags":["go","cli","state","plan"],"backgroundTag":"current-context-missing","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"}