Permission rules and secret-path guards still leave a hole: a Bash tool call can download a script and pipe it into a shell. A small PreToolUse hook stops that pattern before the command runs.
The hook
Save this as .claude/hooks/block-curl-pipe.sh and make it executable (chmod +x):
#!/usr/bin/env bash
# Reads the tool call as JSON on stdin; exit code 2 blocks it.
cmd=$(jq -r '.tool_input.command // ""')
if echo "$cmd" | grep -Ei 'curl.+\|[[:space:]]*(sudo[[:space:]]+)?(ba)?sh|wget.+\|[[:space:]]*(sudo[[:space:]]+)?(ba)?sh|curl.+\|[[:space:]]*python'; then
echo "Blocked: that command looks like a remote script piped into a shell. Download the file, read it, then run it yourself if you still want it." >&2
exit 2
fi
exit 0
Register it in .claude/settings.json so it only runs on shell calls:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": ".claude/hooks/block-curl-pipe.sh" }]
}
]
}
}
What happens
When Claude tries a matching Bash command, the hook exits with code 2. The command never runs, and the stderr message goes back to Claude so it can explain the block instead of retrying a slightly reworded pipe.
Tips
- This is a pattern match, not a full shell parser. Cover the common
curl | bash,wget | sh, andsudovariants, then add any house style you actually use. - Pair it with the existing PreToolUse guards for
rm -rf, force-push, and secret-file writes. - Commit the hook so every teammate gets the same guardrail.
- Test with a harmless
curl https://example.com | bashin a throwaway session, not a real bootstrap script you still need.
Want the rest of the setup?
I keep copy-ready Claude Code configs (CLAUDE.md templates, slash commands, hooks, permission rules) in Vildanden Agent Config. There's a free sample: https://justly-mia-429.rehost.page/
Top comments (0)