plandex-ai/plandex · error

error writing auth: %v

Error message

error writing auth: %v

What it means

After setting auth and resolving the org, handleSignInResponse persists the complete session with writeCurrentAuth(); failure there is wrapped as "error writing auth: %v". The session was obtained but could not be saved to disk, so sign-in does not complete.

Source

Thrown at app/cli/auth/account.go:287

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

	org, err := resolveOrgAuth(res.Orgs, isLocalMode)

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

	Current.OrgId = org.Id
	Current.OrgName = org.Name
	Current.IntegratedModelsMode = org.IntegratedModelsMode

	err = writeCurrentAuth()

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

	fmt.Printf("✅ Signed in as %s | Org: %s\n", color.New(color.Bold, term.ColorHiGreen).Sprintf("<%s> %s", Current.UserName, Current.Email), color.New(term.ColorHiCyan).Sprint(Current.OrgName))
	fmt.Println()

	return nil
}

func createAccount(email, pin, host string, isLocalMode bool) error {
	var name string

	if isLocalMode {
		name = "Local Admin"
	} else {
		var err error
		name, err = term.GetUserStringInput("Your name:")

		if err != nil {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Ensure the auth file's parent directory exists and is writable by the current user.
  2. Fix ownership after prior sudo usage: chown -R $(whoami) ~/.<app>.
  3. Check free disk space and remount read-only volumes.
  4. Retry sign-in once the filesystem is writable.

Example fix

// before
mkdir: cannot write ~/.myapp/auth.json: Permission denied
// after
sudo chown -R $(whoami) ~/.myapp
mkdir -p ~/.myapp
myapp auth login
Defensive patterns

Strategy: validation

Validate before calling

func canWriteAuthFile(path string) error {
    dir := filepath.Dir(path)
    if _, err := os.Stat(dir); err != nil {
        return fmt.Errorf("auth dir missing: %w", err)
    }
    f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o600)
    if err != nil {
        return fmt.Errorf("auth file not writable: %w", err)
    }
    f.Close()
    return nil
}

Try / catch

if err := signIn(email, pin, host); err != nil {
    if strings.Contains(err.Error(), "error writing auth") {
        fmt.Fprintln(os.Stderr, "Session obtained but could not be saved; fix filesystem permissions/space:", err)
    }
    return err
}

Prevention

When it happens

Trigger: writeCurrentAuth returns an error writing the Current auth struct (token, org id, org name) to the local auth file — permission denied, missing directory, disk full, or serialization failure.

Common situations: Read-only filesystem (container/CI), config directory deleted mid-run, disk quota exceeded, or a stale auth file locked/owned by another user after a sudo run.

Related errors


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