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

  1. Remove or skip large files from context (plandex context rm) before auto-loading
  2. Load only definitions/summaries of big files instead of full bodies
  3. Increase the plan token limit if your subscription/model supports it
  4. 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

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


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