Manage agent context budgets on large monorepos
Large monorepos punish careless context. Every extra file you attach competes with the instructions and code that matter.
Large monorepos punish careless context. Every extra file you attach competes with the instructions and code that matter. When the context is too large, the agent forgets constraints and starts “normalizing” distant files. When the context is too small, it invents helpers, duplicates types, and breaks imports.
The goal is simple: attach just enough for a correct patch, then stop.
What to include (and what to exclude)

When this fits vs when it does not
Include these five things first. In this order.
- Task statement. One sentence: what to change and what must not change.
- Path allowlist. The directories the agent may edit. Everything else is read-only by default.
- Constraints. Public API must stay stable, no new dependencies, keep error shape, keep performance budgets.
- Evidence. A failing test, a reproduction command, or the exact error output.
- Local map. The 3 to 8 files that define the boundary: public interfaces, shared types, and one exemplar of local style.
Exclude by default:
- Entire packages “just in case”
- Generated folders and build output
- Huge lockfiles and vendor blobs
- Large JSON fixtures that crowd out code
- Long chat history copied from another task
Workflow: build a context pack, then grow it only on demand

Build a context pack, then grow on demand
- Start narrow. Attach the allowlist and the local map. Do not attach the whole monorepo root.
- Anchor on evidence. For bug work, require a failing test or reproduction before any code edit.
- Add only the call path. Expand context by following imports from the entry point, not by attaching folders.
- Grant expansions as clusters. If the agent asks for more, give one module cluster at a time and re-check scope.
- After a patch, drop stale context. Start a fresh thread for the next slice so old hypotheses do not leak.
Stop gates (context and scope)
Stop and reslice the task when any of these happens:
- The file list explodes. The agent opens dozens of files outside the core call path.
- Drive-by edits. It edits formatting, renames symbols, or “cleans up” unrelated code.
- Cross-package drift. The diff spills into another package without an explicit reason tied to the task statement.
- Forgotten constraints. It proposes changes that violate the allowlist, dependency policy, or API stability rules.
Checklist: the smallest safe context for a patch
- One-sentence task statement with a clear “do not change” constraint.
- Path allowlist set before the first prompt.
- Evidence attached (test, repro command, or error output).
- Local map attached (interfaces, types, and one exemplar file).
- Generated, vendor, and giant data files excluded.
- A fresh thread started when the slice changes.
Three failure modes to expect

Failure modes to catch early
- Rewrite storm. The agent “harmonizes” unrelated code to match a local change.
- Fix: tighten the allowlist. Shrink context. Enforce a no-drive-by rule in review.
- Duplicate helper. It creates a new util because it never saw the existing one.
- Fix: add one exemplar file and the closest shared helper module. Do not attach the whole utils folder.
- Stale paste. Old chat logs or old summaries leak into the next task and override reality.
- Fix: start a new thread per slice. Re-attach only the five-item context pack.
Bottom line
Context is a budget. Spend it on evidence, boundaries, and local style. Do not spend it on repo dumps. If you need a companion rule for stopping runaway sessions, pair this with stop rules for agents and keep diffs small with safe refactors.
Share