Notes

AIClaude CodeMonorepo

Running a monorepo with coding agents

Specialist agents, skills, hooks that enforce the rules, and one command from ticket to draft PR. What worked when coding agents became part of daily work on a large monorepo.

Applies to
Teams using Claude Code or a similar agent every day on a large monorepo.
Verified with
The agent setup I built and ran on an Nx monorepo from February to November 2026. Usage figures are from my own session logs.

I set up how coding agents worked on a large Nx monorepo: web, mobile and about thirty deployable apps on one database schema. Rules I wrote in a prompt got followed some of the time. Hooks fired every time. So anything that mattered ended up as a hook or a check.

What the agents actually followed

For a while I wrote rules into CLAUDE.md and hoped. Then I measured, using my own session logs:

So I stopped relying on the model's judgement for anything I cared about, and moved it into hooks.

Hooks around every tool call

A hook is a script Claude Code runs before or after a tool call. Mine are short bash scripts: they read the call as JSON, and to block it they exit with code 2 and print what the agent should do instead. The agent reads that message and retries the right way.

CallerWhen the agent tries toThe hook
Skill gateedit a governed file, like the schema, permissions or a formblocks the first edit until the matching skill has run, then lets the retry through
Protectionedit env files, lockfiles or generated code, or run a destructive database commandblocks it outright
Agent routinghand work to a generic subagentrefuses and prints the table of specialists
Knowledge firstsearch the knowledge base or schema by handasks for a knowledge-graph query first
After a writefinish editing a fileruns the formatter, and reminds once to regenerate the API client after an API change
Five kinds of hook. The skill gate does the most work: the right instructions get loaded exactly when they're needed.

A few things I learned building them:

Settings back the hooks up: force pushes and commit --no-verify are denied outright.

Short instructions, loaded where they're needed

The always-loaded root CLAUDE.md went from 497 lines to 155. Everything topic-specific moved into skills that a hook loads at the right moment, and command lists went away, because the agent can read package.json itself. Each package has its own short CLAUDE.md for the rules that only apply there.

  1. Root CLAUDE.mdalways loaded: layers, conventions, pointers
  2. Package CLAUDE.mdloaded where the agent is working
  3. Skillsabout 40, loaded on demand or forced by a hook
  4. Agent memorylessons each specialist keeps
  5. Knowledge basepast decisions and incidents, queried through a graph
Layers of instruction, from always loaded to looked up. Most of the detail lives in skills.

I also rewrote rules as what to do, rather than what not to do. Telling a model not to do something mentions the thing you don't want, which makes it more likely.

Specialist agents

Nine in-house agents: builders for backend, web UI, mobile, database and CI, reviewers for a whole branch, a single task and mobile design, and an impact analyser for "what does this change break". Each builder carries its own conventions and memory. When I counted, three security agents had never been picked in 177 sessions, so they became skills instead, and the agent list got much shorter.

One command from ticket to draft PR

/implement takes a ticket to a draft pull request. It wraps an off-the-shelf brainstorm, plan and build workflow with the steps specific to our repo:

  1. Read the ticket backand stop until someone says yes
  2. Branch and set uplocal setup runs in the background
  3. Check the knowledge basepast decisions and incidents first
  4. Plana decision record (ADR) drafted with the design, if the change is architectural
  5. Implementspecialists per lane: backend, web, mobile, database, CI
  6. Test and verifyautomated checks, each task reviewed before the next
  7. Review the branchon a stronger model
  8. Draft PRready for a person to review
  9. Decision record to the knowledge basereconciled after merge, so the next design starts from it
The pipeline. A person approves the start, chooses which checks run, and reviews the draft.

The details that made it trustworthy:

Parallel agents without collisions

To run several agents at once, each one gets its own git worktree, created by a hook. A small CLI gives up to six of them their own database, cache namespace and ports, so they never trip over each other.

What I'd tell anyone starting

Rules in a prompt
  • followed when the model remembers
  • drift between model versions
  • grow until nobody reads them

Fine for preferences

Rules in hooks and checks
  • fire every time the situation comes up
  • say exactly what to do instead
  • keep the always-loaded prompt short

Use for anything that matters

Where to put a rule depends on what happens when it's ignored.

Measure before you add another instruction. Count what your agents actually use, cut what they don't, and turn the rules you can't afford to have ignored into hooks. The same goes for verification: the checks are only worth something if they can actually fail.