plandex-ai/plandex · error

Too many files to map: %d (max %d)

Error message

Too many files to map: %d (max %d)

What it means

GetFileMapHandler enforces shared.MaxContextMapPaths (3000): if req.MapInputs contains more than 3000 entries the handler rejects the request with HTTP 400 and 'Too many files to map: %d (max %d)' showing the actual count and the 3000 limit.

Source

Thrown at app/server/handlers/file_maps.go:36

func GetFileMapHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("Received request for GetFileMapHandler")

	auth := Authenticate(w, r, true)
	if auth == nil {
		log.Println("GetFileMapHandler: auth failed")
		return
	}

	var req shared.GetFileMapRequest
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		http.Error(w, fmt.Sprintf("Error decoding request: %v", err), http.StatusBadRequest)
		return
	}

	log.Println("GetFileMapHandler: checking limits")

	if len(req.MapInputs) > shared.MaxContextMapPaths {
		http.Error(w, fmt.Sprintf("Too many files to map: %d (max %d)", len(req.MapInputs), shared.MaxContextMapPaths), http.StatusBadRequest)
		return
	}

	totalSize := 0
	for path, input := range req.MapInputs {
		// the client should be truncating inputs to the max size, but we'll check here too
		if len(input) > shared.MaxContextMapSingleInputSize {
			http.Error(w, fmt.Sprintf("File %s is too large: %d (max %d)", path, len(input), shared.MaxContextMapSingleInputSize), http.StatusBadRequest)
			return
		}
		totalSize += len(input)
	}

	// On the client, once the total size limit is exceeded, we send empty file maps for remaining files
	if totalSize > shared.MaxContextMapTotalInputSize+10000 {
		http.Error(w, fmt.Sprintf("Max map size exceeded: %d (max %d)", totalSize, shared.MaxContextMapTotalInputSize), http.StatusBadRequest)
		return
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Reduce the number of paths sent per request to <= 3000
  2. Apply ignore patterns (vendor, node_modules, generated files) before collecting paths
  3. Split the work into multiple requests of at most 3000 files each
  4. Respect the client-side limit enforced in shared.MustLoadContext, which already blocks >3000 paths

Example fix

// before
inputs := allRepoFiles(repoRoot) // 12000 files
sendMapRequest(inputs)
// after
const maxPaths = shared.MaxContextMapPaths // 3000
for _, batch := range chunkPaths(filterIgnored(allRepoFiles(repoRoot)), maxPaths) {
    sendMapRequest(toInputMap(batch))
}
Defensive patterns

Strategy: validation

Validate before calling

// Client-side check before calling the API
if len(inputs) > shared.MaxContextMapPaths {
    return fmt.Errorf("%d files exceeds max %d; batch them", len(inputs), shared.MaxContextMapPaths)
}

Prevention

When it happens

Trigger: POSTing a GetFileMapRequest whose MapInputs map has >3000 file-path entries.

Common situations: Pointing the client at a monorepo or vendored dependency tree without ignore rules; a recursive directory walk that includes node_modules/.git; batch scripts that skip the client-side MustLoadContext pre-check.

Related errors


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