CLAUDE.md is easy to write when your codebase is small and you're the only contributor. One file, top of the repo, everything Claude needs to know about the project. Simple, and it works.
The story gets more complicated at scale. Once your monorepo has 15 packages, three languages, four teams, and a mix of legacy and new code, one CLAUDE.md doesn't fit. Neither does no CLAUDE.md. The right answer is a layered structure — but only if you're disciplined about what goes where.
This post is the pattern we settled on after running Claude Code in a ~120-package TypeScript monorepo for eight months. It doesn't claim to be the only way to structure CLAUDE.md at scale, but it's the one that survived contact with real projects and stuck.
The problem with one big CLAUDE.md
When we started, we had a single 800-line CLAUDE.md at the repo root. It covered everything: coding standards, deployment, tooling, per-package conventions, historical decisions. It was comprehensive, and it was almost useless.
The problem: Claude reads context that's relevant to the current task. Loading 800 lines of monorepo-wide guidance when the task is "fix this bug in the payments service" wastes context and dilutes signal. The high-signal 30 lines specific to payments were buried in 770 lines of stuff about other subsystems, the CI pipeline, and testing conventions for a package the user hadn't touched.
A useful CLAUDE.md tells Claude what it wouldn't have figured out on its own. Everything else is noise.
The layered layout that worked
The structure we ended up with:
repo-root/
├── CLAUDE.md ← Global: monorepo topology, cross-cutting standards
├── packages/
│ ├── payments/
│ │ ├── CLAUDE.md ← Package-specific: domain, patterns, gotchas
│ │ └── src/
│ ├── auth/
│ │ ├── CLAUDE.md ← Package-specific
│ │ └── src/
│ └── ...
├── services/
│ ├── api-gateway/
│ │ └── CLAUDE.md ← Service-specific
│ └── worker/
│ └── CLAUDE.md
└── infra/
└── CLAUDE.md ← Infrastructure-specificClaude picks up the CLAUDE.md in the directory tree from the current working file up to the repo root. If you're editing packages/payments/src/refund.ts, Claude sees packages/payments/CLAUDE.md plus the root CLAUDE.md. It doesn't see packages/auth/CLAUDE.md — which is exactly what you want.
What belongs at each level
Getting the layout right is easy. Getting the content boundaries right is harder. Our rules:
Root CLAUDE.md (60-100 lines max)
- Repo topology: where packages live, what each top-level directory contains
- Cross-cutting conventions: the standards that apply everywhere (naming, formatting, commit message format)
- Universal tooling: "we use pnpm, not npm"; "run tests with
pnpm test" - Non-obvious gotchas: historical decisions Claude wouldn't infer from the code alone
- What NOT to touch without human review: generated files, vendor directories, legacy paths in the process of migration
If root CLAUDE.md gets over 200 lines, something is misplaced. Either you're putting package-specific detail at the root, or you're over-documenting. Trim it down.
Package CLAUDE.md (30-80 lines each)
- Domain vocabulary: what specific terms mean in this package (a "cart" in payments is different from a "cart" in inventory)
- Package-specific patterns: how errors are handled here, how data flows, why certain shapes exist
- Test patterns: what fixtures exist, what mocking strategy is used, what edge cases matter
- Gotchas specific to this package: "the retry logic depends on this env var being set even in tests"
- What this package must NOT do: forbidden dependencies, don't-cross-the-streams rules
Service CLAUDE.md
- Deployment context: where it runs, what config it needs, health check semantics
- Upstream/downstream: what services it calls, what services call it
- Observability: where to find its logs, what metrics matter
- Failure modes: the known bad states and how to recognize them
Anti-patterns that made the monorepo worse
Some things we tried that made Claude's output worse, not better:
Anti-pattern: duplicating content across CLAUDE.mds
When we started building package CLAUDE.mds, we copy-pasted "we use TypeScript strict mode" into all of them. Result: contradictions when we changed the standard and forgot to update all copies. Fix: cross-cutting standards live at the root. Package-level files can reference them ("see root CLAUDE.md for TS conventions") but don't restate them.
Anti-pattern: aspirational content
One package CLAUDE.md described how the code "should" work after a planned migration. The migration hadn't happened. Claude followed the aspirational guidance, produced code that didn't match reality, and confused the whole review. Fix: CLAUDE.md describes what is, not what will be. Migrations and target states go in ADRs or design docs, not in living context files.
Anti-pattern: instructions Claude can't verify
Rules like "don't use inline styles" are useful. Rules like "match the coding style of the rest of the file" are noise — Claude does that by default, and the instruction just consumes tokens. Fix: only include instructions that (a) express a real constraint and (b) Claude wouldn't follow without being told.
For every line in a CLAUDE.md, ask: "if I removed this, would Claude get this wrong in a way that would matter?" If the answer is no, remove it. Ruthless.
Anti-pattern: CLAUDE.md as design doc
We had a package where CLAUDE.md included a long section on the design rationale for the current architecture. Interesting reading; wrong file. Claude doesn't need the "why" for most tasks — the file just got polluted with backstory. Fix: keep design rationale in docs/ or ADRs. CLAUDE.md gets the "what" and the "how" only.
Content patterns that worked
The invariants section
The most valuable pattern we found: an "Invariants" section listing the rules that must never be broken. Not conventions ("prefer X"), invariants ("never Y"). Short, specific, high-signal.
## Invariants
- All monetary values are stored as integers in cents. Never floats.
- Never call `db.query` directly from a handler. Use the repository layer.
- Never log full request bodies (they may contain PII).
- The `Order` type is immutable after creation. New states create new records.
- The `webhooks/` directory has separate auth. Do not import from `handlers/`.The "if you're about to..." section
Predictive guidance for the most common tasks. When you're about to add a new endpoint, add a migration, deprecate a field — the shape of what a well-formed change looks like.
## If you're about to add a database migration
- Create it in `db/migrations/` with the timestamp prefix format
- Every migration must be reversible (up and down)
- Test it against staging DB before merging
- Never modify a shipped migration — write a new one that fixes itKeeping CLAUDE.md fresh
The last problem: CLAUDE.md rots. Standards change, packages get reorganized, invariants get relaxed or tightened. If nobody updates the file, Claude keeps operating on stale guidance.
The pattern we run: a monthly cron workflow (see Claude Code in GitHub Actions for the shape) that cross-references every CLAUDE.md against the current code. Files that reference no-longer-existing paths, invariants that no longer hold, tooling instructions that use commands we've renamed — it flags all of these. Not automatic fixes; a report for human review.
Twice a quarter, one person on the team does a 45-minute CLAUDE.md review cycle, works through the flags, and updates or removes. Cost: low. Payoff: Claude's guidance stays trustworthy, which is more valuable than any specific instruction.
The shape of what scales
The version of CLAUDE.md that works at 3 packages doesn't work at 100. But the failure isn't "we need bigger files"; it's "we need better-shaped files." Layered, scoped, ruthlessly trimmed, describing what is rather than what should be. Any team getting into monorepo territory should think about this early — the cost of restructuring is higher once the files are the wrong shape than it would be to do it right the first time.
Get cctk running in one command
85 slash commands, 12 subagents, 12 MCP integrations, 12 hooks. All the patterns from this post are shipped in cctk.