ClaudeClaude CodeLevel 3: Workflows

How Do You Make Claude Code Check Its Own Work?

Give it a command that comes back pass or fail, and put that command in your prompt or CLAUDE.md. Claude Code then makes the change, runs the check, reads the output and fixes what broke. If the check must always happen, enforce it with a Stop hook instead of asking.

Prompt to copy
[Describe the change.]

When you've made it, run `[test command for the affected files, such as pnpm vitest run src/auth]` and `[typecheck command]`. If either fails, read the output, fix the cause in the source and run them again.

Rules:
- Don't edit, skip or delete a test to get it passing. If you think a test is wrong, stop and tell me why.
- Don't change anything outside [folder].

When you finish, show me the exact commands you ran and their final output. "All tests pass" without the output doesn't count.
  1. 1A line in your promptClaude decides
  2. 2/goal with a conditiona second model judges
  3. 3A Stop hook running your checkClaude Code enforces
  4. 4CI, and a person approving the mergeoutside the session
From least to most strict, based on Anthropic's best-practices page. Only the lower two don't depend on what a model decides.

Try it now

  1. 1Add the command that runs one test file to your CLAUDE.md.
  2. 2Paste the prompt above with a small, real change, and confirm the reply shows the command and its output.
  3. 3For the strict version, add this to .claude/settings.json: {"hooks":{"Stop":[{"hooks":[{"type":"command","command":"pnpm tsc --noEmit 1>&2 || exit 2"}]}]}}, swapping in your own command.
  4. 4Ask for a change that breaks a type. It worked if Claude gets the compiler errors back and keeps going instead of finishing.

Use it when

Any repo with a test, typecheck or build command fast enough to run repeatedly. Use /goal for long runs you aren't watching, such as a migration across many files, where the docs say Claude can end a turn with a progress summary while items are still open. Use a Stop hook for a check that has no exceptions in this repo.

Skip it when

Don't hand it a check with side effects, such as a script that hits production or sends real email, because it may run many times. Rule of thumb, not a vendor figure: skip a flaky suite too, since a random failure sends Claude back to work on code that's fine, and keep Stop hooks to checks that take seconds, because they run every time Claude tries to stop.

Why it works

Anthropic's docs say Claude stops when the work looks done, so without a check, that's all it has to go on, and you become the test suite. The check can be a test file, a build's exit code, a linter, a script that diffs output against a fixture, or a browser screenshot next to a mockup. You choose how strict to be. A line in your prompt leaves the call to Claude. /goal has a small, fast model judge your condition after every turn, using only what Claude has shown in the conversation. A Stop hook runs your script whenever Claude tries to end its turn, and exit code 2 sends it back to work. That last one is enforced by Claude Code itself.

Example

Say users report that login fails after a session timeout. Anthropic's sample prompt is users report login fails after the session times out. look at token refresh in src/auth/, write a failing test that reproduces it, then fix it. For a longer job, set an end state and a limit: /goal all tests in test/auth pass and the lint step is clean, no other test file is modified, or stop after 20 turns. After each turn, the evaluator reads the test output in the transcript and either sends Claude back or clears the goal.

Going further

The Stop hook has a ceiling. If it blocks eight stops in a row with no tool call between them, Claude Code overrides the next block and ends the turn. Raise the cap with CLAUDE_CODE_STOP_HOOK_BLOCK_CAP. For problems that tests and typechecks miss, run /verify once Claude says it's done. It builds and runs your app and looks at the result, and it only runs when you invoke it.

Common mistakes

  • Accepting "all tests pass" with no output. Anthropic's docs say that tells you very little, and for a session you weren't watching, the output is the only evidence you have.
  • Writing keep going, don't be lazy into the prompt. Anthropic now lists this as advice to drop, because it's more likely to cause overwork. A check to pass is what helps.
  • Setting a /goal that Claude can't demonstrate. The evaluator doesn't run commands or read files, so write npm test exits 0, not the app works.
  • Starting a /goal in Manual mode and walking away. A goal doesn't change your permission mode, so Claude still stops to ask before any command your settings don't allow.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course