You have probably written a line like this. It sits in an instruction file, in capitals, sometimes twice: NEVER run destructive SQL. NEVER.
The capitals are the tell. You wrote it loudly because you need it to hold, and a prompt can't make it hold. A rule written in a prompt is a request, and a rule that must always hold belongs in code that can refuse, such as a permission, a hook, a validator or a merge check.
Claude Code's own documentation says CLAUDE.md files are treated as context, not enforced configuration. When you need to block an action regardless of what the model decides, it points you to a PreToolUse hook.
A prompt guides. Code refuses.
Wording still matters. The same documentation says more specific and concise instructions are followed more consistently, and the page never calls that enforcement.
OWASP is blunter. Its guidance on system prompt leakage says critical controls such as privilege separation and authorization bounds checks must not be delegated to the LLM, because they need to happen in a deterministic, auditable way. Its prompt injection entry says it is unclear whether any fool-proof prevention method exists. So if your only guard is a sentence the model reads, your guard is as strong as the weakest input it reads next to that sentence.
Before
The rule lives in the prompt
- The model reads it, weighs it, and usually follows it
- A clever input can argue with it
- When it breaks, you find out from the damage
After
The rule lives in code
- It runs whether or not the model agrees
- It can refuse the action, and a hook can tell the model why
- When the check runs before the action, the action stops before the damage
Sort your rules into two piles
Not every rule deserves code. Most of what sits in an instruction file is guidance: naming conventions, the test style you like, prefer small commits. If the agent drifts, you fix it in review and nothing is lost.
I'd sort them with one question: what would one violation cost? If the answer is "an annoying review comment", it stays in the prompt. If the answer is lost data, a leaked secret or broken main, it's a hard limit.
- Guidance: style, structure, tone, the order you like things done in. Keep it in the prompt, and keep it short.
- Hard limits: what the agent may touch, what it may run, what shape its output must have, what can merge. These also get a check in code.
Give the costly rule teeth
There is more than one place a rule can live outside the model, and each fits a different kind of limit:
- Permissions. Claude Code evaluates deny, then ask, then allow, and an allow rule cannot carve an exception out of a deny.
- Access at the source. OWASP says to put authorization in downstream systems and give agents the minimum permissions they need. Its example is read-only access, enforced by the database identity.
- Hooks. Shell commands that run at set points, so certain actions happen without relying on the model to choose them.
- Validators. Define the output format and check it with deterministic code. JSON Schema covers structure; some relationships between fields will likely need real code.
- Merge checks. A protected branch with required status checks won't merge until they all pass.
- A human. For high-impact actions, OWASP recommends approval before they are taken.
For the SQL rule from the opening, a PreToolUse hook is a first layer. Exit code 2 blocks the tool call, and whatever you write to stderr goes back to the model as feedback. The documentation's own example blocks a command containing "drop table". This one catches only those words in a shell command; the harder limit is a database account that cannot drop anything.
That proves the script refuses. It doesn't prove Claude Code calls it. Register it as a PreToolUse hook with the Bash matcher, then confirm in a safe session that it fires.
Then try to break it
A check you haven't seen refuse is a check you hope works. Hooks, permission rules and branch protection each have gaps their own documentation names.
- Placement: a PostToolUse hook can't undo anything. The tool already ran.
- Coverage: a matcher covers only the tools it names. The model can also change files through shell commands, so a check that watches only edit and write can miss them.
- Reach: Read and Edit deny rules don't apply to arbitrary subprocesses. For operating system level enforcement, the docs point to the sandbox.
- Bypass: GitHub branch protection doesn't apply to admins by default. Turn on "Do not allow bypassing the above settings" if it should.
Where I'd start
Open your instruction file. Find every line in capitals. For each one, ask what a single violation would cost. Take the most expensive and move it into a permission, a hook, a validator or a merge check. Test it with sample input, as above, or in a throwaway environment with nothing to lose, until you see it refuse.
The sentence can stay in the prompt, minus the shouting. It isn't the limit anymore; the check is, for the cases you tested. The prompt goes back to guiding the agent on everything else.
Building with AI?Let's talk about your appBook a free intro call


