plandex-ai/plandex · error

error unmarshalling current-plans-v2.json: %v

Error message

error unmarshalling current-plans-v2.json: %v

What it means

WriteCurrentPlan reads the user's ~/.plandex/current-plans-v2.json cache to record which plan is currently checked out. If the file exists but cannot be parsed as JSON into types.CurrentPlanSettingsByAccount, the function aborts so it never overwrites a corrupt state file with new data. The wrapped %v carries the underlying json.Unmarshal detail (offset, type mismatch).

Source

Thrown at app/cli/lib/plans.go:29

	"sync"
)

func WriteCurrentPlan(id string) error {
	if fs.HomePlandexDir == "" {
		return fmt.Errorf("HomePlandexDir not set")
	}

	if CurrentProjectId == "" || HomeCurrentPlanPath == "" {
		return fmt.Errorf("no current project")
	}

	var currentPlanSettingsByAccount *types.CurrentPlanSettingsByAccount

	bytes, err := os.ReadFile(HomeCurrentPlanPath)
	if err == nil {
		err = json.Unmarshal(bytes, &currentPlanSettingsByAccount)
		if err != nil {
			return fmt.Errorf("error unmarshalling current-plans-v2.json: %v", err)
		}
	} else if !os.IsNotExist(err) {
		return fmt.Errorf("error checking if current-plans-v2.json exists: %v", err)
	}

	if currentPlanSettingsByAccount == nil {
		currentPlanSettingsByAccount = &types.CurrentPlanSettingsByAccount{}
	}

	settings := types.CurrentPlanSettings{
		Id: id,
	}

	(*currentPlanSettingsByAccount)[auth.Current.UserId] = &settings

	bytes, err = json.Marshal(currentPlanSettingsByAccount)
	if err != nil {
		return fmt.Errorf("error marshalling current plan: %v", err)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the file: cat ~/.plandex/current-plans-v2.json | python3 -m json.tool to confirm it is invalid JSON.
  2. Back it up and delete it (mv ~/.plandex/current-plans-v2.json ~/.plandex/current-plans-v2.json.bak); WriteCurrentPlan treats a missing file as a fresh empty state and recreates it.
  3. Fix the specific JSON defect reported by the wrapped %v (e.g. a truncated or hand-edited entry).
  4. If the schema changed across CLI versions, upgrade or re-run to let the current CLI rewrite the file.

Example fix

// before: corrupt file blocks everything
plandex cd
// error unmarshalling current-plans-v2.json: unexpected end of JSON input

// after: remove the corrupt cache so it is rebuilt
mv ~/.plandex/current-plans-v2.json ~/.plandex/current-plans-v2.json.bak
plandex cd
Defensive patterns

Strategy: try-catch

Validate before calling

f, err := os.Open(filepath.Join(os.Getenv("HOME"), ".plandex", "current-plans-v2.json"))
if err == nil {
	dec := json.NewDecoder(f)
	var probe types.CurrentPlanSettingsByAccount
	if err := dec.Decode(&probe); err != nil {
		// invalid JSON — quarantine before invoking the CLI
		os.Rename(path, path+".bak")
	}
	f.Close()
}

Type guard

func isValidPlansJSON(path string) bool {
	b, err := os.ReadFile(path)
	if err != nil { return false }
	var v types.CurrentPlanSettingsByAccount
	return json.Unmarshal(b, &v) == nil
}

Try / catch

if err := lib.WriteCurrentPlan(id); err != nil {
	if strings.Contains(err.Error(), "error unmarshalling current-plans-v2.json") {
		os.Rename(homePlansPath, homePlansPath+".bak") // reset state and retry once
		err = lib.WriteCurrentPlan(id)
	}
}

Prevention

When it happens

Trigger: os.ReadFile on HomeCurrentPlanPath succeeds (file exists), but json.Unmarshal into *types.CurrentPlanSettingsByAccount fails — i.e. malformed JSON, an incompatible schema from an older Plandex version (the file is 'v2'), or the file's top level is not a JSON object keyed by account id. Raised from the 'plandex cd' and 'plandex new' commands.

Common situations: A ~/.plandex directory synced/cloned from another machine; a crashed prior write left a truncated JSON file; the user hand-edited current-plans-v2.json and broke the syntax; downgrading the CLI so the v2 schema no longer parses.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/85dda575c2efa3f6. Report an issue: GitHub.