plandex-ai/plandex · error

failed to load context: %v

Error message

failed to load context: %v

What it means

MustLoadContext wraps the error message from api.Client.LoadContext when the server rejects or fails the context-load request for the current plan/branch. It means the API call itself failed (network, auth, server-side error), so no context was loaded. The wrapped apiErr.Msg carries the server-side reason.

Source

Thrown at app/cli/lib/context_load.go:727

			fmt.Println()
			fmt.Printf("%s with the -n flag:\n", color.New(color.Bold, term.ColorHiCyan).Sprint("Load a note"))
			fmt.Println("plandex load -n 'Some note here'")

			fmt.Println()
			fmt.Printf("%s from any command:\n", color.New(color.Bold, term.ColorHiCyan).Sprint("Pipe data in"))
			fmt.Println("npm test | plandex load")
		}

		os.Exit(0)
	}

	var res *shared.LoadContextResponse
	if cachedMapLoadRes != nil {
		res = cachedMapLoadRes
	} else {
		res, apiErr = api.Client.LoadContext(CurrentPlanId, CurrentBranch, loadContextReq)
		if apiErr != nil {
			onErr(fmt.Errorf("failed to load context: %v", apiErr.Msg))
		}
	}

	term.StopSpinner()

	if hasConflicts {
		term.StartSpinner("🏗️  Starting build...")
		_, err := buildPlanInlineFn(false, nil)
		if err != nil {
			onErr(fmt.Errorf("failed to build plan: %v", err))
		}
		fmt.Println()
	}

	fmt.Println("✅ " + res.Msg)

	if len(alreadyLoadedByComposite) > 0 {
		printAlreadyLoadedMsg(alreadyLoadedByComposite)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect apiErr.Msg for the server-side reason (auth vs validation vs 5xx)
  2. Verify API connectivity and re-authenticate (log in again / refresh API key)
  3. Confirm CurrentPlanId and CurrentBranch still exist, then retry the load

Example fix

// before
res, apiErr = api.Client.LoadContext(CurrentPlanId, CurrentBranch, loadContextReq)
if apiErr != nil {
    onErr(fmt.Errorf("failed to load context: %v", apiErr.Msg))
}
// after — distinguish auth from transient errors
res, apiErr = api.Client.LoadContext(CurrentPlanId, CurrentBranch, loadContextReq)
if apiErr != nil {
    if apiErr.Code == 401 {
        onErr(fmt.Errorf("session expired, please log in again: %v", apiErr.Msg))
    } else {
        onErr(fmt.Errorf("failed to load context: %v", apiErr.Msg))
    }
}
Defensive patterns

Strategy: retry

Validate before calling

if CurrentPlanId == "" || CurrentBranch == "" {
    return fmt.Errorf("no active plan/branch; select one before loading context")
}
if err := checkApiReachable(); err != nil {
    return fmt.Errorf("API unreachable: %w", err)
}

Try / catch

res, apiErr := api.Client.LoadContext(planId, branch, req)
if apiErr != nil {
    if apiErr.Code == 401 || apiErr.Code == 403 {
        // re-authenticate then retry once
        reauth(); res, apiErr = api.Client.LoadContext(planId, branch, req)
    }
    if apiErr != nil { onErr(fmt.Errorf("failed to load context: %v", apiErr.Msg)) }
}

Prevention

When it happens

Trigger: api.Client.LoadContext(CurrentPlanId, CurrentBranch, loadContextReq) returns a non-nil apiErr — server 4xx/5xx, expired session, unreachable API, or invalid loadContextReq entries.

Common situations: Expired or invalid API key; plan/branch deleted server-side; offline or proxy/DNS issues; requesting paths the server no longer recognizes after a repo rebase.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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