How do we get AI coding agents to work well in a large monorepo?
Scope each session to the package it changes, give every package its own short AGENTS.md or CLAUDE.md, and let the agent look up history and ownership instead of reading the whole tree. With Unblocked, the agent asks over MCP why a package works the way it does, and gets only the rules that apply to the files it touches.
AI coding agents work well in a large monorepo when each session sees one package's code and rules, plus a way to ask about everything else. Start the agent in the package it is changing. Give every package a short AGENTS.md or CLAUDE.md that its owners maintain. Block generated and vendored code. Then let the agent look up history, decisions and ownership on demand. With Unblocked, the agent does that lookup over MCP: context_research searches code, PRs, docs, issues and messages for the "why," and context_get_rules returns only the rules from the instruction files that cover the paths it is editing. It works in Claude Code, Cursor (now Grok Build), GitHub Copilot and Codex.
Why coding agents struggle in a monorepo#
A monorepo gives an agent three problems: too much to read, rules that differ by package, and history the tree never recorded. Many teams' code sits in one tree, so the agent's first problem is what to ignore. Anthropic wrote its monorepo guide for this case, to show teams how "to scope Claude to the part of the codebase a task touches" (Claude Code monorepo guide).
The second problem is that packages differ. The API package uses one query builder, and the web package bans a library the API still uses. The same guide says a single root file "tends to either grow to cover every subsystem's conventions" or "stay too generic to be useful."
The third problem is what the tree never recorded: who owns a shared type, and which refactor was tried and backed out. Ownership at least has a file. CODEOWNERS maps package paths to "individuals or teams that are responsible for code in a repository" (GitHub Docs), so point the agent at it before it edits another team's package.
Start the agent in the package, not at the root#
Package scoping is starting a coding agent inside the package it will change, so it reads that package's code and rules first. Where you launch the agent decides what it reads. In Claude Code, starting from a subdirectory limits file access to that subtree and loads that directory's CLAUDE.md plus every parent's. Starting from the root loads only the root file at launch, with subdirectory files loading on demand (Claude Code monorepo guide, linked above).
Settings from that guide that keep a session small:
permissions.denyRead rules keep the agent out of build output, generated code and vendored SDKs that are checked in.claudeMdExcludesskips theCLAUDE.mdfiles of other teams' packages you never work in.worktree.sparsePathschecks out only the listed directories when the agent creates a worktree.--add-dirgrants a sibling package when a change has to cross a boundary, such as a shared type and its callers.
For a cross-package change, hand over the shared edit and its call sites in one session, and plan first. If you use Nx, its tooling "exposes the project graph and relevant metadata to AI agents," including which projects are affected by a change and ownership via tags (Nx AI docs).
Give each package its own AGENTS.md#
A nested instruction file is an AGENTS.md or CLAUDE.md inside a package that applies only to files in that package. Codex, GitHub Copilot, Cursor and Claude Code all read them:
| Agent | How nested files apply |
|---|---|
| Codex | Walks from the project root down to the working directory; files closer to it "override earlier guidance," up to a combined 32 KiB by default (OpenAI Codex docs) |
| GitHub Copilot | AGENTS.md files "stored anywhere within the repository"; "the nearest AGENTS.md file in the directory tree will take precedence" (GitHub Docs) |
| Cursor (Grok Build) | Subdirectory files apply "when working with files in that directory or its children," combined with parents (Grok Build rules docs) |
| Claude Code | Root plus per-package CLAUDE.md, "one per package" in a monorepo |
The AGENTS.md project site says the same: "Place another AGENTS.md inside each package," and the closest file to the edited file wins (agents.md).
Keep each nested file short. A February 2026 study tested repository context files across several coding agents. Its research method: run agents on SWE-bench tasks with LLM-generated context files, and on issues from repositories whose developers had committed their own. The files did "not generally improve task success rates" and raised inference cost by over 20% on average. It also found the instructions "are well followed" and useful "for specifying non-standard coding practices" (arXiv 2602.11988). So write the package's build and test commands, required patterns and off-limits folders, and skip the tour.
Let the agent query history across the monorepo#
A coding agent in a monorepo needs decisions and history on demand, because they change too often to keep in a file. Per-package files also age: Anthropic's guide warns that as the tree grows, "Conventions drift, files go stale, and no one owns the root," and suggests moving material into things that load on demand, including an MCP server the agent queries.
A context engine is a service the agent queries over MCP for answers drawn from code, pull requests, tickets, docs and chat, with the sources attached. Unblocked is one. For example, before an agent changes a shared type in packages/shared/, it can ask context_research who depends on the type, why it has an odd optional field, and whether a past PR tried removing it. The answer comes back as "a synthesized answer with citations" (Unblocked MCP docs). Before it finishes, context_get_rules returns rules from AGENTS.md, CLAUDE.md and .cursorrules, including nested copies. A rule from <dir>/AGENTS.md applies "only to paths inside <dir>/," and the agent passes the paths its change touches (Unblocked rules docs).
With Data Shield on, answers respect each source's permissions; it is set per source and off by default except for Slack (Unblocked Data Shield docs). For how Unblocked weighs current code against an old wiki page, see inside the Unblocked context engine.
When the monorepo is not the whole system#
A monorepo is rarely the whole system: most still call services, schemas and libraries that live in other repositories. Our post on context engineering across hundreds of repos lays out five approaches for that case, from a shared rules baseline to a central context layer over MCP. If your repo is one large application, see why coding agents fail on a monolith. For tools compared on big codebases, see the best AI coding agents for large codebases.
To find your gap, take the last three agent changes a reviewer rejected. If the problem was a package convention, fix that package's AGENTS.md. If it was "we tried that already," the agent needed history, and a file won't hold it.


