CLAUDE-MD · context-engineering
CLAUDE.md section: Java service calling Bedrock
Drop-in CLAUDE.md conventions for a Java repo on Bedrock: Converse API first, one client factory, EU Geo model IDs, no hardcoded credentials.
✓ verified 2026-06-10 · stack: java, spring-boot, bedrock, claude-code · source
A CLAUDE.md section for any Java repository that calls Claude on Bedrock. It pins the decisions an agent would otherwise re-make differently every session: which Bedrock API, which model ID shape, how clients are constructed, and where credentials come from. Append it to your existing CLAUDE.md (or merge into the template from claude-md-java-service).
## Bedrock integration
- Use the **Converse API** (`converse`/`converseStream`) for all Claude calls. Never generate `InvokeModel` calls with model-specific JSON unless the feature genuinely isn't exposed via Converse — and say so in the PR description if you do.- Model IDs are **EU Geographic profile IDs**: `eu.anthropic.<model>` (e.g. `eu.anthropic.claude-sonnet-4-6`). Never a bare model ID, never a `us.` or `global.` prefix — this repo has an EU data-residency requirement.- Model IDs and region live in configuration (`application.yml`), not in code. Region is `eu-west-2`.- All Bedrock calls go through the existing `BedrockRuntimeClient` bean — never construct SDK clients inline. Streaming uses the `BedrockRuntimeAsyncClient` bean with `ConverseStreamRequest`.- Credentials come from `DefaultCredentialsProvider.create()` only. Never hardcode keys, never add `StaticCredentialsProvider`, never write credentials into config files or tests.- Always set `maxTokens` in `inferenceConfig` — no unbounded responses.
## Dependencies
- AWS SDK: `software.amazon.awssdk:bedrockruntime` (v2), version managed by the SDK BOM in `pom.xml`.- LangChain4j (if present): use the version pinned in `pom.xml`. Do not bump it to get a new model ID — raise it instead; new-model access can use the raw SDK with the model ID string.
## IAM expectations (don't fight these in code)
- The service role allows `bedrock:InvokeModel` / `bedrock:InvokeModelWithResponseStream` on a specific `eu.` inference profile plus the foundation model in the EU destination regions, and `bedrock:GetInferenceProfile`. An `AccessDeniedException` on a new model ID is an IAM/Terraform change, not a retry-or-workaround situation.- If invocations fail with a guardrail-related denial, the role enforces a required guardrail — include the guardrail ID in the request; do not remove it.What it does
- Stops the most common agent drift in Bedrock repos: regenerating
per-provider
InvokeModelJSON when the repo standard is Converse, and inventing new client construction instead of using the shared bean. - Encodes the EU residency rule at the place the model ID is typed, so a
generated example never quietly introduces a
us.orglobal.profile. - Tells the agent how to interpret IAM failures: the alternative is an
agent that “fixes” an
AccessDeniedExceptionby widening retry logic or swapping model IDs until one works.
Failure modes
- It is advisory. CLAUDE.md is prompt-space; under context pressure it can be missed. Back the credential and config rules with deterministic enforcement: a PreToolUse hook on config paths and IAM that denies non-EU profiles, per the policy hierarchy.
- The model ID example will age. When the team’s default model changes,
update the example ID here and in
application.ymltogether; a stale CLAUDE.md example is how old model IDs reappear in new code. - Repo-specific assumptions. The section assumes a Spring-style shared
client bean and a
pom.xml; adjust names for Gradle or non-Spring DI before committing, or the agent will hunt for beans that do not exist.
Verified against the Claude Code on Bedrock deployment-patterns guidance (Converse-first integration, credential and configuration discipline) and the AWS SDK for Java v2 Bedrock examples, 2026-06-10.