plandex-ai/plandex · error
context body is too large: %d
Error message
context body is too large: %d
What it means
LoadContexts rejects any single incoming context whose body exceeds shared.MaxContextBodySize bytes. The size is computed as len(context.Body) server-side; the client should have prevented this, so the error indicates an oversized file/blob was submitted directly to the API.
Source
Thrown at app/server/db/context_helpers_load.go:116
if err != nil {
return nil, nil, fmt.Errorf("error getting existing contexts: %v", err)
}
// check overall context limits - these should be getting enforced by the client, so just error out if exceeded
numExistingContexts := len(existingContexts)
if numExistingContexts+len(*req) > shared.MaxContextCount {
return nil, nil, fmt.Errorf("too many contexts: %d", numExistingContexts+len(*req))
}
var totalContextSize int64
for _, context := range existingContexts {
totalContextSize += context.BodySize
}
for _, context := range *req {
size := int64(len(context.Body))
totalContextSize += size
if size > shared.MaxContextBodySize {
return nil, nil, fmt.Errorf("context body is too large: %d", size)
}
}
if totalContextSize > shared.MaxTotalContextSize {
return nil, nil, fmt.Errorf("total context size is too large: %d", totalContextSize)
}
existingContextsByName := make(map[string]bool)
for _, context := range existingContexts {
composite := strings.Join([]string{context.Name, string(context.ContextType)}, "|")
existingContextsByName[composite] = true
if planConfig.AutoLoadContext && context.ContextType == shared.ContextMapType {
totalMapTokens += context.NumTokens
totalPlannerTokens -= context.NumTokens
}
if !context.AutoLoaded && context.ContextType != shared.ContextMapType {View on GitHub (pinned to e2d772072e)
Solutions
- Remove or ignore the oversized file (add it to .plandexignore / don't load it).
- Load only the relevant portion of the file (split or excerpt it).
- For generated files, exclude build/dependency directories from context loads.
- If an API caller, check len(body) <= shared.MaxContextBodySize before submitting.
Example fix
// before: sending the whole file
data, _ := os.ReadFile("dist/bundle.js")
params := shared.LoadContextParams{Body: string(data)}
// after: guard on client side
const MaxContextBodySize = 200 * 1024 // shared.MaxContextBodySize
if len(data) > MaxContextBodySize {
return fmt.Errorf("file too large for context: %d bytes", len(data))
} Defensive patterns
Strategy: validation
Validate before calling
func withinBodyLimit(body string) bool {
return int64(len(body)) <= shared.MaxContextBodySize
}
for _, p := range reqParams {
if !withinBodyLimit(p.Body) {
return fmt.Errorf("skipping %s: body exceeds MaxContextBodySize", p.Name)
}
} Try / catch
_, err := client.LoadContexts(req)
if err != nil {
if strings.Contains(err.Error(), "context body is too large") {
// extract reported size, split or excerpt the offending file, resubmit
return splitAndRetry(err)
}
return err
} Prevention
- Check len(body) against MaxContextBodySize before submitting
- Exclude generated artifacts and minified bundles from context loads
- Use .plandexignore to keep large files out of loads
- Split very large files into smaller excerpts before loading
When it happens
Trigger: A LoadContexts request containing one context with len(Body) > shared.MaxContextBodySize — typically a very large file loaded via direct API call or an automation that skips client checks.
Common situations: Loading generated artifacts (build outputs, lockfiles, datasets, minified bundles) that exceed the per-context size cap; API scripts passing whole large files; binary files base64-bloated past the limit.
Related errors
- too many contexts: %d
- error getting org session: %v
- error committing plan build: %v
- Error storing plan result: planRes is nil
- Error storing plan build result: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/a0f5b204ce327b00.
Report an issue: GitHub.