cd /news/ai-agents/my-agent-guard-blocked-its-own-healt… · home › topics › ai-agents › article
[ARTICLE · art-172695] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

My agent guard blocked its own health check

A developer building Mac YOLO Safeguards, a credential guard for AI coding agents like Claude Code, Codex and Cursor, fixed a self-protection rule that was blocking the guard's own read-only health check and settings greps. The original guard-config check flagged any command containing both an interpreter and the guard's name, so `node .../mac-yolo-credential-guard.js doctor` was denied as an attack on the guard. Commit 86f295d replaces it with a `guardConfigWrite` check that splits commands into parts and judges each, backed by test lists of 17 read-only commands that must pass and 15 write commands that must be denied.

recommendation

Split agent tool-call commands into segments and check each for writes to guarded paths, then keep paired test lists of read-only commands that must pass and writes that must be denied.

more in playbook: Securing agents and AI tools
by read4 min views8 publishedNov 19, 2026

I build ThumbGate, a check that runs before every Claude Code, Codex or Cursor tool call and blocks the risky ones. Free install: npx thumbgate init. Pro is $19/month: https://thumbgate.ai/pricing?utm_source=devto&utm_medium=article&utm_campaign=daily-2026-11-19

I build Mac YOLO Safeguards, a set of guards for AI coding agents that run with approvals turned off. One of them is a credential guard: a hook that Claude Code, Codex and Cursor run before every tool call, and that refuses things like keychain reads and copies of browser login stores. Both it and ThumbGate, my other project, are mine, and this post is about a bug that showed up as soon as the hook was switched on.

The first version of the guard shipped in commit 1319269 on 2026-11-19. It includes a rule called guard-config, whose job is self-protection. An agent must not be able to switch off the thing that is watching it, so the guard refuses install, uninstall and edits to its own settings and to the hook files of each agent.

With the hook live, the guard's own health check, node tools/mac-yolo-credential-guard.js doctor run after a cd, was denied as a guard-config change. So was a grep of ~/.claude/settings.json to see whether the hook was registered. Same rule both times. A read-only look at the guard was being treated as an attack on the guard. The fix is in commit 86f295d, and its message describes both failures.

The original check combined two questions about the whole command string. Did the command contain a write-capable operation or an interpreter anywhere? Did it name the guard anywhere? If both answers were yes, deny.

That sounds careful, and it is, in the way a smoke alarm that goes off when you make toast is careful. node counts as an interpreter, because an interpreter can write any file it names. The path to the guard file contains the guard's name. So node .../mac-yolo-credential-guard.js doctor matched both questions without writing a single byte. The grep of the settings file hit the same pair from the other side.

The deeper problem is the unit of judgment. A command line is not one action. cd /repo && node tool.js doctor 2>&1 | head -20 is three parts, and what matters is what each part does to which file.

The new check, guardConfigWrite in tools/mac-yolo-credential-guard.js, splits the command into parts and judges each one. The rules from the commit message:

install, uninstall, fix and work-folders add or remove are denied. doctor, check, work-folders list and --help pass.rm, mv, ln, chmod, sed -i, jq -i, tee or cp. cd earlier in the same command, so cd ~/.cursor && echo {} > hooks.json is still caught. One excerpt shows the shape of it:

// Redirect targets: `> file`, `>> file`, `2> file` (not `2>&1`).
for (const m of seg.text.matchAll(/(?:^|[^<>&\d])\d?>>?\s*([^\s>&]\S*)/g)) {
  const t = resolve(m[1]);
  if (t && isGuarded(t, false)) return true;
}
if (DESTRUCTIVE_HEADS.has(seg.head) && paths.some((p) => isGuarded(p, true))) return true;

Interpreters keep a conservative rule. An interpreter can write any file it names, so if one appears in the command and a guarded path is also named, the guard still denies. That is why python3 -c "json.dump({}, open('<hook file>', 'w'))" is blocked.

I did not trust myself to get the boundary right by reading it, so the test file tests/test-mac-yolo-credential-guard.js now holds two lists, added in the same commit. Seventeen read-only commands that must pass, including doctor, grep and jq on the hook files, and fifteen write commands that must be denied, including sed -i on the settings file, rm ~/.cursor/hooks.json and the interpreter case above. Both lists run on every change. A guard that blocks too much gets switched off, and a guard that blocks too little is decoration, so each list covers one of those two failures.

The same commit made --help exit 0, since a usage screen should not look like a failure.

If you run agents with approvals off, you will write hooks like this. Two lessons transfer.

First, a deny rule written against the whole command string will eventually block you. Agents chain commands with &&, pipes and cd, and a guard that cannot tell doctor from uninstall pushes you toward turning the guard off, which loses everything it was protecting.

Second, a guard that is too noisy trains you to approve things without reading them. The credential guard's design is also meant to fail safe: commit 5bdef17 made a crash inside the guard deny the call, and an invalid settings file only makes it stricter. Those choices only work if the normal path is quiet enough that you leave it on.

;, &&, || and pipes, and look at the program each part runs, not at words that appear anywhere in the line.npx thumbgate init. It installs in under a minute and blocks the mistakes your agent repeats. Follow me here for one of these build notes every day.

── more in #ai-agents 4 stories · sorted by recency
── more on @thumbgate 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/my-agent-guard-block…] indexed:0 read:4min 2026-11-19 · —