plandex-ai/plandex · error

error checking if current-plans-v2.json exists: %v

Error message

error checking if current-plans-v2.json exists: %v

What it means

WriteCurrentPlan attempts to read ~/.plandex/current-plans-v2.json; a missing file is tolerated, but any other read error (permissions, I/O failure) is a hard error because the function cannot know the current-plan state. This error wraps the raw os.ReadFile failure.

Source

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

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)
	}

	err = os.WriteFile(HomeCurrentPlanPath, bytes, 0644)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check permissions: ls -l ~/.plandex/current-plans-v2.json and chown/chmod it back to your user (chmod u+r).
  2. Check what the path actually is (file vs directory vs broken symlink): file ~/.plandex/current-plans-v2.json.
  3. If it was created by root/sudo, chown $(whoami) ~/.plandex/current-plans-v2.json or move it aside.
  4. Verify HOME is correct and points at your own ~/.plandex directory.

Example fix

// before: file owned by root, unreadable
sudo plandex new
// error checking if current-plans-v2.json exists: open ...: permission denied

// after: restore ownership to the invoking user
sudo chown $(whoami) ~/.plandex/current-plans-v2.json
plandex new
Defensive patterns

Strategy: validation

Validate before calling

path := filepath.Join(os.Getenv("HOME"), ".plandex", "current-plans-v2.json")
if fi, err := os.Stat(path); err == nil && fi.IsDir() {
	return fmt.Errorf("%s is a directory; remove it first", path)
}
if f, err := os.Open(path); err == nil { f.Close() } else if !errors.Is(err, fs.ErrNotExist) {
	return fmt.Errorf("state file unreadable (%v); fix permissions before running plandex", err)
}

Type guard

func stateFileReadable(path string) bool {
	f, err := os.Open(path)
	if err != nil { return os.IsNotExist(err) } // missing is OK
	f.Close()
	return true
}

Try / catch

if err := lib.WriteCurrentPlan(id); err != nil {
	if strings.Contains(err.Error(), "error checking if current-plans-v2.json exists") {
		// surface a permission fix hint or run with corrected ownership
	}
}

Prevention

When it happens

Trigger: os.ReadFile(HomeCurrentPlanPath) returns an error that is not os.ErrNotExist — e.g. EACCES on the file, EISDIR (the path is a directory), or a device I/O error. Triggered via 'plandex cd' or 'plandex new'.

Common situations: current-plans-v2.json exists but is unreadable after running as a different user (root-created file); the path was replaced by a directory; a broken symlink pointing to an inaccessible target; read-only or failing filesystem.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


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