InterviewKata
AI engineering · Module 09a · Level 3: Configure your tools

Repository setup for agents

An agent is only as good as what it can find, build and check. The same model does far better in a repository where instructions sit next to the code, one command runs the right tests, and the dependency graph can be asked "what depends on this?". This module covers the repository standards that help any coding agent, then the two big structural choices: one repository or many, and which build system. Each comes with its pros and cons for agents.

A 5-minute conversation: Sam asks, Priya explains
0:00 / 5:00

1. The idea

A new contractor arrives at a large building site. On one site there's a site map, a labelled cabinet for each trade, and a board that says which rooms depend on which pipes. On another, each trade has its own locked yard across town, and the pipe plan lives in someone's head. The contractor is equally skilled in both, but only one site lets them work out what their change will affect before they start digging.

Three decisions shape how well agents work in your code:

DecisionOptionsWhat it changes for an agent
Repository standardsInstructions, setup, one-command checks, ownership rulesWhether the agent can start, build, test and follow your conventions without guessing. Matters in every layout.
Repository layoutMonorepo (all projects in one repository), polyrepo (one repository per service or module), or a hybridWhat the agent can see and change in one session, and whether a cross-project change is one pull request or several.
Build systemNative per-language tools (npm/pnpm, Gradle, Maven, Go, Cargo, CMake), monorepo task runners (Nx, Turborepo), or unified build systems (Bazel, Buck2, Pants)How fast and reliable the agent's checks are, and whether it can ask the build "what does this change affect?".

One idea links all three, put well by Daniel Westgaard: what matters is "whether your dependency graph is declared to a machine or remembered by people." An agent can query a machine. It can't query your senior engineer's memory.

2. How it works

The repository standards every agent benefits from

These come from GitHub's guidance for Copilot's cloud agent, the AGENTS.md standard and Claude Code's large-codebase guide. They work with every tool, whatever your layout:

The same change, two layouts

An agent must change how a shared money-formatting library rounds amounts. Three services use it. Watch it in a monorepo with a build graph, and in a polyrepo.

In a monorepo with a build graph, the agent asks the build which projects depend on the library, runs only their tests, and changes everything in one pull request.

What the agent can ask each build system

3. Try it yourself

Which layout and build system fit you?

Answer five questions about your organisation. The recommendation explains its reasoning; there's no single right answer for everyone.

How agent-ready is your repository?

Tick what your repository already has.

4. Why it matters at work

Monorepo, polyrepo or hybrid: pros and cons with agents

