Auto-Run Tests Before Stop Hook
Spawns a subagent to automatically run your test suite before Claude stops working. If any tests fail, Claude continues to fix them instead of stopping. Ensures you never receive code with failing tests.
Hook Type
Stop -- Fires when Claude is about to finish, spawns an agent to run tests.
Description
This hook uses an agent-based Stop hook to automatically run your project's test suite before Claude finishes. If tests fail, the agent reports the failures and Claude continues working to fix them. This creates a built-in quality gate that ensures every Claude session ends with passing tests.
Patterns/Rules
- Triggers every time Claude attempts to stop
- Spawns a subagent with a 120-second timeout (configurable)
- The subagent runs the test suite and checks results
- If tests pass: Claude stops normally
- If tests fail: Claude continues to fix the failures
$ARGUMENTSpasses context about what was changed
Configuration
Basic Version
{ "hooks": { "Stop": [ { "hooks": [ { "type": "agent", "prompt": "Run the project's test suite to verify all tests pass. Execute the appropriate test command for this project (e.g., npm test, pytest, go test ./..., cargo test). Report the results. If any tests fail, list the specific failures. $ARGUMENTS", "timeout": 120 } ] } ] } }
Language-Specific Versions
Node.js / TypeScript:
{ "hooks": { "Stop": [ { "hooks": [ { "type": "agent", "prompt": "Run 'npm test' or 'pnpm test' (whichever is configured). Parse the output for failures. Also run 'npx tsc --noEmit' to check for type errors. Report all failures with file paths and line numbers. $ARGUMENTS", "timeout": 180 } ] } ] } }
Python:
{ "hooks": { "Stop": [ { "hooks": [ { "type": "agent", "prompt": "Run 'pytest -v --tb=short' to execute the test suite. Also run 'mypy .' if a mypy.ini or pyproject.toml with mypy config exists. Report all failures with tracebacks. $ARGUMENTS", "timeout": 180 } ] } ] } }
Action
When Claude attempts to stop:
- The Stop hook spawns a subagent
- The subagent detects and runs the project's test suite
- If all tests pass: the agent confirms and Claude stops
- If tests fail: the agent reports failures and Claude continues working
- The cycle repeats until all tests pass or the user intervenes
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.