DEV Community

Cover image for One "yes" can delete your coding agent's deny rules. Snapshot them.
Redlio Labs
Redlio Labs

Posted on

One "yes" can delete your coding agent's deny rules. Snapshot them.

Last week, two preprints and a Cloud Security Alliance research note described a problem with coding-agent permissions that is easy to miss: answering a permission prompt can change the rules the next prompts are checked against.

The paper, When Answering Is Administering (Fei et al., Nov 2026), looks at Claude Code first and names Codex, Gemini CLI, opencode and Goose as related designs. Its abstract puts the root cause plainly: Claude Code "checks only updates that add or replace allow rules." A reply to a permission prompt can carry rule updates, so a reply that deletes a deny rule goes through.

The CSA note gives the example that makes it concrete. Whoever answers the prompt approves an unrelated command and, in the same reply, removes Read(./.env) from your user settings. The sandbox is built from the same deny rules, so it loses that restriction too. The agent can now read the file in this session and the next.

Two details make this worse than it sounds:

  • The answer doesn't have to come from you. Permission prompts can be answered by plugins with permission hooks, SDK apps and remote or mobile relays. The paper says relays that forward these deletions exist, "including the vendor's own Remote Control." CSA surveyed 70 relays and front ends and found 5 that forward remote-written rule updates.
  • Nothing records who changed the rule. Rules carry no author, so the deletion "leaves the same record as an edit by the operator."

It isn't widespread abuse. Of 2,227 marketplace plugins the researchers fetched, only two send policy updates at all. But a deny rule you wrote last month is only as good as the last party that answered a prompt.

How a permission reply removes a deny rule: approve an unrelated command, attach a rule update, the deny rule is gone, and the sandbox follows

The real fix: managed settings

If a rule must never change, don't keep it in a file the agent can write. Claude Code reads managed settings from a system path:

  • macOS: /Library/Application Support/ClaudeCode/managed-settings.json
  • Linux and WSL: /etc/claude-code/managed-settings.json
  • Windows: C:\Program Files\ClaudeCode\managed-settings.json

Managed settings sit at the top of the precedence order. A deny rule there can't be overridden by user or project settings, and permission replies can't write to it. Put your non-negotiables there: credential files, SSH keys, cloud config.

{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(~/.ssh/**)",
      "Read(~/.aws/**)"
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

For a team machine, CSA also suggests allowManagedPermissionRulesOnly, which makes managed settings the only source of permission rules. It's strict: user and project allow, ask and deny rules are ignored, so move every rule you rely on into the managed file first.

Detect the change anywhere else

Most of us still keep rules in ~/.claude/settings.json and the project's .claude/settings.json. CSA's other recommendation is to snapshot those and alert when the deny list changes. Here is a small script that does it:

// deny-watch.mjs: snapshot your coding agent's permission rules and
// alert when a deny rule disappears or a new allow rule shows up.
// Usage: node deny-watch.mjs            (compare against the snapshot)
//        node deny-watch.mjs --accept   (you made the change: save a new snapshot)
import { readFile, writeFile } from "node:fs/promises";
import { homedir } from "node:os";
import { join, resolve } from "node:path";

const FILES = [
  join(homedir(), ".claude/settings.json"),
  resolve(".claude/settings.json"),
  resolve(".claude/settings.local.json"),
];
const SNAPSHOT = join(homedir(), ".claude/permission-snapshot.json");

async function readJson(path) {
  try { return JSON.parse(await readFile(path, "utf8")); } catch { return null; }
}

// Current rules as a set of "file | kind | rule" strings.
const current = new Set();
for (const file of FILES) {
  const p = (await readJson(file))?.permissions ?? {};
  for (const kind of ["deny", "ask", "allow"])
    for (const rule of p[kind] ?? []) current.add(`${file} | ${kind} | ${rule}`);
}

const saved = await readJson(SNAPSHOT);
if (!saved || process.argv.includes("--accept")) {
  await writeFile(SNAPSHOT, JSON.stringify([...current].sort(), null, 2));
  console.log(`Saved ${current.size} rules to ${SNAPSHOT}`);
  process.exit(0);
}

const before = new Set(saved);
// Removing deny/ask rules or adding allow rules makes the agent refuse less.
const loosened = [
  ...[...before].filter((r) => !current.has(r) && !r.includes(" | allow | ")).map((r) => `REMOVED  ${r}`),
  ...[...current].filter((r) => !before.has(r) && r.includes(" | allow | ")).map((r) => `ADDED    ${r}`),
];
const tightened = [
  ...[...current].filter((r) => !before.has(r) && !r.includes(" | allow | ")),
  ...[...before].filter((r) => !current.has(r) && r.includes(" | allow | ")),
];

for (const line of loosened) console.log(line);
if (tightened.length) console.log(`(${tightened.length} change(s) that only tighten the policy)`);
console.log(loosened.length
  ? `\n${loosened.length} change(s) loosened your policy. If you didn't make them, find out who did.`
  : "No loosening changes since the snapshot.");
process.exitCode = loosened.length ? 1 : 0;
Enter fullscreen mode Exit fullscreen mode

Run it once to save a snapshot, then again whenever you want to check. Here's what it printed in a test setup after I deleted the .env deny rule from user settings and added an allow rule to the project's local settings (paths shortened):

REMOVED  /home/me/.claude/settings.json | deny | Read(./.env)
ADDED    /home/me/project/.claude/settings.local.json | allow | Bash(git push:*)

2 change(s) loosened your policy. If you didn't make them, find out who did.
Enter fullscreen mode Exit fullscreen mode

It only reports changes that make the agent refuse less: a deny or ask rule removed, or an allow rule added. Tightening changes are counted but don't fail the check. When you made the change yourself, run it with --accept.

Where to run it

  • At the start of each session. Add it as a SessionStart hook, so a change made in the last session shows up before the next one starts.
  • In CI for project settings. .claude/settings.json is committed, so a pull request that loosens it should get a human look. The exit code makes that easy.
  • Before you trust a new relay or plugin. Snapshot, use it for a day, then compare.

What it doesn't do

It doesn't stop the change. It tells you after the fact, which is what CSA's detection advice is for. It reads the three common settings files, not managed settings (those can't be changed this way) or rules passed on the command line. And the snapshot lives in your home folder, so anything that can rewrite your settings could rewrite it too. If that's in your threat model, keep the snapshot in version control or somewhere the agent can't write.

The bigger lesson from the paper is a design one: answering is not administering. Until runtimes record who wrote each rule, the safest deny rules are the ones the agent can't reach.


I'm Mayursinh, founder of Redlio Labs. We build custom software and add AI features and agents to it for mid-size companies. The script was tested on Node 22 with a throwaway home folder.

Top comments (1)

Collapse
 
leoamos profile image
Leo Amos •

Worth adding that managed-settings.json only helps if the agent's user can't write it. On macOS and Linux keep it owned by root with 644 permissions, so even a fully trusted session can't edit it. For the user-level file, keeping ~/.claude in a small git repo and diffing it before each session catches a deleted deny rule before you start work.