LayoutPros for agentsCons for agents
MonorepoSees every consumer of a change; one atomic pull request across projects; one continuous context instead of a reset at each repository boundary; one set of instructions, skills and checks; build tools that answer "what depends on this?"Huge trees fill the context unless scoped (nested instructions, sparse checkouts, excluded generated code); full test suites time out unless tests are scoped to affected projects; needs build infrastructure and shared standards; infrastructure code often still lives elsewhere
PolyrepoSmall, focused repositories are easy for an agent to understand; independent CI, releases and permissions; mixed stacks coexist; a mistake's blast radius is one repositoryThe agent can't see who consumes its change; cross-cutting changes become several PRs that must merge in order; versions drift between repositories; standards must be copied into every repository; some agent modes are limited to one repository per task
HybridA monorepo per product or domain, with stable contracts (OpenAPI, protobuf) between them; or a "synthetic monorepo" layer that maps dependencies across repositoriesMore moving parts; cross-repository changes stay non-atomic ("eventually consistent", in Nx's words about its own Polygraph tool)

Evidence is thin and mostly from vendors. Nx (which sells monorepo tools) argues agents hit read, write and memory limits in polyrepos, and cites Airbnb compressing an 18-month migration into 6 weeks with agents in a monorepo. Riftmap (which sells cross-repository graphs) argues the real variable is a queryable dependency graph, which a polyrepo can have too, and cites data showing more variable pull-request cycle times in monorepos. No independent comparison exists yet. Both agree on the essential point: agents need to know what a change affects.

Build systems: pros and cons with agents

Build systemWhat it isPros for agentsCons for agentsBest for
Native tools (npm/pnpm workspaces, Gradle, Maven, Go modules, Cargo workspaces)Each language's standard build and package toolsAgents know them extremely well from training data; no new language; easy for every contributorNo cross-language graph; "what's affected?" needs extra tooling; tests often run whole packages or the whole repository; caching is per toolPolyrepos, and small or single-language monorepos
Nx, TurborepoTask runners layered on top of native tools, mainly for JavaScript/TypeScript monorepos (Nx also supports other languages via plugins)Keep native tools; add a project graph, affected-only tasks and local/remote caching; Nx ships an MCP server and agent-oriented CI features; Turborepo describes itself as "the build system for coding agents"Graph quality depends on declared dependencies; not hermetic like Bazel; another config layer to keep correctJS/TS monorepos of any size
BazelOpen-source, multi-language build system; targets declared in BUILD files written in StarlarkHermetic, sandboxed builds give the same result in the agent's sandbox and in CI; rebuilds only what changed; bazel query answers "what depends on this?"; remote caching and execution; proven above 100,000 source filesBUILD files are another language the agent must write correctly, and a new failure mode; steep setup and migration; needs dedicated build engineersLarge polyglot monorepos (C++, Java, Go, mobile) with a platform team
Buck2Meta's rewrite of Buck, written in Rust, open source since 2023One incremental graph; remote execution built in; rules in Starlark; about 2× faster than Buck1 in Meta's tests; composes many languages in one buildSmaller community and ecosystem than Bazel; same BUILD-file burden; fewer examples in agents' training dataVery large polyglot monorepos willing to adopt early
PantsBuild system focused on Python, Go, Java, Scala, Kotlin, Shell and DockerInfers most dependencies from imports, so little BUILD-file boilerplate for agents to maintain; runs only tests affected by a changeNarrower language set; smaller communityPython-heavy or mixed Python/Go/JVM monorepos
CMakeKitware's build-system generator for C and C++: it writes the native build files (for example for Ninja or Make), which then build the codeThe C/C++ standard, so agents know it well; works with IDEs and language servers through generated compile commandsNot a monorepo orchestrator: no affected-project queries or remote cache of its own; large CMake trees are hard for agents to reason aboutC/C++ projects; at monorepo scale, often paired with or replaced by Bazel or Buck2

What to choose, by situation

SituationRecommended
One product, one or a few teams, mostly one languageMonorepo with native workspaces; add Nx or Turborepo (JS/TS) when CI gets slow
Frontend and backend that change togetherMonorepo, so one agent can change the API and its callers in one pull request
Many teams, polyglot, very large, with a platform teamMonorepo with Bazel (or Buck2), remote caching and execution
Python-heavy monorepoPants, or native tools plus a task runner
C/C++ productCMake with Ninja; consider Bazel only when scale and many languages demand it
Independent services owned by separate teams, different release cycles, strict access boundariesPolyrepo with shared contracts, a template repository for AGENTS.md and checks, and cross-repository search for agents

If you keep separate repositories

  1. One template: a template repository with AGENTS.md, the check script, CI, CODEOWNERS and the PR template, so every repository starts agent-ready.
  2. Contracts as the interface: OpenAPI, protobuf or JSON Schema in a contracts repository, versioned; agents change the contract first, then each consumer.
  3. Shared skills as a plugin (Module 12), instead of copying skills into each repository.
  4. Cross-repository context: a code-search MCP server, or a tool that can open several repositories in one session (section 5).
  5. Automated dependency updates (Dependabot or Renovate), so version drift doesn't build up silently.
The honest caveatsMost claims about repository layout and agents come from vendors with a product to sell, on both sides. Moving to a monorepo or to Bazel is a large, multi-month investment with its own risks; don't migrate for agents alone. Start with the standards in section 2, which help in any layout, and measure where your agents actually struggle (Module 21a) before changing structure.

5. In your five tools

How each tool handles monorepos and multiple repositories. Checked 31 October 2026.

ToolIn a monorepoAcross several repositories
Claude CodeRoot and per-directory CLAUDE.md (subdirectory files load on demand); claudeMdExcludes for other teams' packages; Read deny rules for generated and vendored code; worktree.sparsePaths for sparse worktrees; code intelligence plugins for symbol lookups; per-package skills--add-dir or additionalDirectories to open sibling checkouts; projects coordinate several cloud sessions across repositories
GitHub CopilotAGENTS.md at any level; .github/copilot-instructions.md; path-specific .github/instructions/*.instructions.md with applyTo globs; copilot-setup-steps.yml preinstalls dependenciesThe cloud agent in a cloud sandbox can span several repositories in one organisation; in GitHub Actions mode it is limited to one repository
Codex CLIAGENTS.md merged from the root down to the working folder; AGENTS.override.md takes precedence in its folder; combined files capped at 32 KiB by defaultCodex cloud environments are set up from the repositories you choose; locally, run a session per checkout and coordinate through contracts
CursorNested AGENTS.md and .cursor/rules/*.mdc with file globs; environment in .cursor/environment.jsonCloud agents can work across several repositories and open a PR in each
Antigravity CLIAGENTS.md or GEMINI.md per folder; .agents/rules/*.md with a glob modeSubagents can work in separate git worktrees; open other repositories in their own sessions

6. Remember it

Memory hook: "Give the agent the map, not just the maze"Whatever the layout, the agent needs instructions next to the code, one command to check its work, and a dependency graph it can query.
How this hook works: what “Give the agent the map, not just the maze” means

What the slogan means, phrase by phrase

“the map”
Nested AGENTS.md files, a queryable build graph, code intelligence, CODEOWNERS: things that tell the agent where it is and what depends on what.
“not just the maze”
Access to files alone. An agent that can open everything but can't ask what depends on what explores, guesses and burns tokens.

Why this picture fits: a monorepo without a graph is a bigger maze; a polyrepo with a parsed dependency graph has a map. The layout matters less than the map.

The story → the concept

Building siteRepository
Site rules at the gate, trade notes at each cabinetRoot and nested AGENTS.md
Tools laid out before work startsSetup script, dev container, copilot-setup-steps.yml
The pipe boardThe build graph (Nx, Bazel, Pants…)
One shared siteMonorepo
Separate yards across townPolyrepo
Who signs off each roomCODEOWNERS

The trap it saves you from

Migrating to a monorepo and expecting agents to improve on their own. Without scoped instructions, scoped tests and a graph, a bigger repository just gives the agent more to read.

7. Common mistakes

One giant root instruction fileEvery package's conventions in one file: the agent loads all of it for every task. Use a short root file plus one per package.
"Run all the tests"In a big repository the full suite times out. Give per-package or affected-only test commands.
No environment setupAgents that discover dependencies by trial and error waste their session. Preinstall them.
Letting the agent read generated and vendored codeIt fills the context with code nobody edits. Deny those paths.
Polyrepos without contractsAn agent changing one service can't see its consumers. Make the interface explicit and versioned.
Adopting Bazel for agents aloneIt's a large investment; its payoff is speed, hermeticity and graph queries at scale, not a better agent in a small repository.
Copying standards by hand across many repositoriesThey drift within months. Use a template repository and a shared plugin.

8. Hands-on lab (roadmap week 9)

  1. Score your repository with the checklist above and fix the two cheapest gaps.
  2. Split the instructions: a short root AGENTS.md, and one per package or major folder with its own build and test commands.
  3. Add environment setup: a setup script or dev container, and copilot-setup-steps.yml if you use Copilot's cloud agent.
  4. Make "what's affected?" answerable: try your build tool's affected or query command on a shared library. If you have none, note what an agent would need to find the consumers.
  5. Run the same cross-project task twice: once with the agent scoped to one package, once with the consumers available. Compare the result.
  6. Decide: write down whether your layout and build system are holding agents back, with evidence, before proposing any migration.

9. Self-check quiz

A monorepo has AGENTS.md at the root and in packages/api/. Which instructions win for a file in packages/api/?

The AGENTS.md standard: the nearest file takes precedence; explicit prompts override everything.

Whatever the layout, what most helps an agent judge a change's blast radius?

Monorepo build tools give you one as a side effect; polyrepos need contracts or a parsed cross-repository graph.

What does a monorepo give an agent changing a shared library that a polyrepo doesn't?

In a polyrepo it's a library release plus a PR per consumer, merged in order.

Which Bazel property helps agents most?

Plus caching and graph queries. The cost: BUILD files the agent must keep correct.

What is CMake?

It generates native build files; affected-project queries and remote caching need other tools.

Your agents struggle in your polyrepo estate. First step?

Instructions, setup, checks and contracts help in any layout; migrations are big bets that need evidence.

10. Go deeper

ResourceTimeWhy
Set up Claude Code in a monorepo or large codebase (Claude Code docs)20 minNested instructions, exclusions, sparse worktrees, code intelligence, per-package skills.
Get the best results from Copilot cloud agent (GitHub Docs)15 minInstructions files, copilot-setup-steps.yml, task scoping.
AGENTS.md (Agentic AI Foundation)5 minThe open format, its sections, and nested files in monorepos.
How Claude Code works in large codebases (Anthropic)15 minScoped test commands, LSP, ownership of the agent setup.
The monorepo advantage for AI agents (Victor Savkin, Nx, July 2026) and Monorepo vs polyrepo: the debate is measuring the wrong thing (Daniel Westgaard, Riftmap, June 2026)25 minThe two sides, each from a vendor with a stake.
Code intelligence as agentic tooling (Thoughtworks Radar, April 2026)3 minWhy agents should use language servers and codemods, not just text search.
Bazel, Buck2, Pants, Turborepo, CMake30 minEach build system in its own words.