OmniscioGuidesCLAUDE.md examplesJava and Spring Boot
CLAUDE.md for Java and Spring Boot
A Spring Boot repository has one structural decision above all others: the build system. Spring Boot's own documentation recommends a build system with dependency management that can consume artifacts from Maven Central, and names Maven and Gradle as the two, so a session needs to know which one it is looking at before it runs anything.
The file below settles that in the first block, then writes down the layer rules that a Java codebase enforces by convention rather than by compiler. Each block is explained underneath, with what was left out and why.
- The file, ready to copy.
- Why each block is there.
- What was left out, and why.
- Adapting it to Maven or a plain Java library.
Checked against Anthropic's Claude Code documentation and the frameworks' own docs on November 25, 2026. By the Omniscio team. Updated .
The file
This one describes a Spring Boot service with a Postgres database and Flyway migrations. Save it as ./CLAUDE.md or ./.claude/CLAUDE.md in the repository root.
# billing-api
Spring Boot service for invoices, payments and refunds.
Java 21, Gradle with the Kotlin DSL, Postgres.
## Commands
./gradlew bootRun
./gradlew test
./gradlew test --tests 'com.acme.billing.InvoiceServiceTest'
./gradlew check # unit tests plus Checkstyle
./gradlew spotlessApply
## Layout
- src/main/java/com/acme/billing/api/ controllers; HTTP only
- src/main/java/com/acme/billing/service/ business rules and transactions
- src/main/java/com/acme/billing/repo/ Spring Data repositories
- src/main/java/com/acme/billing/domain/ records, enums, value objects
- src/main/resources/db/migration/ Flyway; append only
- src/test/java/com/acme/billing/ mirrors main
## Rules
- Constructor injection only. No @Autowired on a field, and no new-ing a
collaborator inside a method.
- A controller validates, delegates and maps to a DTO. No business logic, no
repository calls.
- DTOs are records. An entity never leaves the service layer.
- @Transactional goes on the service method, never on a controller or a
repository. A read is @Transactional(readOnly = true).
- "Not found" is an exception mapped by one @RestControllerAdvice, not a null
return and not an empty Optional in the response body.
- Flyway migrations are append only. Never edit one that has run anywhere,
including on a colleague's machine.
- Log with the parameterised form: log.info("invoice {}", id). Never concatenate
a string, and never System.out.
## Testing
- JUnit 5. A unit test has no Spring context; @SpringBootTest is for wiring and
database tests only.
- Testcontainers for Postgres. H2 is not the same database and hides the bugs
that matter.
- Test names read as sentences: rejectsPaymentWhenInvoiceIsVoid().
- A bug fix starts with a test that fails before the fix.
## Traps
- The Gradle wrapper is the build. Run ./gradlew, never a system gradle.
- An entity change reaches the schema only through a new Flyway migration.
- Lombok is not on the classpath. Do not add it.That is 52 lines. Most rules are phrased as boundaries rather than as taste, because a boundary is the part a reviewer can check.
Why each block is there
The title line and the build
The build system goes in the first block because it decides every command that follows. Spring Boot's documentation recommends a build system that manages dependencies and consumes Maven Central artifacts, and names Maven or Gradle; a session that guesses wrong writes instructions nobody can run.
The commands are named in their wrapper form, ./gradlew, because that is the one pinned to this repository rather than to whatever Gradle a machine happens to have installed. The single-test command gives "run the tests" a cheap answer on a large suite, so a session has a reason to run it while it works instead of skipping the check.
The layout
The paths follow the standard source sets: production code under src/main/java and tests under src/test/java, which is where the Java plugin looks by default. Only the package split inside them is this project's own decision, so that is what the file spells out.
Each package gets three or four words, not a paragraph. Anthropic's size target is the reason: a layout nobody can skim spends context and buys nothing.
The rules
Every rule here is one a reviewer has had to write down at least once. The controller sentence is the best example: "validate, delegate, map to a DTO" tells a session what the file may contain, which is checkable, where "keep controllers thin" is not.
We name the layer rather than the style, because a layer is what a reviewer can check. Moving a @Transactional off a controller is a one-line fix, but deciding which layer owns it can become a design debate; naming the layer upfront skips the debate.
The logging rule is in the file because a concatenated log line is the default a session writes, and it is invisible in review until somebody greps for it. Naming the parameterised form, with an example, is the concrete shape Anthropic asks for.
Testing
"A unit test has no Spring context" is the rule that keeps a suite fast. Without it, the cheapest way to test a service is to start an application context, and a suite that does that for every class is how a full run reaches minutes.
The sentence-shaped test names are a small convention with a large effect: a failing report reads as a sentence, so the failure explains itself before anyone opens the file.
Traps
All three traps are decisions this repository enforces by convention rather than by the compiler. The wrapper is in the tree, the Lombok rule is a choice, and the migration rule is the one that costs you a production incident if nobody writes it down, which is the kind of fact Anthropic says a CLAUDE.md should hold.
What was left out, and why
- A rule that only matters in one package. That belongs in a path-scoped rule under
.claude/rules/, which loads only when Claude touches a matching file. - The dependency list. It lives in
build.gradle.kts, and a version in a CLAUDE.md would be a second copy of something the build already decides. - Spring's own conventions. A session does not need to be told what
@RestControllerdoes; it needs to be told which package it belongs in. - The release procedure. A multi-step runbook belongs in a skill, not in context every session.
- Personal database URLs and test accounts. Those go in
CLAUDE.local.md, which is not committed. - "Follow SOLID." Nobody can check it in a diff, and the specific boundaries above already say what it would mean here.
Adapting it
- Maven. Replace every
./gradlewcommand with itsmvnwequivalent, and replace the layout's Gradle source-set note with the same paths, which Maven uses by convention too. - A plain Java library. Drop the controller, transaction and migration rules, and add what a library needs instead: what counts as a breaking change, and where the public API lives.
- A different Java version. Change the one number in the title line, and check whether your project can use records, which is why the DTO rule mentions them.
Then prove it loaded. /context all lists the memory files read at launch, and a file that is missing from that list is not being ignored; it is not being seen.
How this page was written
The guidance on what belongs in a CLAUDE.md, how long it should be and how Claude treats it was read from Anthropic's Claude Code memory documentation on November 25, 2026. The statements about Spring Boot and Gradle were read from their own documentation the same day, and every claim about them is quoted from those pages.
The example file was written for this page and was not run against a live service. Every line is meant to be checked against your own repository before it is kept, which is why the adaptation steps below are worth working through before you keep it.
Sources
- Anthropic's How Claude remembers your project, for what belongs in a CLAUDE.md, the size target, the "concrete enough to verify" rule and the conflict rule, read November 25, 2026.
- Spring Boot, Build systems, for the recommendation of a dependency-managing build system and the Maven or Gradle choice, read November 25, 2026.
- Gradle, The Java Plugin, for the
src/main/javaandsrc/test/javasource sets, read November 25, 2026.
Common questions
What should a CLAUDE.md for a Spring Boot project contain?
The Gradle or Maven commands you actually run, the package layout and what each layer may import, the rules that keep transactions and HTTP at the right layer, and the traps: the wrapper is the build, migrations are append-only across every machine, and Lombok is deliberately absent. Anthropic's target is under 200 lines, so the framework's own conventions stay out.
Should the CLAUDE.md say Maven or Gradle?
Name the one the project uses and give the exact commands, wrapper included. Spring Boot's documentation recommends choosing a build system that supports dependency management and can consume artifacts from Maven Central, and names Maven or Gradle as the two; which one your repository uses is a fact Claude cannot infer from a Java file, so it belongs in the file.
How do I stop Claude putting business logic in controllers?
Write the controller's whole job as a sentence: validate, delegate, map to a DTO. Rules phrased as a boundary are followed more reliably than advice about clean architecture, and a reviewer can check the rule in a diff. The same applies to transactions: name the layer they belong to rather than saying the code should be well structured.
Does this file work for a plain Java project without Spring?
Most of it. Drop the controller and transaction rules, keep the package layout, the test naming, the logging rules and the build commands, and replace the Flyway trap with whatever your project uses to change the schema. The shape of the file is the same: commands, layout, rules and traps.
One instructions file, every agent that reads one
Omniscio keeps your canonical CLAUDE.md or AGENTS.md mirrored to the filenames Codex, Gemini, Cursor and Copilot look for, and flags a copy that was edited outside it. Any model, any harness.
The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.