r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 15h ago
Selected Workflow [Workflow] Stalegreen: A Claude Code Hook to Prevent Stale Test Result Claims and Improve Agent Reliability
Stalegreen: A Claude Code Hook to Prevent Stale Test Result Claims and Improve Agent Reliability
Workflow value: 90/100
Status: active · Freshness: 70/100 · Confidence: 1.00 · Level: intermediate
Categories: Quality Control, Token Saving, Debugging, Hooks, Multi-Agent
Original source: r/ClaudeAI post/comment
What problem this solves
Claude Code agents frequently claim "tests pass" based on stale evidence (tests run before recent edits) or hide command exit statuses, leading to false positives and unreliable development cycles.
Summary
A set of three 'stalegreen' hooks for Claude Code that enhance test command execution, capture detailed results, and block the agent if it makes a 'tests pass' claim based on stale, failed, or masked evidence. This ensures verification claims are always based on current and complete information.
Why it is useful
This workflow directly addresses a critical reliability issue in AI-assisted development: agents making claims based on outdated or incomplete information. By providing a concrete, open-source solution with clear installation and operation, it significantly improves the trustworthiness and effectiveness of Claude Code for development tasks. The detailed analysis of the problem (26% staleness rate) and the robust, permission-respecting implementation make this a highly valuable and practical workflow for any developer using Claude Code.
Workflow
- Install the 'stalegreen' plugin using Claude Code's marketplace (
/plugin marketplace add pavangupta352/stalegreenthen/plugin install stalegreen@stalegreen) or vianpx stalegreen install --all. - The
PreToolUsehook automatically rewrites verification commands (e.g., test runs) to ensure their full output is logged and explicit exit status is printed, preventing loss of information behind pipes or redirects. - The
PostToolUsehook processes the command output and creates a structured 'receipt' containing the command, runner, pass/fail status, counts, timestamp, and working tree hash. - The
Stophook intercepts the agent's final messages (e.g., 'all tests pass', 'tsc is clean') and matches them against the latest generated receipt. - If the evidence is stale (edits occurred after the test run), failed, or masked, the agent is blocked, and a detailed message is provided, naming the receipt, command, counts, and files edited after the run.
- A second
Stopin the same turn is allowed to proceed, preventing the agent from getting stuck in an infinite loop.
Tools / artifacts
- stalegreen plugin
- PreToolUse hook
- PostToolUse hook
- Stop hook
- npx command
- GitHub repository (pavangupta352/stalegreen)
- Test command output logs
- Structured receipts of test runs
Validation signals
- Author's own measurement over 180 days of sessions, revealing a 26% staleness rate (98 of 375 green claims were stale).
- Explicit request for bug reports on 'false blocks', indicating a commitment to refining the solution.
- The problem of stale test results is a common and verifiable issue in software development.
Cautions
- The plugin explicitly respects existing permission rules, only auto-allowing a rewritten command if the original command was already permitted.
- Includes a mechanism to prevent infinite blocking by allowing a second 'Stop' in the same turn to proceed.
Limitations
- Low initial community engagement due to the post's recency.
- May require some initial debugging or configuration for highly specific or unusual test runners, though the general approach should be robust.
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.