Under the hood : the harness I used to keep Claude Code on spec
A practical harness for keeping Claude Code honest - built from skill packs, file locks and failed builds.
The Problem Nobody Talks About
In late 2025, I handed Claude Code a requirements document and asked it to build a small security demo: two Spring Boot services that sign and encrypt messages using JOSE. Nothing exotic. A few endpoints, some key generation, a couple of integration tests.
Claude wrote code fast. Too fast! Within an hour it had scaffolded a Maven multi-module project, picked library versions, and started implementing features. It also added OAuth2 (which I'd explicitly banned), pulled in a JWT library, and "helpfully" refactored my acceptance tests to make them pass.
This is the core tension with AI coding agents in 2026. They're genuinely useful & faster than any human at boilerplate, tireless at refactoring - but they optimize for looking done, not being correct. A prompt that says "don't use OAuth2" is a suggestion. And you won't know until something breaks.
The fix isn't a better prompt. It's a harness: a set of automated checks that make bad outcomes impossible rather than discouraged. This post is the story of building that harness - what worked, what failed, and what I'd do differently.
If you're a developer, you'll find concrete scripts and prompts you can steal. If you're not, the core lesson applies to any AI workflow:
Background
Claude Code is Anthropic's command-line coding agent. You point it at a repository, give it a task, and it reads files, writes code, runs tests, and commits changes—all through natural language.
That autonomy is also the problem. An agent with shell access can:
- Edit files you meant to protect
- Add dependencies you explicitly banned
- Weaken tests to make a build pass
- Merge tasks that should stay separate
- Commit work you haven't reviewed
For a hobby project, you might not care. For anything resembling production code - you care a lot.
The demo in question is a Maven multi-module Spring Boot 4 project on Java 25. It has four modules:
- Shared jose-common library
- Downstream-app (port 8081)
- Client-app (port 8080)
- Black-box acceptance-tests module
Both applications generate public-private key pairs and retrieve each other's public keys through JWKS endpoints. That distinction matters because the objective was to demonstrate signing, encryption and key distribution without introducing a broader authentication framework.
With the application defined, the next challenge was setting up Claude Code to work within those boundaries.
The Setup
1. Two skill packs, two different responsibilities
I couldn't find a single skill pack that covered both disciplined agent-assisted development and the specific Spring Boot conventions I needed.
So I used two -
- Addy Osmani's agent-skills - This provided the development workflow:
- /interview-me – clarify requirements through questions.
- /spec – turn requirements into a specification.
- /plan – break the specification into implementation tasks.
- /build – implement individual tasks.
- Source-driven development – verify APIs against official documentation rather than guessing.
- Review
- SivaLabs Spring Boot skill - This provided Spring Boot-specific conventions, including project structure, Maven configuration and implementation patterns.
I installed both, then spent an hour reading their contents. This is important: Claude treats skill files as instructions. If a skill pack says "use Spring Data JPA for persistence," the agent will try. You need to know what you're feeding it.
The Spring pack, for instance, includes references for Spring Data JPA, Spring Modulith, and Thymeleaf - none of which belong in a JOSE demo. Rather than fork the pack (which would break updates), I layered three defenses:
CLAUDE.md: Explicitly told Claude which skills and references were out of scope- Dependency checks: A script that fails if prohibited dependencies appear in the Maven dependency tree.
- Architecture tests: ArchUnit rules that prevent application code from depending on prohibited packages.
Key Learning :
Don't blindly install a third-party skill pack and assume everything inside it is appropriate for your project. Read the skill files before using them. Claude treats their contents as instructions, and those instructions can influence its implementation decisions. The instruction is advice. The checks are enforcement!
2. The most important part: making locked files actually locked
I wanted certain files to be controlled exclusively by me-
- The engineering harness itself
- The application specification
- The acceptance tests
Because if Claude can modify the requirements or the tests that validate those requirements, it can potentially make an incorrect implementation appear correct.
I introduced a human-maintained file called .claude/locks. It contains patterns for files that the agent must not modify.
An example:
1 # .claude/locks: human-owned. One glob per line.
2 .claude/*
3 scripts/hooks/*
4 scripts/locks.sh
5 .gitattributes
6 docs/spec/*
7 acceptance-tests/*
The list grows as the project progresses. After Phase 0, the harness is locked. After Phase 1, the specification is locked. After Phase 2, the acceptance tests are locked.
I implemented four complementary mechanisms -
a. File fingerprinting
The scripts/locks.sh script supports two operations:
- record: Calculates and stores fingerprints of protected files.
- check: Recalculates fingerprints and compares them with the recorded values.
If a protected file changes, the check fails. It also ignores line-ending differences, which is important when working across Windows and Linux environments.
b. PreToolUse guard hook
Claude Code supports hooks that run before certain tool operations. I used a PreToolUse hook to intercept:
- Edit
- Write
- MultiEdit
- NotebookEdit
Before allowing an operation, the hook checks whether the target file matches a protected path. If it does, the operation is blocked and logged in .claude/guard.log.
c. Built-in deny rules
I added another layer through .claude/settings.json. These rules prevent editing .claude/**. This is additional protection for the harness itself.
d. Stop hook
I also used a Stop hook. When Claude attempts to finish its turn, the hook runs verify.sh. If verification fails, Claude is not allowed to finish normally. There is one exception: documentation-only changes skip the full Maven verification, so that the requirements interview doesn't trigger a complete build after every answer. The Stop hook is useful, but it has an important limitation: a green build doesn't necessarily mean the implementation is correct.
It only means the checks you have defined are passing.
What about shell commands?
There is an intentional gap. The PreToolUse hook protects file-editing tools, but Claude still needs shell access to run Maven and other commands. A shell command could modify a protected file without going through the edit hook. That's why I also run the fingerprint check during verification. The hook prevents the easy route. The fingerprint check catches changes that bypass it.
For a team environment, I'd take this further by moving fingerprint checks into CI and protecting important paths using branch protection rules.
To deliberately unlock a file, I follow a controlled process:
- Comment out its entry in
.claude/locks - Make the required change
- Bump the specification version where applicable
- Run
./scripts/locks.shrecord. - Commit with the reason for the change.
That's how the three observability requirements were introduced in specification version 1.1.
3. One command defines what 'done' means
A common problem with AI-assisted development is that the agent can declare a task complete simply because it has finished writing code. I wanted a more objective definition. For every task, two commands must pass:
1 ./scripts/verify.sh
2 ./scripts/accept.sh <task's REQ tags>
verify.sh runs four steps and stops at the first failure:
locks.shcheck - no locked file has changedcheck-deps.sh- the dependency tree is clean (no OAuth2, no JWT libraries, no JPA, no Thymeleaf)mvn -q verify- every module compiles, unit tests pass, ArchUnit rules hold, JaCoCo coverage floor is mettrace.sh- every requirement ID inSPEC.mdhas at least oneJUnit @Tagin the acceptance tests, and every tag names a requirement that exists.
The Stop hook runs verify.sh automatically when Claude tries to finish its turn. If the build is red, Claude can't stop. (It's skipped when only .md files change, so the spec interview doesn't trigger a full Maven build after every answer.)
I proved the checks were real before trusting them. I added a class in jose-common holding a com.nimbusds.jwt.SignedJWT field—the build failed. I added spring-boot-starter-data-jpa to a pom - the build failed again. A rule you haven't seen fail isn't a rule yet.
4. The development workflow: from requirements to working code
Rather than asking Claude to build the application in one go, I divided the work into distinct phases. Each phase had a specific objective and a clear output. I also stored the prompts in the repository under docs/prompts/.
Before starting a new phase, I used /clear so that the agent started with a clean context and loaded only the files relevant to that phase.
Phase 0: Scaffold and Guardrails
The first instruction was deliberately restrictive.
No feature implementation.
1 Phase 0: scaffold and guardrails only. NO feature code. Read docs/input/REQUIREMENTS.md.
2
3 1. Maven multi-module with ./mvnw: parent + jose-common, downstream-app (8081), client-app (8080),
4 acceptance-tests. Latest GA Spring Boot 4.x, Java 25, latest nimbus-jose-jwt. Use
5 source-driven-development: confirm versions from official sources and do not guess. Each app has
6 only an Application class and config properties jose.peer.jwks-url and server.port.
7 2. CLAUDE.md (<80 lines): stack, commands, hard rules (no OAuth2, no JWT, no com.nimbusds.jwt),
8 workflow (one task at a time; Definition of Done = verify.sh + the task's acceptance tags green),
9 "never edit locked files (.claude/locks); if one seems wrong, STOP and explain",
10 "ignore frontend/browser/a11y/webperf skills", and that the spring-boot skill's JPA, Modulith
11 and Thymeleaf references do NOT apply. Point to the docs below.
12 3. CONSTRAINTS.md: JaCoCo floor 85% line coverage for jose-common, banned deps/APIs, algorithm
13 allow-list (ES256, ECDH-ES+A256KW, A256GCM), "never weaken, skip or delete a test to go green".
14 4. docs/CONTEXT.md glossary; docs/adr/0001-plain-jose-no-jwt, 0002-ec-p256, 0003-sign-then-encrypt,
15 0004-jwks-on-both-sides (status: Proposed); docs/PROGRESS.md.
16 5. ArchUnit tests in every module (bans listed above; only jose-common may use com.nimbusds.jose..;
17 controllers must not touch key material).
18 6. Scripts (bash, LF, must run in Git Bash on Windows and on Linux/macOS): check-deps.sh,
19 trace.sh, accept.sh [TAG...], verify.sh.
20 7. Do not modify .claude/, scripts/hooks/, scripts/locks.sh or .gitattributes. Do not commit.
21 Done when ./scripts/verify.sh passes. Show me the tree and stop.
Phase 1: Interview and Spec
This was one of the most important decisions in the entire process. Instead of asking Claude to immediately write a technical specification from the initial requirements, I used /interview-me. The agent asked questions one at a time, starting with the open questions.
Only after the requirements were sufficiently clear did I ask it to generate docs/spec/SPEC.md using /spec
Requirement IDs are grouped. Each has a MUST or MUST NOT along with Given/When/Then. The test tag equals the requirement ID. The spec lists what's out of scope (OAuth2, JWT, key rotation, mTLS, persistence)
I also defined three boundaries for the agent:
- Always
- Ask first
- Never
Phase 2: Acceptance Tests, All Failing
These are black-box tests only. They don't depend on jose-common, and they build every JOSE object directly with Nimbus. Both apps start as separate JVM processes from their packaged jars on free ports. For negative tests, the test plays the client: it serves its own JWKS from a JDK HttpServer and points the downstream app at it.
Done meant every test fails for a behavioural reason (a 404 or a failed assertion), not because of a compile or startup error. This helped establish that the tests were checking actual application behaviour rather than merely detecting incomplete project setup.
Phase 3: Plan
I used /plan to convert the specification into docs/plan/TASKS.md. The objective was to create small, independently verifiable implementation tasks.
Each task included:
- Requirement IDs it addressed
- Files it was expected to modify
- Unit tests to be added
- The exact commands required to verify completion
The smaller the task, the easier it is to understand what changed and why. More importantly, it makes code review substantially easier.
Phase 4: Build one task at a time
This was the actual implementation phase. For each task, I used /build with a relatively restrictive prompt.
1 /build T<n> from docs/plan/TASKS.md.
2 - Load only CLAUDE.md, CONSTRAINTS.md, the task and its REQs.
3 - Unit tests first (red) -> implement (green) -> refactor.
4 - Confirm every Nimbus API you use against the Nimbus docs/javadoc, especially deferred
5 crit params on the verifier. Cite the sources in docs/PROGRESS.md.
6 - Done when: ./scripts/verify.sh && ./scripts/accept.sh <task tags> are green.
7 - Tick the task in TASKS.md and update PROGRESS.md.
8 - If this task cannot be completed or verified on its own, STOP and explain before writing
9 code. Do not merge tasks.
10 - Do not commit. When done, stop and tell me the REQ-IDs covered.
11 If a locked file blocks you or looks wrong: STOP and explain. Do not work around it.
Note - The last two instructions weren't in the first version: "do not merge tasks" and "do not commit." Both were added after the agent merged T1 and T2 (more on that below).
5. How Much Freedom the Agent Had
Claude Code's permission mode decides how much the agent can do without asking. I changed it for each phase instead of picking one for the whole run.
| Phase | Mode | Reason |
|---|---|---|
| Scaffold | Plan first, then accept edits | Wrong versions and module layout get baked in here. Review the plan, then let it write. |
| Interview & Spec | Default | It's a conversation that ends in one file. |
| Acceptance Tests | Plan first, then accept edits | Reviewing a list of tests is cheaper than reviewing 30 test files. |
| Task Plan | Default | The output is already a plan.. |
| Routine build tasks | Accept edits | I review each finished task anyway. |
| ! JWS verification, replay and crit handling, nested JWE | Security-critical, and exactly where an agent guesses library APIs. | |
| Reviews and shipping | Default | The reviewers are read-only, and I want to see every fix. |
Accept-edits mode only auto-approves file edits. The guard hook, the deny rules, and the Stop hook still run, and shell commands outside the allow-list still ask first. I never used --dangerously-skip-permissions. It removes the allow and deny rules, leaving only the hooks and my review. For me
Speed is useful only when it doesn't come at the cost of losing control over what is changing
6. Human in the Loop: the agent doesn't commit
One of the decisions I made was to keep commits under my control. From T3 onwards, Claude stopped after completing a task. I staged the changes, ran my review checklist, and committed only after approving them.
The review process covered several things -
1 PREV=t2-ok; TASK=t3
2 TAGS="<REQ tags of ALL completed tasks, including this one>"
3
4 git add -A # stage everything, new files included
5 git diff --cached --stat # scope: files and size match the task
6
7 # protected paths untouched: must print nothing
8 git diff --cached --name-only -- .claude scripts/hooks scripts/locks.sh docs/spec acceptance-tests .gitattributes
9
10 ./scripts/locks.sh check && echo "locks OK"
11
12 git diff --cached --name-only -- docs/plan/TASKS.md docs/PROGRESS.md # bookkeeping updated
13 git diff --cached -- '*.java' # the actual review: read the code
14
15 ./scripts/verify.sh && ./scripts/accept.sh $TAGS # run it yourself; TAGS unquoted on purpose
16
17 git commit -m "T3: <summary> [<REQ-IDs>]" && git tag "${TASK}-ok"
Two details matter the most here -
accept.shgets the tags of every completed task, not just the current one, so a later task that breaks an earlier one fails immediately- Each approved task is tagged, so the next review diffs from the last approved state instead of
HEAD~1
To reject a task: git reset --hard "$PREV", then git clean -nd to see what would be deleted, then git clean -fd. Then /clear and run the build prompt again with feedback.
Key Learning
T1 generated keys; T2 published them. T1's acceptance tests could see the keys only through the JWKS endpoint, so T1 could never go green on its own. Claude merged the two tasks and explained why in the commit message.
Its reasoning was right; the process wasn't. It made a scope decision without asking. The root cause was my plan. Before T3, I had the agent audit every remaining task with one question: can its tests pass using only this task and the ones before it? I approved a re-slice, then added "stop, don't merge" and "don't commit" to the build prompt.
Conclusion: Harness is the key
The most useful thing I built for this demo wasn't the JOSE code. It was the harness around it: the lock file, the dependency checker, the acceptance tests, the review checklist.
An AI assistant can make changes much faster than a human developer. But speed also means it can introduce architectural drift, unintended dependencies, sloppy code and subtle implementation mistakes much faster. The solution to this, is not about writing longer prompts or asking the agent to be more careful.
It's to build a harness where important constraints are independently verified. Let the AI handle the implementation work where it adds value. Keep architectural decisions, acceptance criteria and approval of changes under human control.
The objective isn't to make AI autonomous at all costs. It's to make AI-assisted development reliable enough that we can confidently use it for real engineering work.
That's the distinction I wanted to explore with this experiment.
And it's probably the distinction that will matter most as AI coding assistants become inevitable part of software development.
comments powered by Disqus