Prompts are suggestions. Settings are rules.
If you only write "never run dangerous shell commands" in CLAUDE.md, the model can still try them. Claude Code lets you put an explicit allow / deny list in .claude/settings.json so the runtime blocks the tool call before it runs.
Minimal example
{
"permissions": {
"deny": [
"Bash(rm -rf *)",
"Bash(git push --force*)",
"Bash(git reset --hard*)",
"Bash(sudo *)"
],
"ask": [
"Bash(npm publish*)",
"Bash(gh pr merge*)"
]
}
}
Exact matcher syntax can vary by Claude Code version — treat this as the shape, then confirm against your installed docs. The point is: put the policy where the tool layer enforces it.
Why this beats a longer prompt
- A deny in settings fails closed. A sentence in
AGENTS.mdis soft. - You can keep
CLAUDE.mdshort (house rules + stack map) and still be strict on shell. - Pair with a
PreToolUsehook for patterns settings cannot express, and aStophook so the agent cannot say "done" whiletscis red.
I keep the deny list, hooks, and short house-rules file together in Vildanden Agent Config. The free sample is enough to try the pattern.
Top comments (2)
Agree on settings over prose. The permissions docs have a section, "What a Bash rule doesn't match", that is worth reading next to the
Bash(rm -rf *)example. A Bash rule matches the command text Claude writes, after Claude Code splits compound commands and strips wrappers liketimeoutandnohup. SoBash(rm *)in deny stopsrm -rf build/, but the docs list/bin/rm -rf build/andbash -c 'rm -rf build/'as forms it does not stop, and they say a deny rule "isn't a security boundary around the program". The narrowerrm -rf *pattern also leavesrm -fr buildandrm -r -f buildoutside it, because the text afterrmdiffers. Two cheap fixes: widen the deny toBash(rm *), and turn on the sandbox when the rule has to hold. One catch from the same page: an allow rule can't carve an exception out of a deny, soBash(rm -rf build/)in allow won't get past aBash(rm *)deny. Put the cleanup in a script or an npm task instead. Have you seen an agent retry with a different form after a deny?A prompt rule can be pushed out of attention once the context gets long. A settings rule is checked by the harness on every call, which is why it holds.