plandex-ai/plandex · error

auth.Current.UserId is empty

Error message

auth.Current.UserId is empty

What it means

PromptSyncModelsIfNeeded checks local model/config files for drift before a plan attempt. It requires an authenticated user and returns 'auth.Current.UserId is empty' when auth.Current has no UserId, i.e. the CLI is not logged in.

Source

Thrown at app/cli/lib/models_sync.go:17

package lib

import (
	"fmt"
	"plandex-cli/auth"
	"plandex-cli/term"

	"github.com/fatih/color"
)

func PromptSyncModelsIfNeeded() error {
	var changes []string
	var onApprove []func() error

	userId := auth.Current.UserId
	if userId == "" {
		return fmt.Errorf("auth.Current.UserId is empty")
	}

	customModelsPath := GetCustomModelsPath(userId)

	customModelsRes, err := CustomModelsCheckLocalChanges(customModelsPath)
	if err != nil {
		return fmt.Errorf("error checking custom models: %v", err)
	}

	if customModelsRes.HasLocalChanges {
		changes = append(
			changes,
			fmt.Sprintf("%s → %s", color.New(term.ColorHiCyan, color.Bold).Sprint("Custom models"), customModelsPath))

		onApprove = append(onApprove, SyncCustomModels)
	}

	defaultModelSettingsRes, err := ModelSettingsCheckLocalChanges(DefaultModelSettingsPath)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Run `plandex login` / the auth flow to populate auth.Current.UserId
  2. Verify the auth state file exists in the expected HomePlandexDir for the current HOME
  3. In scripts/CI, add a login or auth-check step before plan commands

Example fix

// before
err := lib.MustApplyPlanAttempt(...)
// after
if lib/auth.Current.UserId == "" {
	// run login first
}
err := lib.MustApplyPlanAttempt(...)
Defensive patterns

Strategy: type-guard

Validate before calling

if auth.Current == nil || auth.Current.UserId == "" {
	return fmt.Errorf("not authenticated: run plandex login before syncing models")
}

Type guard

func isLoggedIn() bool {
	return auth.Current != nil && auth.Current.UserId != ""
}

Try / catch

if err := lib.PromptSyncModelsIfNeeded(); err != nil {
	if strings.Contains(err.Error(), "auth.Current.UserId is empty") {
		// trigger interactive login flow, then retry
	}
	return err
}

Prevention

When it happens

Trigger: Calling PromptSyncModelsIfNeeded (directly or via MustApplyPlanAttempt) before any `plandex auth` login, or after the stored auth state was cleared/corrupted so auth.Current.UserId is the empty string.

Common situations: Fresh machine or CI container without `plandex login`; auth cache deleted or overwritten; running commands in a different HOME so the auth file isn't found.

Related errors


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