Files
agentic-dev/.claude/hooks/bash-guard.sh
Danijel Martinek f77e6ea881 chore(template): clean-slate template snapshot from bb4a0c7
Curated, product-agnostic snapshot of the post-story-04 tree: demo
content deleted, auth-only reference feature, web-next shell, all gates
green. Product-specific docs, ADRs 027-029, PRDs/epics/archive, editor
library traces, and product naming are curated out; generic template
repairs (coverage provider devDeps, root test:coverage script, live
lint fixes, root-only release-please) are kept. See TEMPLATE.md for
provenance, curation list, and usage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
2026-07-12 20:40:54 +02:00

45 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Tier 1 — blocks dangerous shell invocations the agent shouldn't run
# autonomously. Reads PreToolUse JSON on stdin; exits 2 with stderr to block,
# 0 to allow. Reinforces the Git Safety Protocol in CLAUDE.md.
set -euo pipefail
input=$(cat)
cmd=$(printf '%s' "$input" | jq -r '.tool_input.command // ""')
blocks=(
'(^|[[:space:]])--no-verify([[:space:]]|$)'
'(^|[[:space:]])--no-gpg-sign([[:space:]]|$)'
'git[[:space:]]+push[[:space:]]+([^&|;]*[[:space:]])?(-f|--force)([[:space:]]|$)'
'git[[:space:]]+reset[[:space:]]+[^&|;]*--hard'
'git[[:space:]]+clean[[:space:]]+-[a-zA-Z]*f'
'git[[:space:]]+checkout[[:space:]]+\.([[:space:]]|$)'
'git[[:space:]]+restore[[:space:]]+\.([[:space:]]|$)'
'git[[:space:]]+branch[[:space:]]+-D'
'git[[:space:]]+commit[[:space:]]+[^&|;]*--amend'
'rm[[:space:]]+-rf?[[:space:]]+/'
'rm[[:space:]]+-rf?[[:space:]]+~'
'rm[[:space:]]+-rf?[[:space:]]+\$HOME'
)
for pattern in "${blocks[@]}"; do
if [[ "$cmd" =~ $pattern ]]; then
cat >&2 <<EOF
BLOCKED by .claude/hooks/bash-guard.sh
This template forbids the agent from running this autonomously:
Pattern: ${pattern}
Command: ${cmd}
If the user has explicitly authorized this action this turn, ask them to
run it themselves (\`! <command>\` in the prompt) or document the override
in their request. See CLAUDE.md → "Executing actions with care" and the
Git Safety Protocol section.
EOF
exit 2
fi
done
exit 0