CLAUDE-MD · context-engineering

CLAUDE.md template: Java monorepo root

A root CLAUDE.md that is a map, not a manual: module index, cross-cutting constraints, commit conventions, and delegation to per-module files.

✓ verified 2026-06-10 · stack: java, claude-code · source

The root file for a Java microservices monorepo. It answers exactly four questions (what is this repo, how is it laid out, what conventions cut across modules, where is everything else decided) and delegates all stack-specific content to per-module CLAUDE.md files, which load on demand when Claude works in those directories. The per-module shape is the Java service template; the reasoning is the monorepo pattern.

CLAUDE.md
# Acme platform monorepo
Java microservices. Services under `services/`, shared libraries under
`libs/`. Each module has its own Gradle build — run commands from the
module directory, not the root.
## Cross-cutting constraints
- All modules target Java 21 on Amazon Corretto
- Commit format: `<type>(<module>): <summary>` — type is
feat|fix|chore|refactor|test|docs
- Never commit secrets; a pre-commit hook blocks `.env` writes
- Shared code changes land in `libs/` with their own PR — never copy
classes between services
- New AWS clients come from the `AwsClients` factory in `libs/common-aws`;
never construct SDK clients inline
## Module index
Each module has its own CLAUDE.md with stack, commands, and judgment
calls. Read it before working in that module.
- `services/user-service` — user management, IAM integration
(Spring Boot 3, PostgreSQL)
- `services/order-service` — order lifecycle (Spring Boot 3, DynamoDB)
- `services/billing-service` — invoicing, payment adapters (Quarkus)
- `libs/common-aws` — shared AWS client factories
- `libs/test-fixtures` — Testcontainers bases and test data builders
## Where rules are decided
- Formatting and imports: Spotless, applied by hook and gated in CI —
never discussed in prose
- Style: Checkstyle, config at `config/checkstyle/checkstyle.xml`
- Architecture boundaries: ArchUnit tests per service — do not suppress
violations
- Module conventions: that module's CLAUDE.md
<!-- Maintainers: keep this file under 80 lines. Module detail belongs in
the module's CLAUDE.md; procedures belong in skills. HTML comments
like this one are stripped before injection and cost no tokens. -->

What it does

  • Loads everywhere, cheaply. Files above the working directory load in full at launch, so this map is in context for a session started in any module. At roughly 40 lines, it costs little and orients every session.
  • Lists module files instead of @importing them. @path imports expand inline at launch, which would pull every module’s content into every session, exactly what the two-level model exists to prevent. Plain path references preserve on-demand loading: a module’s CLAUDE.md enters context only when Claude reads files there.
  • Points at enforcement rather than restating it. The “where rules are decided” section tells the agent which violations are tool-owned, so it fixes the failing check instead of negotiating with prose. The tooling is wired in settings-standards-enforcement.
  • Carries maintainer guidance for free. HTML comments are stripped before injection, so the size discipline is documented where editors will see it without spending tokens.

Failure modes

  • The index rots. A renamed or new module that is not reflected here sends the agent exploring (cheap) or, worse, following stale descriptions (expensive). Make updating the index part of the definition of done for adding a module; a CODEOWNERS entry on CLAUDE.md keeps changes reviewed.
  • It will try to grow. Every incident produces a candidate rule. Apply the test from the architecture pattern: if it is module-specific it goes in the module file; if a tool can verify it, it goes in a linter; if it is a procedure, it becomes a skill.
  • Compaction favours this file over module files. After /compact the project-root CLAUDE.md is re-injected but nested module files are not: a long session inside one module can lose that module’s context until Claude touches its files again. Keep module files short so the reload is cheap.
  • It is advisory. Like all CLAUDE.md content, this is prompt-space at 70–90% compliance. The commit format and secrets rules it states need deterministic backing. See the deterministic policy pillar.

Verified against the memory docs’ hierarchy, load-on-demand, @import, and HTML-comment behaviour, 2026-06-10.