plandex-ai/plandex Β· error
update would add %d πͺ and exceed token limit (%d) by %d πͺ
Error message
update would add %d πͺ and exceed token limit (%d) by %d πͺ
What it means
This error is thrown by AutoLoadContextFiles when the server responds that the context update would push the plan's total context past the configured maximum token limit (res.MaxTokensExceeded is true). It reports how many tokens would be added, the max limit, and the overage, so the user can trim context. It is a server-enforced budget check, not a runtime fault.
Source
Thrown at app/cli/lib/context_auto_load.go:141
}
// Convert map back to ordered slice
loadContextReqs := make(shared.LoadContextRequest, 0, len(loadContextReqsByIndex))
for i := 0; i < len(files); i++ {
if req := loadContextReqsByIndex[i]; req != nil {
loadContextReqs = append(loadContextReqs, req)
}
}
// even if there are no files to load, we still need to hit the API endpoint because the stream is waiting on a channel for the autoload to finish
res, apiErr := api.Client.AutoLoadContext(ctx, CurrentPlanId, CurrentBranch, loadContextReqs)
if apiErr != nil {
return "", fmt.Errorf("failed to load context: %v", apiErr.Msg)
}
if res.MaxTokensExceeded {
overage := res.TotalTokens - res.MaxTokens
return "", fmt.Errorf("update would add %d πͺ and exceed token limit (%d) by %d πͺ", res.TokensAdded, res.MaxTokens, overage)
}
msg := res.Msg
// Print skip info if any
if len(filesSkippedTooLarge) > 0 || len(filesSkippedAfterSizeLimit) > 0 {
msg += "\n\n" + getSkippedFilesMsg(filesSkippedTooLarge, filesSkippedAfterSizeLimit, nil, nil)
}
return msg, nil
}
func MustLoadAutoContextMap() {
MustLoadContext([]string{"."}, &types.LoadContextParams{
DefsOnly: true,
SkipIgnoreWarning: true,
AutoLoaded: true,
})View on GitHub (pinned to e2d772072e)
Solutions
- Remove or skip large files from context (plandex context rm) before auto-loading
- Load only definitions/summaries of big files instead of full bodies
- Increase the plan token limit if your subscription/model supports it
- Split work across branches or plans to spread context usage
Example fix
// before
if res.MaxTokensExceeded {
return "", fmt.Errorf("update would add %d πͺ and exceed token limit (%d) by %d πͺ", res.TokensAdded, res.MaxTokens, overage)
}
// after
if res.MaxTokensExceeded {
return "", fmt.Errorf("context limit exceeded by %d πͺ (max %d). Trim context with `plandex context rm <name>` or increase your token limit", overage, res.MaxTokens)
} Defensive patterns
Strategy: validation
Validate before calling
// estimate context size before auto-loading
var total int64
for _, path := range files {
if fi, err := os.Stat(path); err == nil { total += fi.Size() }
}
// rough token estimate (~4 bytes/token)
if total/4+currentTokens > maxTokens {
return fmt.Errorf("files too large to auto-load: trim context first")
} Type guard
// Go: check the response flag before computing overage
func tokensExceeded(res *shared.AutoLoadContextResponse) bool {
return res != nil && res.MaxTokensExceeded
} Try / catch
// Go: inspect the typed response rather than parsing the error string
res, err := api.Client.AutoLoadContext(ctx, planId, branch, reqs)
if err == nil && res.MaxTokensExceeded {
return fmt.Errorf("over budget by %d tokens β remove context or raise limit", res.TotalTokens-res.MaxTokens)
} Prevention
- Periodically run `plandex context ls` to audit loaded context size
- Load large files as definitions/summaries, not full bodies
- Exclude vendored/dependency directories from auto-load
- Raise the plan token limit proactively for large codebases
When it happens
Trigger: api.Client.AutoLoadContext returns a response with MaxTokensExceeded=true, i.e. res.TotalTokens - res.MaxTokens > 0 after adding the auto-loaded files' TokensAdded.
Common situations: Auto-loading a large directory whose files collectively exceed the plan's token budget; long-running session that already has most of the limit consumed; large images or vendored/dependency files auto-included.
Related errors
- failed to list contexts: %v
- error selecting account: account not found
- error signing in: %v
- error selecting or signing in to account: %v
- error selecting sign in option: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/869637fc6f71b667.
Report an issue: GitHub.