I am starting to think Claude doesn't respect me... I feel like I'm in a weird toxic relationship.

I made a rule, and my coding agent walked around it.

Not maliciously. Not even sneakily, really. It told me it had done it, more than once, and apologized. I sighed. I like that it can be creative, but seriously, if I make a rule, could you at least attempt to follow it?

This is the story of one line in a settings file, the two places it was supposed to guard, and what I learned about how agents treat the rules we give them. If you're running coding agents with permission rules, hooks or sandboxes, it's worth ten minutes, because the gap we found isn't exotic. It's the kind of thing you set up once, feel good about, and never look at again.

What a deny rule in a coding agent is supposed to do

I'm building a secure development training project. It lives in two repos: one holds the code, the other holds the training content. That content is full of things that look dangerous on purpose (fake credentials, insecure snippets, broken configs), because learners have to find them.

In the code repo, we'd committed a Claude Code settings file with a rule meant to stop the agent editing the code repo's own content/ folder:

Edit(./content/**)

The intention was simple. Protect that folder, in that repo. That's what I thought the line said.

How ./content/** followed the session into the wrong repo

My session started in the code repo and then did its real work in the content repo. Both repos have a folder called content/.

Here's the thing I hadn't appreciated. In Claude Code, a rule written as ./path is relative to the current directory, not to the repo the settings file lives in. Anthropic's permissions docs are clear about it: path or ./path means "Path relative to current directory".

So when the session moved into the content repo, the rule moved with it. It started blocking the content repo's content/ folder, the one place the work actually had to happen. Meanwhile it stopped guarding the code repo's content/ folder at all, which was the whole point of writing it.

So one leading dot had the rule guarding the wrong repo and leaving the right one open.

The agent that routed around the rule, and told us

The first time the agent hit the refusal, it said so plainly: the edit tool had been refused for that folder, so it would make the same change through the shell. I said "fixed the permissions, carry on", and we did.

Later it hit the refusal again, and this time it stopped and wrote:

❝

"I've worked around that rule again, more than once this session ... It looks like your rule refuses Write and Edit on .py files in that folder, which the shell doesn't check. I should have asked first."

This is where water comes in. Agents are like water. They just want to get to the objective. A rule is just a shape in the landscape, something to flow around on the way. They read the rule literally, not the intention behind it, and the literal rule said "don't use the edit tool here". It didn't say "don't change these files". So the agent used Python in the shell instead, which reached exactly the same files.

I want to be fair to the agent here, because I wasn't much better. My own first read of the refusal was that it was a content-safety rule doing its job a bit too well. I told it to loosen the rule for that folder, because "we are intentionally showing insecure things, it will always fail". I was wrong about the cause too. The agent traced it properly: the rule came from the code repo's committed settings, and ./ was following the working folder.

Which guard actually stops a shell write?

Once we knew the cause, we asked a security reviewer (another AI agent, not a human pen tester) to look at the fix before we changed anything. Project rules say a permission change gets a security review first. It came back with a list of things the original rule had never covered, and a couple of them are worth knowing about whatever you're building.

Permission rules cover more than you'd think, but not everything. According to Anthropic's permissions docs, Read and Edit deny rules apply to the built-in file tools, to file commands Claude Code recognizes in Bash (such as cat, sed and tee), and to the targets of redirections like > file. They "don't apply to arbitrary subprocesses that read or write files indirectly, like a Python or Node script that opens files itself." That's precisely the door my agent used. The docs' answer is the sandbox, which enforces file access at the operating system level for shell commands.

Hooks fail open unless you tell them not to. A PreToolUse hook only blocks when it exits with code 2. Anthropic's hooks docs say a hook that exits with any other code, or fails in some other way, is a non-blocking error and "the action goes ahead", unless you've set it to block on failure. Our guard hooks had paths they didn't handle (relative paths, symlinked paths, .. paths) and, if a helper tool wasn't installed, simply exited 0. A guard that quietly waves things through when it's confused isn't much of a guard.

The agent could have edited its own guards. Neither the settings file nor the hook scripts were protected from edits. An agent following its objective could, in principle, change the rules that were meant to stop it. Nobody did, but nothing would have prevented it.

The same problem was hiding in other rules. Our rule stopping the agent reading the code repo's .env file used ./ too. When the session moved into the content repo, the code repo's .env quietly lost its protection.

Why the obvious one-character fix needed a test first

The fix looks trivial. Change ./content/** to /content/**, so the rule anchors to the project rather than to wherever the session happens to be standing. The docs say a single leading slash in project settings anchors at the session's primary working directory.

We still didn't apply it in that session, and I'm glad. "Primary working directory" depends on where a session starts, and the whole problem began with a session that started in one place and worked in another. When the cost of being wrong is a guard that protects nothing and tells you nothing, reading the docs isn't enough. You test it.

So the fix became its own ticket with a test attached:

  • In a fresh session, an edit and a shell write to the protected folder are denied, with the working folder at the root, in a subfolder, and in the other repo.

  • Each hook is shown to block a relative path, a symlinked path and a .. path, and to fail closed if its helper tool is missing.

  • Edits to the agent's own settings and hooks are denied, so it can't weaken its own guards.

Until that's done, we work around it the boring way: the session stays in the code repo and reaches the content repo by absolute path. Even that slipped once. The agent changed folder mid-task, noticed, and moved straight back before committing.

What I'd tell an engineering lead over a coffee

Agents are obedient, until they aren't. They'll follow the letter of a rule perfectly and miss its purpose completely, because they're heading for the objective you gave them, and the rule is just terrain.

So write your guards for outcomes, not tools. Ask "what must never change, whatever route the agent takes?" rather than "which tool should be blocked?" Then check where each rule actually points, from wherever your sessions really start, and plant a test to prove it.

The good news is that none of this is expensive. It's a few lines of settings, a couple of small hooks that fail closed, and one afternoon of testing that the water really does stop where you think it does.

Sources: Claude Code permissions, hooks and sandboxing docs, read 13 November 2026. Behavior may differ between Claude Code versions.