plandex-ai/plandex · error

error creating directory: %v

Error message

error creating directory: %v

What it means

WriteModelSettingsFile persists a plan's current model pack to model-settings.json. Before writing it calls os.MkdirAll on the parent directory (e.g. ~/.plandex/<planId>) and wraps any failure as 'error creating directory: %v'. The cause is the wrapped OS error, typically a permissions or path problem.

Source

Thrown at app/cli/lib/model_settings.go:76

	}

	currentHash, err := clientModelPackSchemaRoles.ToModelPackSchemaRoles().Hash()
	if err != nil {
		return ModelSettingsCheckLocalChangesResult{}, fmt.Errorf("error hashing model pack: %v", err)
	}

	modelPackSchemaRoles := clientModelPackSchemaRoles.ToModelPackSchemaRoles()

	return ModelSettingsCheckLocalChangesResult{
		HasLocalChanges:           currentHash != string(lastSavedHash),
		LocalModelPackSchemaRoles: &modelPackSchemaRoles,
	}, nil
}

func WriteModelSettingsFile(path string, originalSettings *shared.PlanSettings) error {
	err := os.MkdirAll(filepath.Dir(path), 0755)
	if err != nil {
		return fmt.Errorf("error creating directory: %v", err)
	}

	modelPackSchemaRoles := originalSettings.GetModelPack().ToModelPackSchema().ModelPackSchemaRoles

	clientModelPackRoles := modelPackSchemaRoles.ToClientModelPackSchemaRoles()

	bytes, err := json.MarshalIndent(clientModelPackRoles, "", "  ")
	if err != nil {
		return fmt.Errorf("error marshalling model pack: %v", err)
	}

	err = os.WriteFile(path, bytes, 0644)
	if err != nil {
		return fmt.Errorf("error writing JSON file: %v", err)
	}

	err = SaveModelPackRolesHash(path, &modelPackSchemaRoles)
	if err != nil {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped OS error (e.g. permission denied) and fix directory permissions: chmod/chown ~/.plandex or run with proper privileges
  2. Verify HOME is set to a writable directory; override PLandex home if the fs package supports it
  3. If a regular file exists at the target directory path, remove or rename it
  4. Free disk space if the error is no-space-left-on-device

Example fix

// before
mkdir: cannot create directory '/home/ci/.plandex/xyz': Permission denied
// after
export HOME=/writable/dir
chmod u+w "$HOME" && mkdir -p "$HOME/.plandex"
Defensive patterns

Strategy: validation

Validate before calling

dir := filepath.Dir(path)
if info, err := os.Stat(dir); err != nil {
    if os.IsNotExist(err) {
        if err := os.MkdirAll(dir, 0o755); err != nil { return err }
    } else { return err }
} else if !info.IsDir() {
    return fmt.Errorf("%s is a file, not a directory", dir)
}

Try / catch

if err := lib.WriteModelSettingsFile(path, settings); err != nil {
    if strings.Contains(err.Error(), "error creating directory") {
        // check HOME writability/permissions, then retry
    }
    return err
}

Prevention

When it happens

Trigger: Calling WriteModelSettingsFile (directly or via updateModelSettings / SaveLatestPlanModelSettingsIfNeeded) when the parent directory cannot be created: read-only HOME, HOME unset so fs.HomePlandexDir resolves to an invalid path, disk full, or a file already exists where the directory should be.

Common situations: Running the CLI in containers/CI with a read-only or missing $HOME; restricted sandbox permissions; a stray file named like the plan directory under ~/.plandex; SELinux/AppArmor blocking writes.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


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