plandex-ai/plandex · error

error listing contexts: %v

Error message

error listing contexts: %v

What it means

The `plandex contexts show` command fetches the plan's context list via api.Client.ListContext(planId, branch) before resolving the given name or index. If that API call fails, the CLI logs the underlying cause and returns this wrapped error, so the command aborts before it can resolve a context. It almost always reflects a network, auth, or server-side problem rather than a bad argument.

Source

Thrown at app/cli/cmd/context_show.go:32

func init() {
	RootCmd.AddCommand(contextShowCmd)
}

var contextShowCmd = &cobra.Command{
	Use:   "show [name-or-index]",
	Short: "Show the body of a context by name or list index",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		auth.MustResolveAuthWithOrg()
		lib.MustResolveProject()

		nameOrIndex := args[0]

		// Get list of contexts first
		contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)
		if err != nil {
			log.Printf("Error listing contexts: %v\n", err)
			return fmt.Errorf("error listing contexts: %v", err)
		}

		var contextId string

		// Try parsing as index first
		if idx, err := strconv.Atoi(nameOrIndex); err == nil {
			// Convert to 0-based index
			idx--
			if idx < 0 || idx >= len(contexts) {
				return fmt.Errorf("invalid context index: %s", nameOrIndex)
			}
			contextId = contexts[idx].Id
		} else {
			// Try finding by name
			found := false
			for _, ctx := range contexts {
				if ctx.Name == nameOrIndex || ctx.FilePath == nameOrIndex {
					contextId = ctx.Id

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the log line 'Error listing contexts' printed just above this error for the underlying cause and address it directly.
  2. Verify the Plandex server is reachable (plandex ping / correct PLANDEX_HOST) and that you are logged in with a valid session (re-run `plandex auth` if needed).
  3. Confirm you are inside the correct project directory with an active plan and branch (plandex plans / plandex branches).
  4. Retry after network/proxy issues are resolved; if the server returns 5xx, check server logs.

Example fix

// before
cmd.RunE = func(cmd *cobra.Command, args []string) error {
  contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)
  if err != nil {
    return fmt.Errorf("error listing contexts: %v", err)
  }
  _ = contexts
  return nil
}
// after
cmd.RunE = func(cmd *cobra.Command, args []string) error {
  contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)
  if err != nil {
    if apiErr, ok := err.(*shared.ApiError); ok {
      return fmt.Errorf("list contexts failed (HTTP %d): %s", apiErr.Status, apiErr.Msg)
    }
    return fmt.Errorf("list contexts failed: %w", err)
  }
  _ = contexts
  return nil
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before invoking the command, check server reachability and auth
// in shell:
// plandex ping && test -f .plandex/plan.json && echo "plan context available"
// in Go callers of ListContext:
if lib.CurrentPlanId == "" || lib.CurrentBranch == "" {
    return fmt.Errorf("no active plan/branch; run inside a plandex project")
}

Type guard

func isApiErr(err error) (*shared.ApiError, bool) {
    apiErr, ok := err.(*shared.ApiError)
    return apiErr, ok
}

Try / catch

contexts, err := api.Client.ListContext(planId, branch)
if err != nil {
    var apiErr *shared.ApiError
    if errors.As(err, &apiErr) {
        // handle by status: 401 -> re-auth, 5xx -> retry later
    }
    return fmt.Errorf("list contexts failed: %w", err)
}

Prevention

When it happens

Trigger: Running `plandex contexts show <name-or-index>` when the ListContext HTTP call to the Plandex server fails: server unreachable, expired/invalid session, plan or branch not found server-side, or a 5xx from the daemon.

Common situations: The Plandex server/daemon is down or the CLI is pointed at the wrong host; the auth session expired between commands; the current plan was deleted on the server or the branch no longer exists; a proxy/firewall blocks the API connection.

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/4e47882d1e4b4a62. Report an issue: GitHub.