plandex-ai/plandex · error

error writing auth: %v

Error message

error writing auth: %v

What it means

After a successful GetOrgSession refresh, RefreshAuth persists the updated auth via writeCurrentAuth (writes auth.json under fs.HomeAuthPath). If persisting fails (I/O error) it is wrapped as this error. The refresh succeeded remotely but could not be saved locally.

Source

Thrown at app/cli/auth/auth.go:132

func RefreshAuth() error {
	if Current == nil {
		return fmt.Errorf("error refreshing auth: auth not loaded")
	}

	org, apiErr := apiClient.GetOrgSession()

	if apiErr != nil {
		return fmt.Errorf("error getting org session: %v", apiErr.Msg)
	}

	Current.OrgName = org.Name
	Current.OrgIsTrial = org.IsTrial
	Current.IntegratedModelsMode = org.IntegratedModelsMode

	err := writeCurrentAuth()

	if err != nil {
		return fmt.Errorf("error writing auth: %v", err)
	}

	return nil
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check disk space (df -h) and free space or quotas
  2. Verify permissions/ownership of HOME and the auth file path (ls -la ~/.plandex-auth*)
  3. Ensure HOME points to a writable directory when running in containers/CI
  4. Inspect the wrapped inner error (%v) — it names the exact OS-level cause

Example fix

// before
export HOME=/ro-fs/home # read-only mount
// after
export HOME=/home/user && plandex sign in
Defensive patterns

Strategy: validation

Validate before calling

if info, err := os.Stat(filepath.Dir(fs.HomeAuthPath)); err != nil || !info.IsDir() {
	return fmt.Errorf("auth dir missing or unwritable: %v", err)
}
if err := unix.Access(fs.HomeAuthPath, unix.W_OK); err != nil {
	return fmt.Errorf("auth file not writable: %v", err)
}

Type guard

func authWritable() bool {
	f, err := os.OpenFile(fs.HomeAuthPath, os.O_WRONLY|os.O_CREATE, 0600)
	if err != nil { return false }
	f.Close()
	return true
}

Try / catch

if _, err := auth.RefreshAuth(); err != nil {
	if strings.Contains(err.Error(), "writing auth") {
		// check disk/permissions, then retry once
		fmt.Fprintln(os.Stderr, "check disk space and HOME permissions:", err)
		_, err = auth.RefreshAuth()
	}
	if err != nil { term.OutputErrorAndExit("%v", err) }
}

Prevention

When it happens

Trigger: writeCurrentAuth fails writing to HOME: disk full, permission denied on ~/.plandex-auth (or equivalent path), read-only filesystem, or the auth file directory missing.

Common situations: Read-only container/CI filesystem; HOME set to a non-writable path; disk quota exceeded; SELinux/permissions after upgrading the CLI run under a different user; running in a sandbox that blocks writes outside the workspace.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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