CLAUDE-MD · context-engineering

CLAUDE.md template: Java service on AWS

A lean, layered CLAUDE.md for a Spring Boot/Quarkus service: commands first, judgment calls second, zero rules a hook should own.

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

CLAUDE.md
# <service-name>
Spring Boot 3 service. Java 21. Gradle.
## Commands
- Build: `./gradlew build`
- Test: `./gradlew test` (unit) / `./gradlew integrationTest` (Testcontainers)
- Run locally: `./gradlew bootRun` (needs Docker for LocalStack)
## Architecture
- Hexagonal: `domain/` has no framework imports; adapters live in `infra/`
- One module per bounded context; see `docs/architecture.md`
## Judgment calls (things a linter can't decide)
- Prefer constructor injection; no field injection even in tests
- New AWS calls go through the existing `AwsClients` factory — never construct SDK clients inline
- Flyway migrations are append-only; never edit an applied migration

Keep mechanical rules (formatting, imports, licence headers) out of CLAUDE.md: they belong to Spotless and Checkstyle, enforced by the format-on-edit hook, the Checkstyle gate, and CI. The allocation logic is the linters pattern.

Two companions the template assumes:

  • Path-scoped rules go in .claude/rules/ rather than this file: a markdown rule with paths: "src/test/**/*.java" frontmatter loads only when Claude works with matching files, so test conventions stop taxing every session (memory docs).
  • Personal context goes in CLAUDE.local.md (gitignored): sandbox account URLs, local test-data paths, your own shortcuts. It appends after the committed file at the same level, so individual context never churns the team template.

What it does

  • Holds the file to the three sections an agent needs on every turn: copy-pasteable commands, architecture facts, and judgment calls a tool cannot verify, well under Anthropic’s 200-line-per-file guidance, which exists because longer files reduce adherence.
  • Every rule is falsifiable (“no field injection even in tests”), so a reviewer, human or agent, can tell whether it was followed.
  • Encodes the enforcement boundary by omission: nothing in it duplicates what Spotless, Checkstyle, or ArchUnit already decide, so the agent never receives prose that contradicts a tool.

Failure modes

  • It is advisory. CLAUDE.md is prompt-space at 70–90% compliance; the Flyway and AWS-client rules need a deterministic backstop if they must always hold. See the policy hierarchy.
  • It will accrete. Procedures and reference material that creep in belong in skills or .claude/rules/; apply the audit in CLAUDE.md architecture before the file passes 200 lines.
  • Placeholders ship if unedited. <service-name>, the Gradle commands, and the factory/bean names are this template’s assumptions: adjust for Maven or non-Spring DI before committing, or the agent hunts for things that do not exist.

Verified against the memory docs’ hierarchy, .claude/rules/, and CLAUDE.local.md behaviour, 2026-06-10.