SETTINGS · deterministic-policy

Settings: standards enforcement for a Java service

The .claude/settings.json that wires the standards stack: Spotless format hook, Checkstyle gate, build-tool allows, and deny rules for generated output.

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

The committed project settings that make the linters-as-ground-truth stack actually fire: Spotless auto-fix on every Java edit, the Checkstyle gate feeding violations back, the build loop pre-approved so neither hook’s underlying tool ever stalls a session, and deny rules keeping generated sources out of context. It is the standards-focused sibling of the day-one baseline (same shape, narrower purpose) and deliberately carries no security posture: on an AWS-credentialled workstation, merge these hooks into the cautious permission profile rather than running this file alone.

.claude/settings.json
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(./gradlew *)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(git add *)",
"Bash(git commit *)"
],
"deny": [
"Read(./build/generated/**)",
"Read(./target/**)",
"Read(./**/*.generated.java)"
]
},
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path' | { read f; case \"$f\" in *.java) \"${CLAUDE_PROJECT_DIR}\"/gradlew spotlessApply -PspotlessIdeHook=\"$f\" --quiet ;; esac; }"
},
{
"type": "command",
"command": "\"${CLAUDE_PROJECT_DIR}\"/.claude/hooks/checkstyle-gate.sh"
}
]
}
]
}
}

Commit this together with .claude/hooks/checkstyle-gate.sh from the gate artifact. Maven teams: swap the Gradle allow and the hook commands for their Maven equivalents (the gate artifact includes the Maven variant).

What it does

  • Formatting is auto-fixed, style is fed back. The first hook runs Spotless single-file on every Java edit (mechanics and failure modes in format-on-edit); the second runs the Checkstyle gate, which exits 2 with violations on stderr so Claude fixes them in-session. Together they enforce the auto-fix/report split the linters pattern prescribes, at 100% compliance, not prompt-space’s 70–90%.
  • The loop never prompts. Bash(./gradlew *) covers the builds, tests, and spotlessApply runs the agent performs itself; the git subset covers the read-and-commit loop. git push is deliberately absent: pushing is a decision, so it prompts.
  • Generated code stays out of context. Deny rules on build/generated/, target/, and *.generated.java stop the agent reading (and then imitating or “fixing”) code that a tool will overwrite on the next build. Standards apply to sources, not outputs.
  • Monorepo note. In a multi-module repository, add a baseline claudeMdExcludes here for commonly-irrelevant module directories; individuals extend it in settings.local.json and arrays merge across scopes. See standards in monorepos.

Failure modes

  • Hook ordering is not guaranteed. Both hooks match the same event; do not assume Spotless completes before the gate runs. This is safe while checkstyle.xml contains no formatting modules: Spotless owns layout. If yours does, chain both commands in a single script to force the order.
  • No security posture. No credential-path denies, no sandbox, broad Gradle allow (any task, including publish tasks, is covered: narrow to Bash(./gradlew build*) and friends if your build can reach a remote repository). Layer onto the cautious profile for the full posture.
  • Two JVM-backed hooks per edit. On large modules the gate’s source-set run dominates edit latency. The gate artifact’s failure modes cover the mitigations (Maven single-file scoping, or demoting the gate to CI).
  • jq absent breaks both hooks quietly. Non-blocking errors mean edits proceed unformatted and ungated. Assert command -v jq at onboarding or in a SessionStart hook.
  • This file is policy: gate changes to it. Anyone who can merge to .claude/ can weaken the gates; put it behind CODEOWNERS per CI as the outer gate.

Verified against the settings file reference (permissions, hooks key, scope merging) at code.claude.com/docs/en/settings, 2026-06-10.