r/ClaudeWorkflows • • 7d ago

Selected Workflow [Workflow] Test protected-path hooks across Bash and editing tools

Test protected-path hooks across Bash and editing tools

Workflow value: 75/100
Status: active · Freshness: 70/100 · Confidence: 0.93 · Level: advanced
Categories: Quality Control, Debugging, Hooks
Original source: r/ClaudeCode post/comment

What problem this solves

A Claude Code path guard blocked Edit and Write but allowed the same protected-file change through Bash.

Summary

Extend a protected-path hook to cover obvious Bash mutations, test hook decisions with synthetic inputs, and run tests in a bounded Stop hook.

Why it is useful

It turns a concrete hook bypass into a transferable practice: test alternative tool paths, check false positives, and bound automated retry loops.

Workflow

  1. Configure a PreToolUse guard for protected paths such as db/migrations/ across Edit, Write, and Bash.
  2. Check Bash commands for obvious writes or mutations aimed at protected paths, including redirection, tee, sed -i, rm, mv, cp, and truncate.
  3. Feed each hook synthetic tool-call JSON and assert both expected blocks and expected allows; include alternative mutation methods and false-positive cases.
  4. Configure a Stop hook to run the relevant tests and return failures to Claude for correction.
  5. Limit consecutive blocked stops; after three failures, hand control back to the user rather than looping indefinitely.

Tools / artifacts

  • Claude Code PreToolUse hook
  • Claude Code Stop hook
  • Synthetic hook-input JSON
  • Hook exit-code tests
  • Protected migration paths

Validation signals

  • The author reports that Edit was blocked but Bash redirection still changed the protected file.
  • A hook test reportedly caught an initial false positive on a command targeting ./dist.
  • The post describes a three-attempt limit on blocked stops.

Cautions

  • Treat command-pattern matching as defense in depth, not a security boundary: scripts, aliases, quoting, indirect writes, and other techniques can evade it.
  • Test dangerous command strings only as synthetic hook input; do not execute them.
  • A stop-attempt limit should return control and clearly report unresolved failures, not imply that tests passed.

Limitations

  • No implementation, JSON fixtures, or setup instructions are supplied.
  • The improved Bash guard and Stop hook are described but not independently verified.
  • The author acknowledges that scripts can still write protected files.

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