I simply forbid or force Claude Code to ask for permission to run a dangerous command. Here are my command validation rules:
(
r"\bbfs.*-exec",
decision("deny", reason="NEVER run commands with bfs"),
),
(
r"\bbfs.*-delete",
decision("deny", reason="NEVER delete files with bfs."),
),
(
r"\bsudo\b",
decision("ask"),
),
(
r"\brm.*--no-preserve-root",
decision("deny"),
),
(
r"\brm.*(-[rRf]+|--recursive|--force)",
decision("ask"),
),
find and bfs -exec is forbidden, because when the model notices it can't delete, it works around with very creative solutions :)
This feels a lot like trying to sanitize database inputs instead of using prepared statements.