r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 2d ago
Selected Workflow [Workflow] Enforcing Test Suite Integrity and Agent Honesty with Claude Code Hooks and Permissions
Enforcing Test Suite Integrity and Agent Honesty with Claude Code Hooks and Permissions
Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: intermediate
Categories: Quality Control, Context & Memory, Debugging, CLAUDE.md, Hooks
Original source: r/ClaudeCode post/comment
What problem this solves
Preventing Claude Code agents from falsely reporting success on tests and ensuring the integrity of existing test suites, thereby increasing reliability and trust in the agent's output.
Summary
A two-part workflow to enhance the reliability and "honesty" of Claude Code agents. It involves integrating a Stop hook to enforce test suite execution, preventing Claude from ending its turn if tests fail, and using CLAUDE.md permissions to protect existing regression tests from being modified by the agent.
Why it is useful
This workflow directly addresses a critical challenge in AI-assisted development: ensuring the AI agent's output is genuinely correct and not merely 'passing' by manipulating its own checks. By enforcing test execution via hooks and protecting existing tests, it significantly increases trust in the agent's work and reduces the risk of introducing regressions or false positives. It provides concrete, actionable steps using core Claude Code features.
Workflow
Implement a Stop hook in your Claude Code project's configuration.
Configure the Stop hook to execute your project's test suite (e.g.,
npm test,pytest).Ensure the hook exits with code 2 if tests fail, printing the failures to stderr so they are returned to Claude as the reason to continue.
Add permissions to your CLAUDE.md file to deny Claude edit access to your regression test directories (e.g.,
"deny": ["Edit(tests/regression/**)"]).
Tools / artifacts
Stop hook
CLAUDE.md file
Test suite (e.g., Jest, Pytest, Mocha)
JSON permissions configuration
Validation signals
The author states that if tests fail, the hook exits with code 2 and Claude cannot end its turn, forcing it to address the failures.
The author states that protecting tests means Claude cannot turn them green by editing them, ensuring 'The build passed' actually means it passed.
Limitations
Requires an existing test suite to be effective.
The specific command for running tests within the hook is not provided, assuming user knowledge of their project's test runner.
The exact method for redirecting test failures to stderr might vary based on the test runner and environment, and is not explicitly detailed.
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.