{"record":{"id":"869637fc6f71b667","repo":"plandex-ai/plandex","slug":"update-would-add-d-and-exceed-token-limit-d","errorCode":null,"errorMessage":"update would add %d 🪙 and exceed token limit (%d) by %d 🪙","messagePattern":"update would add (.+?) 🪙 and exceed token limit \\((.+?)\\) by (.+?) 🪙","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_auto_load.go","lineNumber":141,"sourceCode":"\t}\n\n\t// Convert map back to ordered slice\n\tloadContextReqs := make(shared.LoadContextRequest, 0, len(loadContextReqsByIndex))\n\tfor i := 0; i < len(files); i++ {\n\t\tif req := loadContextReqsByIndex[i]; req != nil {\n\t\t\tloadContextReqs = append(loadContextReqs, req)\n\t\t}\n\t}\n\n\t// 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\n\tres, apiErr := api.Client.AutoLoadContext(ctx, CurrentPlanId, CurrentBranch, loadContextReqs)\n\tif apiErr != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to load context: %v\", apiErr.Msg)\n\t}\n\n\tif res.MaxTokensExceeded {\n\t\toverage := res.TotalTokens - res.MaxTokens\n\t\treturn \"\", fmt.Errorf(\"update would add %d 🪙 and exceed token limit (%d) by %d 🪙\", res.TokensAdded, res.MaxTokens, overage)\n\t}\n\n\tmsg := res.Msg\n\n\t// Print skip info if any\n\tif len(filesSkippedTooLarge) > 0 || len(filesSkippedAfterSizeLimit) > 0 {\n\t\tmsg += \"\\n\\n\" + getSkippedFilesMsg(filesSkippedTooLarge, filesSkippedAfterSizeLimit, nil, nil)\n\t}\n\n\treturn msg, nil\n}\n\nfunc MustLoadAutoContextMap() {\n\tMustLoadContext([]string{\".\"}, &types.LoadContextParams{\n\t\tDefsOnly:          true,\n\t\tSkipIgnoreWarning: true,\n\t\tAutoLoaded:        true,\n\t})","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_auto_load.go#L123-L159","documentation":"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.","triggerScenarios":"api.Client.AutoLoadContext returns a response with MaxTokensExceeded=true, i.e. res.TotalTokens - res.MaxTokens > 0 after adding the auto-loaded files' TokensAdded.","commonSituations":"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.","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"],"exampleFix":"// before\nif res.MaxTokensExceeded {\n\treturn \"\", fmt.Errorf(\"update would add %d 🪙 and exceed token limit (%d) by %d 🪙\", res.TokensAdded, res.MaxTokens, overage)\n}\n// after\nif res.MaxTokensExceeded {\n\treturn \"\", fmt.Errorf(\"context limit exceeded by %d 🪙 (max %d). Trim context with `plandex context rm <name>` or increase your token limit\", overage, res.MaxTokens)\n}","handlingStrategy":"validation","validationCode":"// estimate context size before auto-loading\nvar total int64\nfor _, path := range files {\n\tif fi, err := os.Stat(path); err == nil { total += fi.Size() }\n}\n// rough token estimate (~4 bytes/token)\nif total/4+currentTokens > maxTokens {\n\treturn fmt.Errorf(\"files too large to auto-load: trim context first\")\n}","typeGuard":"// Go: check the response flag before computing overage\nfunc tokensExceeded(res *shared.AutoLoadContextResponse) bool {\n\treturn res != nil && res.MaxTokensExceeded\n}","tryCatchPattern":"// Go: inspect the typed response rather than parsing the error string\nres, err := api.Client.AutoLoadContext(ctx, planId, branch, reqs)\nif err == nil && res.MaxTokensExceeded {\n\treturn fmt.Errorf(\"over budget by %d tokens — remove context or raise limit\", res.TotalTokens-res.MaxTokens)\n}","preventionTips":["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"],"tags":["token-limit","context-loading","cli","quota"],"backgroundTag":"token-limit-exceeded","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}