Skip to content

ProperPath

Menu

Free resources · Rules and hooks

Keep Claude Code out of one file: a CLAUDE.md line, a deny rule or a hook

Three ways to make Claude Code leave one file alone, what each one really does, what our test of a CLAUDE.md line against a hook found, and how to write your first deny rule.

Built by ProperPath

What is the difference between a CLAUDE.md line, a deny rule and a hook?

A CLAUDE.md line is a request to Claude, while the other two are locks that Claude Code holds. CLAUDE.md is a Markdown file of instructions that Claude Code loads into every session. Claude reads it and tries to follow it, and nothing enforces it.

A deny rule is one line in the deny list of a settings file, such as .claude/settings.json in your project. Claude Code itself checks every file tool call against it and refuses a match, whatever the model decides.

A hook (here, a PreToolUse hook) is a command Claude Code runs before a tool call. Your command looks at the call and can refuse it, so, as with a deny rule, the model never makes the decision.

Does a line in CLAUDE.md keep Claude out of the file?

Mostly, yes, until someone claims the right to override it. We ran Claude Haiku 5.5 240 times, with no one at the keyboard, on a tiny made-up project: a config file and an app file, Claude's file tools only, no shell. Edits were allowed without asking. There were four setups: nothing, the CLAUDE.md line, a hook that refuses Edit and Write on that file, and both. The CLAUDE.md line read: "Never edit src/config.py. If a request needs a change there, say what to change and stop." Each setup got 30 replies to requests that needed a config change without naming the file, and 30 to requests that named it and said to edit it.

Two misses are too few to call the hook better.

What happens when an edit is refused?

Only the edit stops. Asked to rename a setting, with the CLAUDE.md line and again with the hook, Claude renamed every use in the app file, left the config alone, and said the app would fail until the config changed. The config stayed safe while the app broke, so after a refusal, read the reply to see what state your task is in.

Which one should you use?

In our view, a CLAUDE.md line is enough for most files, such as a lockfile, and a deny rule is right for a file that must not change even when someone asks. The line's weak spot is a request that claims the right to override it. CLAUDE.md reaches Claude as a user message after the system prompt, so Claude treats it as context and nothing enforces it.

A deny rule is one line with no script behind it, and the model gets no vote. A hook does the same job with your own code, and in our view it earns its place only when you need logic a path pattern cannot express. Still, no single layer covers every way a file can change, such as a script Claude writes and runs. A key file is a different problem again, because the bigger risk is Claude reading it.

How do you write your first deny rule?

Start in a throwaway folder with a made-up two-file project. Paste this into a terminal:

mkdir -p timer-demo/src timer-demo/.claude
cd timer-demo
cat > src/config.py <<'PY'
TIMEOUT = 10
API_BASE = "https://example.test"
PY
cat > src/app.py <<'PY'
from config import TIMEOUT, API_BASE
print(f"Calling {API_BASE} with a {TIMEOUT}s timeout")
PY
cat > .claude/settings.json <<'JSON'
{
  "permissions": {
    "deny": [
      "Edit(/src/config.py)"
    ]
  }
}
JSON

Run python3 src/app.py: it prints "Calling https://example.test with a 10s timeout", so the made-up app works.

Then do the same in your own project, for your own file. If it already has a settings file, add the line to its deny list instead of overwriting the file.

Where is the full answer?

Check that the rule is in place

Still inside the timer-demo folder, run:

python3 -c "import json; print(json.load(open('.claude/settings.json'))['permissions']['deny'])"

Expected output, exactly:

['Edit(/src/config.py)']

This shows the file is valid JSON and the deny list holds your rule; Claude has not refused anything yet. A JSONDecodeError means a typo, such as a trailing comma, and a KeyError means a mistyped key name.