Created
December 19, 2025 18:38
-
-
Save mikedamage/176f462abc12e3a64685b76323835e14 to your computer and use it in GitHub Desktop.
Stop Claude from reading files or running bash commands on files/directories matching a grep pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "hooks": { | |
| "PreToolUse": [ | |
| { | |
| "matcher": "Bash", | |
| "hooks": [ | |
| { | |
| "command": "bash .claude/scripts/validate-bash.sh" | |
| } | |
| ] | |
| }, | |
| { | |
| "matcher": "Read", | |
| "hooks": [ | |
| { | |
| "command": "bash .claude/scripts/validate-read.sh" | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| "permissions": { | |
| "allow": [], | |
| "deny": [], | |
| "ask": [] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| COMMAND="$(cat | jq -r .tool_input.command)" | |
| BLOCKED="node_modules|\.env|\.git/|dist/|build/" | |
| if echo "$COMMAND" | grep -qE "$BLOCKED"; then | |
| echo "Error: blocked file/directory pattern" >&2 | |
| exit 2 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| FILE_PATH="$(cat | jq -r .tool_input.file_path)" | |
| BLOCKED="node_modules|\.env|\.git/|dist/|build/" | |
| if echo "$FILE_PATH" | grep -qE "$BLOCKED"; then | |
| echo "Error: blocked directory pattern" >&2 | |
| exit 2 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment