Last week's part showed every step your AI and its helpers took, and the two stops on that timeline: customers.csv and .env, each with "A rule in your settings stopped it." This part is where those stops come from, and the routes they leave open.
Two ways to read a file
Claude Code can read a file in two ways. With its own Read tool, which names the file. Or with a shell command, where the file is somewhere inside a line of text.
A deny rule in Claude Code's settings covers the first way. It names a tool and a path, Read(.env*), and Claude Code refuses the call before it runs. In my setup such a refusal fired no hook at all, so it showed up only in the saved conversation.
The shell is the harder half. In September I tried a deny list of shell verbs: cat, grep, head. python3 -c printed the whole file anyway. A list of verbs doesn't close the shell.
What init writes
npx @agentwhy/cli init
In a terminal it asks who the setup is for, what agentwhy should do in this project, and what else to protect. Then it shows the exact JSON it will add and asks before writing. It writes to .claude/settings.local.json, which is yours and stays out of the repository, unless you say the change is for everyone.
Two things go in. A hook that runs before every shell command: the check the rest of this post is about. And deny rules, Read(...) and Edit(...), for each file you name, with --protect or when init asks what else to protect.
Name no file, and the check falls back to a built-in list: .env*, *.env, .npmrc, secrets/, .ssh/ and id_rsa*. But then no deny rule is written, so Claude Code's own Read tool is not stopped for those files, only the shell. Name them, with init --protect ".env*" for example, and you get both halves; from then on the check reads your list instead of the built-in one. Since .env* is a pattern, it also refuses cat .env.example.

Settings in the demo, a made-up project: the private files, each set to Block.
What the check reads
It does not look for verbs. It reads a command for the files it would read, and refuses the command if one of them is private:
-
cat .env, a file named outright. -
cat .env*, a glob that expands to one. -
grep -rorrgover a folder that holds one. That is the route from my incident in September: a helper searched the project for a variable's name, never named.env.development, and the search printed the line with the value. -
find -exec cat,find | xargs cat,for f in $(find …): a listing whose names another program opens. - A
cdinto the folder, then the read.
It judges what a command would read, not what it writes. echo X=1 >> .env still runs.
What your AI is told
When the check refuses a command, Claude Code doesn't run it, and the agent gets agentwhy's reason instead. For a search that would have printed from .env, it reads:
agentwhy refused this command: this search would read .env, which this project's policy protects (**/.env*).
Protected files are kept out of the agent's reach. Tell the user agentwhy blocked the command.
Do not ask them to paste this file or a secret value into the chat; they can inspect it in their IDE.
It names the file, because the agent would see the name in a listing anyway, and never anything from inside it. It suggests no other way in. And it tells the agent not to ask you to paste the value, since a pasted key reaches the model just the same. The one time I measured it, Claude Code blocked the command before it ran, and the agent asked me instead of working around it.
The refusal is also in the saved conversation, so it is one of the stops you saw in part 1's Step by step.

Step by step, Only private, in the demo: a tracked read, a stop by a rule, and a helper that was stopped too.
Codex and Copilot
Codex runs the same check as a hook, with the same list of files. Codex skips a hook nobody approved without a word, and in VS Code the first conversation starts before anything can be approved. So init writes the check into your own ~/.codex/hooks.json and approves its own two entries in ~/.codex/config.toml, and nothing else: no folder is marked trusted. Before writing, it runs the check once the way Codex will, and writes nothing if that fails. So it blocks from the first message, in the terminal and in VS Code. Measured on Codex 0.159.
In GitHub Copilot the check runs once you turn it on: Block in Copilot too in Settings, or init --copilot. There it also judges Copilot's own file tools, so a read, an edit or a search that would open a private file is refused. One gap I measured on 13 October: in VS Code, a file open in the editor, or attached to a question, is handed to Copilot by VS Code itself, with no tool call to check. A blocked .env open in a tab reached Copilot that way. Close a blocked file before you ask.
What still gets past
The check reads the command line, not what runs. So these pass:
- A path held in a variable, or built while the command runs.
- A script, or a program the check doesn't know.
- A command handed to another shell,
sh -c '…'. - In Copilot, a call made while agentwhy can't start, after a Node upgrade, say. Copilot runs it unchecked rather than stopping your work.
It is not a sandbox. What holds against the shell route is a sandbox at the level of the operating system, or a secret that isn't in a plain file in the first place: if there is nothing on disk, there is nothing to print. The check closes the obvious routes. The record stays for whatever went another way.
Try it
Use a key that isn't real. In a test project, put a made-up line in .env, such as TEST_KEY=not-a-real-key, then:
npx @agentwhy/cli init --protect ".env*"
Ask your AI where TEST_KEY is set, and read what it answers. Afterwards npx @agentwhy/cli opens the report, with the attempt on its timeline. Don't try it on a project with real keys: if a route gets past, the value is in the conversation.
Next week, part 3: hiding a key before the AI reads it, for the key that sits in a file no rule names.
If you wanted to get past this check, which route would you try first?
Disclosure: I build agentwhy, the open-source tool this post describes.
Top comments (0)