r/ClaudeWorkflows • • 11d ago

Selected Workflow [Workflow] Keep Claude's verification checks with CLAUDE.md rules and a bounded Stop hook

Keep Claude's verification checks with CLAUDE.md rules and a bounded Stop hook

Workflow value: 76/100
Status: active · Freshness: 70/100 · Confidence: 0.94 · Level: intermediate
Categories: Quality Control, Token Saving, Debugging, CLAUDE.md, Hooks
Original source: r/ClaudeCode post/comment

What problem this solves

Claude may verify a change with temporary scripts but leave few reusable tests in the repository.

Summary

Add verification requirements to CLAUDE.md and a bounded Stop hook that runs tests and asks Claude to fix failures. Encourage persistent property, differential, and performance tests rather than relying only on temporary checks.

Why it is useful

It provides a repeatable way to turn ephemeral verification into durable tests, with a concrete comparison and an explicit cost tradeoff.

Workflow

  1. Add project-specific verification rules to CLAUDE.md, including retaining useful checks as repository tests.
  2. Where appropriate, add property tests, differential tests against a preserved reference implementation, and performance tests.
  3. Configure a Stop hook to run the project verification script and return exit code 2 with a corrective message when tests fail.
  4. Check stop_hook_active to prevent repeated hook-triggered retries from looping indefinitely.
  5. Validate the setup by running representative checks and introducing a controlled defect to see whether the tests and hook catch it.

Tools / artifacts

  • CLAUDE.md verification section
  • Claude Code Stop hook
  • settings.json
  • verify.sh
  • Property, differential, and speed tests

Validation signals

  • The author reports that both the configured and plain runs passed a hidden grader using 3,000 random strings, 5,000 random orders, and 7 real files.
  • The configured run left 13 new tests in the repository, while the plain run left 4 small example tests and used temporary scripts for other checks.
  • A manually planted bug caused 4 of 16 tests to fail in the configured repository, versus 1 of 7 in the plain repository; the configured Stop hook returned exit code 2.
  • The reported configured run cost $0.55 and took 157 seconds, versus $0.35 and 104 seconds for the plain run.

Cautions

  • The bounded retry prevents an infinite loop but does not guarantee that every failing test is fixed before Claude stops; retain independent review and CI checks.
  • Review test failures rather than blindly changing either implementation or tests: tests themselves can be incorrect.
  • Inspect externally supplied hook scripts before running them and avoid verification commands with destructive side effects.

Limitations

  • The comparison used only one run per configuration on small Python tasks.
  • The defect was manually planted rather than introduced during a subsequent Claude session.
  • The exact five rules and hook implementation are not present in the post itself.
  • The measured outcome supports better retained regression coverage, not superior correctness on the original task.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

2 Upvotes

2 comments sorted by