Back to blog

· 8 min read

Prompts aren’t permissions. Guards are.

Why a prompt is not a permission system: how we built a fail-closed guard for Claude AI agents, what broke along the way and what real tests showed.

A sentence in a prompt is a request, not a barrier. “Please do not change any files” can shape what an agent tries, but it cannot stop a tool call. We needed a real limit for an AI project companion, so we put a guard in front of every tool call, tested it in Claude Desktop and wrote down where it stops working.

The short version: the guard held in every case we tested, but only after four design mistakes were found and fixed. It is a useful control, not a sandbox.

A companion, not an autopilot

We are building ZYRIS, a kit that lets an LLM accompany a software project. The agent reads project knowledge, spots open questions, records progress and prepares work packages. It does not decide for us, and it does not touch the code on its own.

That leads to three kinds of change that should never be mixed:

  • Non-binding progress: open questions, notes and hand-overs may be written down by the agent.
  • Binding knowledge: decisions and contracts need an explicit approval.
  • Implementation: code changes, commits, pushes and merges are separate, controlled steps.

Why a prompt is not enough

Our rules for the companion were clear on paper. In practice, text instructions were not a reliable stop, and we stopped treating them as one. It helps to keep three layers apart:

  1. Prompt and process: what should the agent do?
  2. Guard or sandbox: what is a tool actually allowed to do?
  3. Tests: has this been shown to work in the real runtime?

A prompt only covers the first layer. Passing unit tests only covers part of the third. The second layer needs its own mechanism.

How the guard works

Claude Code can run a hook before every tool call (a PreToolUse hook). The hook receives the planned call as JSON and answers allow or deny. That is the right place for a decision, because it happens before anything changes.

In a registered project, our guard allows:

  • read-only tools,
  • edits to exactly two existing documents, OPEN.md and HANDOFF.md, addressed by absolute path,
  • a short allowlist of shell commands and a few read-only Git subcommands.

Everything else is denied, including unknown tools and MCP tools that are not explicitly allowed.

Two details matter more than the allowlist:

  • Projects are registered, not guessed. The installer takes a list of project roots. A folder that is not on the list is not affected.
  • The guard lives outside the project. It is installed with administrator rights into the managed settings location of Claude Code (on macOS under /Library/Application Support/ClaudeCode/), so the agent should not be able to overwrite it. The hook is configured to block when it fails.

Four things that went wrong

Several independent reviews found real flaws before we installed anything. Each one taught us something.

1. Unknown meant unprotected. An early version let a call through when it could not work out which project it belonged to. In a security control, “cannot tell” was treated like “not protected”. Now every call is classified as registered, clearly unregistered or unknown. Only clearly unregistered passes freely; unknown is denied.

2. Two interpreters, two answers. A shell pre-filter read one project signal, the Python guard read two. When they disagreed, the shell could skip the guard entirely. Plain string comparison of paths also fails with symlinks and with upper and lower case on macOS. Now a match in a registered project wins, and directories are compared by file system identity.

3. JSON parsed with grep and sed. A quick fix extracted the working directory from the JSON with text patterns. That is a second, weaker interpretation of the same event. The shell no longer reads the event at all. Python reads it once and decides.

4. Duplicate keys and broken bytes. A JSON event with the same key twice looks different to different parsers. A lenient UTF-8 decoder quietly replaced invalid bytes and processed a damaged event as if it were fine. Now duplicate keys and invalid UTF-8 are errors, and errors are denied.

The common lesson: a security decision must not rest on input that can be read in more than one way. One component decides, and it fails closed. The price is a Python process per tool call. The development agent put that at roughly 50 ms; we have not measured it ourselves.

Testing it in the real app

Unit tests came first. The development agent reported passing tests for the guard and the install scripts on Python 3.15 and on the macOS system Python 3.9, plus the knowledge and companion suites of the kit. We have not re-run those ourselves, and they do not show that Claude Desktop loads managed settings and applies the hook.

So we installed the guard on a Mac and tested in Claude Desktop (Code tab, Auto mode) with three throwaway projects: one registered, one registered for a later workspace-trust test and one unregistered as a control.

Check Result
Install and verify Verified
Read a file in the protected project Allowed
Append a line to a source file Denied
Append a line to OPEN.md Allowed
git add in the protected project Denied
Change a file in the unregistered project Allowed
Guard deliberately broken, read in the protected project Denied
Guard deliberately broken, read in the unregistered project Allowed
Restore the guard, verify again Verified
Uninstall, then write in the formerly protected project Allowed

Three moments are worth a closer look.

The denied source edit came with the hook’s own reason (translated from German), which showed the rule was applied and not something else:

Companion mode locked: writing is only allowed on .project/OPEN.md and .project/HANDOFF.md, using an absolute path

The Git test nearly proved nothing. Our first attempt combined git add and git commit in one command and was blocked. The reason was shell metacharacters, not the Git rule. Only a single git add .project/OPEN.md was denied with the message “Git read-only”. If you test a rule, check why it blocked.

Failing closed is visible. With the guard broken on purpose, even a plain read in the protected project was refused, because the hook raised a syntax error and the block-on-failure setting took over. In the unregistered control project, the same broken guard did not matter.

After restoring, verifying and uninstalling, the formerly protected project was writable again. Being able to take a guard out cleanly is part of its design.

What this does not protect against

We do not call this a sandbox. These limits are known:

  1. Cross-project writes. An agent in an unregistered project may be able to change files in a registered one through absolute paths, because the guard decides by session context. This applies in particular to the direct edit and write tools.
  2. Crash handling. If Python crashes, the fallback decides from a single project signal. In a crash with conflicting signals it can behave differently from the normal case.
  3. Timeouts. A hanging hook can, with block-on-failure, also disturb other projects. We documented this but did not reproduce it.
  4. Scope. The tests cover one Claude Desktop and Claude Code configuration. They say nothing about other agents, plugins, MCP tools, subagents or later versions.
  5. Not an operating system permission model. The guard controls tool calls, not what the user account may do.
  6. Tests are not proof. They show relevant allowed and denied cases, not that every input and every path is covered. The workspace-trust test for the second registered project was not part of this series.

What we take from it

  • An instruction is not a barrier. Control the tool call, and where possible the operating system as well.
  • Fail-closed needs a precise definition of “unknown”. Mixing up “cannot tell” and “not protected” was our most important flaw.
  • Keep one source of truth for each security decision.
  • Test the exact rule you claim, and check the reason for a block.
  • Test failure, recovery and removal, not only the normal case.
  • The human stays the approver. The guard supports that split of work and does not replace review.

Hooks are the part of this setup we would reuse first. They are cheap, they run before the action and they can be tested on their own. Just do not mistake them for more than they are.