Stage 4: Test
Give Claude a feedback loop, and run evals continuously in CI.
From QA gates to checks that run all the time
When an agent writes the code, a late "does it work" signal turns a person into the bottleneck. Testing moves into the work itself.
QA gates at stage boundaries
The signal arrives late, and a person has to check everything the agent produced.
Continuous evals woven through implementation
The session checks its own work and iterates until the check passes. What reaches the engineer has already passed.
Check the work, then check the setup
Play 1 makes each session verify itself. Play 2 tests the agent's configuration the way you test code.
Give Claude a feedback loop
"Always give Claude a way to verify its own work." A session checks and fixes its own work before an engineer sees it.
The "does it work" signal comes late: CI minutes later, a tester days later, production weeks later. With an agent producing the code, someone must check all of it.
The session runs the tests, runs the build, takes the screenshot, and iterates until the check passes. What reaches the engineer has already passed it. The engineer running the session sets up the loop.
The loop is not the same thing as the verifier subagent from Stage 3. The loop runs through the whole task, as many times as needed. The verifier is one way to package the final check, in a fresh context window, so its verdict is not colored by the assumptions that produced the code.
Prerequisites
None.
Infrastructure
- A test suite and a build that each run locally with one command.
- For UI work, a browser tool or a screenshot utility wired in through MCP.
- Wrap the checks in one target, such as
make test, that exits non-zero on failure. - List each command in the Commands section of CLAUDE.md, with an example of healthy output.
- State a target you can measure: "All tests in test_status.py pass", or "the endpoint returns 200 with the new field".
- For bug fixes, write the failing test first. Confirm it fails for the expected reason, commit it, then ask Claude to make it pass without editing the test. A test-file hook enforces that.
- For UI work, close the loop visually: implement, screenshot, compare, adjust. Two or three rounds is normal.
- Make verification part of "done" in CLAUDE.md: run the tests before reporting a task complete, and show the output.
- Protect the loop. An agent fixing code must not weaken its own check. Block edits to test files during a fix task, or reject any diff that touches a test in review.
Engineer sets up the loop and runs the session.
What is enforced
Verification before done, and a block on editing test files during a fix. Both are hooks where you want a guarantee.
Evidence
The literal output of make test, the build log, or the screenshot diff, pasted by Claude.
Where it is logged
The session transcript (forwarded by the OpenTelemetry export) and the PR check run.
Who approves
The code owner reviewing the PR. The mechanical evidence is attached, so they can focus on intent and risk.
Watch the loop run
One bug fix, from a failing test to a verified diff. Use Play, or the arrow keys on the step buttons.
Engineer reproduces the bug as a test and confirms it fails for the expected reason. The test is committed before any fix.
Claude runs the check, for example
make test. It fails, as expected.Claude reads the output and works out what failed and why.
Claude changes the code. Hook blocks any edit to the test file.
Same command. If it is still red, go around again. When it is green, the loop ends.
A separate context re-runs the checks, so the verdict is not colored by the assumptions that produced the code.
The diff arrives with the test output attached. The engineer reviews intent and risk.
Continuous evals in CI
"Evals are the AI-native equivalent of stage-gate QA." A suite that says whether the agent still does the work to the same standard.
QA gates at stage boundaries.
A suite of evals reruns whenever the agent's configuration changes, such as a new model or a rewritten prompt. It tells you whether the agent still meets the same standard.
The suite is live. As models improve, some cases stop telling good from bad, and monitoring produces new cases. Some teams prefer to run evals offline on a set cadence. The steps here are for continuous evals.
Prerequisites
CLAUDE.md and the feedback loop above.
Infrastructure
- CI that can run Claude Code non-interactively.
- An API key with budget for eval runs.
- Platform engineer collects 20 to 50 real tasks from recent work, each with its expected or accepted outcome.
- Write each task as an eval: the prompt, plus the checks that define acceptable. For example tests pass, lint is clean, behavior is unchanged, policy is followed.
- Run the suite non-interactively in CI on a schedule, and on any change to CLAUDE.md, skills or hooks. That configuration steers the agent, so it "deserves the regression testing that code gets".
- Gate configuration changes on the results. A skill change that drops the pass rate is reviewed before merge.
- Each production incident gets an eval, written by the team that owned the incident. It stays as a regression test.
Each eval starts from the code as it was before the work, so every run is comparable. The grader rejects a run that changed files outside the allowed paths, so the agent cannot pass by rewriting its own checks. Do not skip CLAUDE.md, skills or hooks in these runs, because they are what you are testing.
What is enforced
The pass-rate threshold, as a merge check. Evals give QA "a gate that keeps up with agent output".
Where it is logged
Runs are logged so you can compare them over time.
Who approves
The team that owns the configuration change.
Threshold
The worked example needs every eval to pass. A suite of 20 to 50 evals may set a lower bar.
Watch a config change meet the evals
A pull request trims CLAUDE.md. The suite runs before it can merge.
CI starts on a pull request that touches CLAUDE.md,
.claudeor the evals. It also runs on a schedule.CI checks out the code as it was before the original work, then copies in the branch's configuration. That is the thing under test.
Claude runs each prompt non-interactively. Then the checks run on whatever files it left behind.
The trimmed file dropped the line about not logging response bodies. The suite catches it.
Config owner puts the line back before merge. The rerun passes.
The team that owned the incident writes it. It joins the suite as a regression test.
What Test hands to Deploy
A verified diff
The change has passed its own checks, with the output attached. Any change to the agent's configuration has passed the evals.
verified diff
A PR enters review
The pull request starts the layered review in Stage 5: Deploy. Reviewers can focus on intent and risk because the mechanical evidence is already there.
Key takeaways
- Give every session one command that says whether the work is done, and put it in CLAUDE.md.
- For bugs, commit the failing test first. A test the agent could not rewrite is proof the bug is gone.
- Protect the loop. The agent fixes the code, never the check.
- Treat CLAUDE.md, skills and hooks like code: a suite of 20 to 50 real tasks reruns on every change and on a schedule.
- Every production incident becomes a new eval.
Based on Anthropic's The AI-native SDLC playbook course (Claude Academy). Summarized by Bitovi to guide client transitions.