Skip to content

Instantly share code, notes, and snippets.

@mikedamage
Created December 19, 2025 18:38
Show Gist options
  • Select an option

  • Save mikedamage/176f462abc12e3a64685b76323835e14 to your computer and use it in GitHub Desktop.

Select an option

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
{
"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": []
}
}
#!/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
#!/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