plandex-ai/plandex · error
failed to list contexts: %v
Error message
failed to list contexts: %v
What it means
MustLoadContext fetches existing contexts with api.Client.ListContext to avoid re-loading already-loaded files; this error means that list call failed via ApiErr.Msg. Without the existing-context list, deduplication cannot happen and the load aborts via onErr.
Source
Thrown at app/cli/lib/context_load.go:129
errCh := make(chan error)
ignoredPaths := make(map[string]string)
mapFilesTruncatedTooLarge := []filePathWithSize{}
mapFilesSkippedAfterSizeLimit := []string{}
// We'll reuse these for all skipping, including directory-tree partial skipping and URLs
filesSkippedTooLarge := []filePathWithSize{}
filesSkippedAfterSizeLimit := []string{}
var totalSize int64
numRoutines := 0
// filter out already loaded contexts
alreadyLoadedByComposite := make(map[string]*shared.Context)
existingContexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)
if apiErr != nil {
onErr(fmt.Errorf("failed to list contexts: %v", apiErr.Msg))
}
existsByComposite := make(map[string]*shared.Context)
for _, context := range existingContexts {
switch context.ContextType {
case shared.ContextFileType, shared.ContextDirectoryTreeType, shared.ContextMapType, shared.ContextImageType:
existsByComposite[strings.Join([]string{string(context.ContextType), context.FilePath}, "|")] = context
case shared.ContextURLType:
existsByComposite[strings.Join([]string{string(context.ContextType), context.Url}, "|")] = context
}
}
var cachedMapPaths map[string]bool
var cachedMapLoadRes *shared.LoadContextResponse
mapInputShas := map[string]string{}
mapInputTokens := map[string]int{}
mapInputSizes := map[string]int64{}View on GitHub (pinned to e2d772072e)
Solutions
- Check server connectivity (PLANDEX_HOST / daemon status)
- Re-authenticate if the message points at auth or permission
- Verify plan/branch exist (`plandex plans`, `plandex branches`)
- Retry; inspect server logs for the wrapped ApiErr.Msg
Example fix
// before
existingContexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)
if apiErr != nil {
onErr(fmt.Errorf("failed to list contexts: %v", apiErr.Msg))
}
// after
existingContexts, apiErr := api.Client.ListContext(CurrentPlanId, CurrentBranch)
if apiErr != nil {
if apiErr.Type == shared.ApiErrTypeAuthExpired {
onErr(fmt.Errorf("session expired — run `plandex login`: %v", apiErr.Msg))
}
onErr(fmt.Errorf("failed to list contexts: %v", apiErr.Msg))
} Defensive patterns
Strategy: retry
Validate before calling
// pre-check auth and plan before listing contexts
if auth.Current == nil || auth.Current.SessionId == "" {
return fmt.Errorf("not logged in — run `plandex login` first")
}
if CurrentPlanId == "" {
return fmt.Errorf("no current plan selected")
} Type guard
// Go: nil-guard the ApiErr before reading Msg
func isApiErr(err error) (*shared.ApiErr, bool) {
if apiErr, ok := err.(*shared.ApiErr); ok && apiErr != nil { return apiErr, true }
return nil, false
} Try / catch
// Go: exponential backoff on list failures
var existingContexts []*shared.Context
var apiErr *shared.ApiErr
for i := 0; i < 3; i++ {
existingContexts, apiErr = api.Client.ListContext(CurrentPlanId, CurrentBranch)
if apiErr == nil { break }
time.Sleep(time.Duration(1<<i) * 500 * time.Millisecond)
}
if apiErr != nil { onErr(fmt.Errorf("failed to list contexts: %v", apiErr.Msg)) } Prevention
- Keep sessions fresh; re-login after server restarts
- Confirm plan/branch exist before load operations
- Monitor server availability in CI before running plandex commands
- Pin matching CLI/server versions
When it happens
Trigger: api.Client.ListContext(CurrentPlanId, CurrentBranch) returns non-nil ApiErr — server unreachable, expired auth session, invalid plan/branch id, or server-side error.
Common situations: Stale session token after server restart; plan deleted in another terminal; offline/proxy outage; server deploy mid-command.
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
- error signing in: %v
- error listing contexts: %v
- error getting context body: %v
- error getting default config: %v
- error creating plan: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/64dd38361c1fda64.
Report an issue: GitHub.