plandex-ai/plandex · error

Context exceeds size limit (size %.2f MB, limit MB)

Error message

Context %s exceeds size limit (size %.2f MB, limit %d MB)

What it means

Each context's Body must be no larger than shared.MaxContextBodySize. If a single context body exceeds it, the server rejects the whole load with HTTP 400, reporting the size in MB against the MB limit.

Solutions

  1. Trim or split the content before adding it as context
  2. Reference only the relevant portion of the large file
  3. Compress/summarize large data instead of loading it whole

Example fix

// before
body, _ := os.ReadFile("huge.log")
client.LoadContexts(ctx, planId, branch, []shared.LoadContextParams{{Body: string(body)}})
// after
body, _ := os.ReadFile("huge.log")
if int64(len(body)) > shared.MaxContextBodySize {
    body = body[len(body)-int(shared.MaxContextBodySize):] // keep recent tail only
}
client.LoadContexts(ctx, planId, branch, []shared.LoadContextParams{{Body: string(body)}})
Defensive patterns

Strategy: validation

Validate before calling

for i := range loadReq {
    if int64(len(loadReq[i].Body)) > shared.MaxContextBodySize {
        return fmt.Errorf("context %s body %d bytes exceeds limit %d", loadReq[i].Name, len(loadReq[i].Body), shared.MaxContextBodySize)
    }
}

Prevention

When it happens

Trigger: Loading any context (file, piped data, note, image) whose context.Body length exceeds shared.MaxContextBodySize — e.g. piping a huge log or adding a large generated file.

Common situations: Piping large datasets/logs into a plan (cat big.log | plandex); adding build artifacts or datasets; database dumps added as context files.

Related errors


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

Appendix: source

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

			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

	var settings *shared.PlanSettings
	var clients map[string]model.ClientInfo
	var authVars map[string]string
	var orgUserConfig *shared.OrgUserConfig

	for _, context := range *loadReq {
		if context.ContextType == shared.ContextPipedDataType || context.ContextType == shared.ContextNoteType || context.ContextType == shared.ContextImageType {

View on GitHub (pinned to e2d772072e)