plandex-ai/plandex · error

Too many contexts to load (found %d, limit is %d)

Error message

Too many contexts to load (found %d, limit is %d)

What it means

loadContexts caps the number of contexts in a single load request at shared.MaxContextCount. If the request would push the total above that cap, the server returns HTTP 400 and loads nothing. This protects the plan's context budget and downstream LLM calls.

Source

Thrown at app/server/handlers/context_helper.go:71

			if len(context.MapBodies) > shared.MaxContextMapPaths {
				log.Printf("Error: Too many map files to load (found %d, limit is %d)\n", len(context.MapBodies), shared.MaxContextMapPaths)
				http.Error(w, fmt.Sprintf("Too many map files to load (found %d, limit is %d)", len(context.MapBodies), shared.MaxContextMapPaths), http.StatusBadRequest)
				return nil, nil
			}

			// these are already mapped, so they shouldn't be anywhere close to the input limit, but we'll use it for the sanity check
			for _, body := range context.MapBodies {
				if len(body) > shared.MaxContextMapSingleInputSize {
					log.Printf("Error: Map file %s exceeds size limit (size %d, limit %d)\n", context.FilePath, len(body), shared.MaxContextMapSingleInputSize)
					http.Error(w, fmt.Sprintf("Map file %s exceeds size limit (size %d, limit %d)", context.FilePath, len(body), shared.MaxContextMapSingleInputSize), http.StatusBadRequest)
					return nil, nil
				}
			}
		}

		if totalFiles > shared.MaxContextCount {
			log.Printf("Error: Too many contexts to load (found %d, limit is %d)\n", totalFiles, shared.MaxContextCount)
			http.Error(w, fmt.Sprintf("Too many contexts to load (found %d, limit is %d)", totalFiles, shared.MaxContextCount), http.StatusBadRequest)
			return nil, nil
		}

		fileSize := int64(len(context.Body))
		if fileSize > shared.MaxContextBodySize {
			log.Printf("Error: Context %s exceeds size limit (size %.2f MB, limit %d MB)\n", context.Name, float64(fileSize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024)
			http.Error(w, fmt.Sprintf("Context %s exceeds size limit (size %.2f MB, limit %d MB)", context.Name, float64(fileSize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024), http.StatusBadRequest)
			return nil, nil
		}

	}

	if mapFilesCount > 0 {
		log.Printf("[ContextHelper] Processing %d map files out of %d total contexts", mapFilesCount, totalFiles)
	}

	var err error

View on GitHub (pinned to e2d772072e)

Solutions

  1. Split the load into multiple smaller requests
  2. Remove or unload unneeded contexts first to stay under the cap
  3. Check shared.MaxContextCount for the server version and batch accordingly

Example fix

// before
client.LoadContexts(ctx, planId, branch, allContexts) // allContexts > MaxContextCount
// after
for batch := range chunk(allContexts, shared.MaxContextCount) {
    client.LoadContexts(ctx, planId, branch, batch)
}
Defensive patterns

Strategy: validation

Validate before calling

if len(loadReq) > shared.MaxContextCount {
    return fmt.Errorf("context count %d exceeds limit %d; batch the request", len(loadReq), shared.MaxContextCount)
}

Prevention

When it happens

Trigger: A LoadContexts request whose context list length exceeds shared.MaxContextCount (checked incrementally as totalFiles during the validation loop).

Common situations: Bulk-loading many files at once via the CLI or API; recursive directory adds; automation scripts appending contexts in a loop without batching.

Related errors


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