Claude Code Ignored My `Write` Deny Rule: 6 Checks Before Running `claude -p` Unattended

I added a directory so an unattended Claude Code session could read it, and the control run wrote a file there. I wrote a deny rule for the Write tool, and it was ignored.
For two trial periods this autumn, the second ending on November 8, 2026, launchd on my Mac started claude -p at 10:00 each morning to prepare a blog draft for me to review.
Nobody was at the keyboard, so the permission flags decided what the session could touch in the rest of my projects.
The job needs an awkward shape.
It must read several sibling repositories to verify what it writes, and it may create Markdown files in exactly one folder, drafts/.
On October 10, 2026, while fixing the runner's permission setup, I measured the flags. I ran sessions with a small model (Haiku) against a fake directory tree in a scratch folder, and I judged each result by what was on disk afterwards, not by what the session said it did. My notes keep the outcome of each probe, not the transcripts.
Below are the six results, the invocation I ended up with, and for each result whether the documentation (read on November 13, 2026) describes it.
1. A Write(path) deny rule did nothing
I tried a deny rule named after the Write tool.
The CLI warned that the rule does not match file permission checks and told me to use Edit(path) instead, then carried on with the rule ignored.
That wording is my paraphrase; I did not save the warning text.
A single Edit(//<abs>/**) deny rule then blocked every file-editing tool, Write included.
Two details are easy to get wrong.
The rule that covers file writes is named Edit.
An absolute path starts with two slashes: //<repo>/drafts, not /<repo>/drafts.
Documented: yes.
The permissions page says Claude Code accepts a Write(path) rule but does not match an edit against it, that Edit rules apply to all built-in tools that edit files, and that a single leading slash anchors at the settings source, not at the filesystem root.
2. acceptEdits approved writes inside --add-dir directories
The session has to read my wiki repository, which sits outside the working directory, so the plan was --add-dir.
In the fake root, with --permission-mode acceptEdits, the control run created a file inside the added directory.
Adding a directory for reading also opened it for writing.
Documented: yes.
The permissions page says files in additional directories follow the same permission rules as the working directory, and the permission modes page scopes acceptEdits auto-approval to the working directory or additionalDirectories.
3. A deny on the parent beat the allow on the child
The obvious repair was a deny list: block Edit on the whole projects root and keep drafts/ writable.
With the deny rule on the root, the write into drafts/ inside the blog repository was refused too.
"Root is read-only, one subfolder is writable" cannot be written as a deny list.
Documented: yes. Rules are evaluated deny, then ask, then allow, and the permissions page states that an allow rule can't carve an exception out of a deny rule.
4. dontAsk plus one Edit allow rule produced the shape I wanted
The configuration that worked inverts the approach: deny by default, allow one pattern.
--permission-mode dontAsk --allowedTools "Edit(//<repo>/drafts/*.md)"
In the fake root, writes to another repository, to the blog repository outside drafts/, and to drafts/sub/ were all refused.
A write to drafts/x.md succeeded.
Read and read-only Bash commands (ls, grep -rn) still ran although neither was on the allow list.
Documented: yes, with one conflict.
The permission modes page says dontAsk denies every call that would otherwise prompt, while file reads in the working directories and a built-in set of read-only Bash commands still run.
The refusal of drafts/sub/ matches gitignore syntax, where * stays within one path segment.
The conflict is git status --porcelain.
The current page lists read-only forms of git in the set that runs without a prompt in every mode.
My runner logs show that exact command refused in unattended runs on September 7, 9, 10 and 11 and again on October 10, until I added Bash(git status --porcelain) to the allow list.
Those refused runs used acceptEdits with --permission-prompts none and an allow list; the runner moved to dontAsk later on October 10.
I do not know whether the behavior changed between releases or whether something in my setup caused the refusals.
I keep the explicit entry.
5. Without --strict-mcp-config, the session inherited my connectors
A probe session started without the flag had three documentation tools loaded and about 190 deferred MCP tools exposed, including my mail, issue-tracker and GitHub connectors. An unattended drafting job has no use for any of them.
With --strict-mcp-config and no --mcp-config, the session had zero MCP tools.
Documented: partly.
The CLI reference describes the flag as using only the servers from --mcp-config, and the headless page says a -p run discovers and loads MCP servers as an interactive session would.
The tool counts, and the empty result when the flag is passed alone, are my measurement.
6. The model's report did not show that a command ran
This one came from the runner's own log, not from the probes.
On September 4, I added an allow list that omitted git status --porcelain, the first command the prompt asks for.
Three consecutive runs (September 9 to 11) were refused that command and then answered RESULT: SKIPPED_DIRTY anyway, judging the tree from the git status snapshot that the session receives at startup.
They said so in their prose.
The result line itself looked exactly like a run that had executed the command.
The runs on September 5, 6 and 8, also before the command was on the allow list, reported the tree as clean and mentioned no refusal. From a text log I cannot tell whether the command ran in those sessions.
On October 10, one run printed only Execution error, and my wrapper logged it as finished because the exit code was 0.
The headless page says the CLI exits non-zero when a run fails, so this is a second place where my log and the documentation disagree, and I have a single occurrence.
The runner now accepts a run only when the output contains one of four contract results:
if ! grep -qE 'RESULT: (SKIPPED_DIRTY|SKIPPED_BACKLOG|NO_ELIGIBLE|DRAFTS_READY)' "$RUN_OUTPUT"; then
fail "model run ended without a contract RESULT line"
fi
The list is closed because one run invented RESULT: TOOL_FAILED.
The headless page also documents --output-format stream-json, whose final message lists permission_denials; my runner still uses text output, so I have not tested that route.
The invocation
This is the call from my runner script, with the prompt and the logging trimmed:
claude -p "$PROMPT" \
--model claude-sonnet-5 \
--permission-mode dontAsk \
--permission-prompts none \
--strict-mcp-config \
--add-dir "$PROJECTS_PHYSICAL" \
--allowedTools \
"Edit(/$BLOG_PHYSICAL/drafts/*.md)" \
"Bash(git status --porcelain)" \
"Bash(node scripts/topic-clusters.mjs --top 35)" \
"Bash(pnpm blog:check)" \
--output-format text >"$RUN_OUTPUT" 2>&1 || model_exit=$?
$BLOG_PHYSICAL comes from pwd -P and already starts with a slash, so the rule expands to Edit(//<repo>/drafts/*.md).
I resolve symlinks first because permission rules match the physical path, not a symlinked one.
The documentation's wording is that an allow rule applies only when both the requested path and the file it resolves to match.
--permission-prompts none tells the CLI that nobody can answer a prompt.
The documentation says the flag requires v2.1.259 or later.
Probe a rule before you trust it
This is the procedure I recommend. My notes record the control run, the four locations and the check on disk, not every step below.
- Build a fake root in a temporary folder that mirrors the real layout: the writable folder, a sibling folder, a nested subfolder, and a second "repository".
- Run a control first, with the mode you intend and without the new rule, and ask the session to create a file at each location.
- Confirm on disk that the control wrote the files. A probe that cannot write proves nothing when the rule "blocks" it.
- Delete the files, add the rule, and run the same prompt.
- Check the disk again with
lsorfind. Do not read the session's summary as the result. - Write down the CLI version next to the result. I did not, and it limits everything above.
I used a small model for the probes; the permissions page says the rules are enforced by Claude Code, not by the model.
The decision that could go another way
I chose an allow list on the host: dontAsk, one Edit pattern, three exact Bash commands.
The documentation recommends dontAsk for CI pipelines and restricted environments where the allowed actions are defined in advance, which describes this job.
acceptEdits with deny rules fits the opposite shape, where the session may edit almost everywhere it can see and a few paths are subtracted.
It could not express mine, for the reason in result 3.
The strongest argument against my choice is that permission rules bound tool calls, not processes.
The permissions page warns that Edit deny rules do not apply to subprocesses that write files indirectly, and its example is a Node script.
Two of my three allowed commands run Node, with my full account's access.
If those scripts or their dependencies misbehave, no permission rule is involved.
The sandbox addresses that gap from the other side: it is enforced by the operating system around shell commands and their child processes, it is off by default, and it does not cover the file tools, which keep following permission rules. The documentation presents the two as complementary layers. I have not measured the sandbox in an unattended run.
--dangerously-skip-permissions in a throwaway container or VM is the remaining option, and the documentation restricts it to isolated environments and says it offers no protection against prompt injection.
My job reads every repository under my projects root, so that VM would need all of them mounted.
I have not built or measured that setup.
Someone whose agent runs untrusted build scripts should weigh that differently and start from the OS boundary.
Limits
Everything in results 1 to 5 was measured on October 10, 2026, with a small model in a fake root. I did not record the CLI version that day. The September and October log entries in result 6 are single observations from one scheduled job.
The documentation comparison reflects the pages as they read on November 13, 2026, and I did not re-run the probes against the current release.
Where the documentation and my logs disagree, in the git status refusals and the exit code after Execution error, I have reported both and resolved neither.
Permission behavior has changed between releases before; the pages I read carry several "requires v2.1.x or later" notes. Treat the invocation above as a starting point and run the probe on your own version.
Get the next post.
Follow new posts in your RSS reader.