{"slug": "my-agent-guard-blocked-its-own-health-check", "title": "My agent guard blocked its own health check", "summary": "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.", "body_md": "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](https://thumbgate.ai/pricing?utm_source=devto&utm_medium=article&utm_campaign=daily-2026-11-19)\n\nI 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.\n\nThe 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.\n\nWith 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.\n\nThe 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.\n\nThat 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.\n\nThe 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.\n\nThe 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:\n\n`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.\nOne excerpt shows the shape of it:\n\n``` js\n// Redirect targets: `> file`, `>> file`, `2> file` (not `2>&1`).\nfor (const m of seg.text.matchAll(/(?:^|[^<>&\\d])\\d?>>?\\s*([^\\s>&]\\S*)/g)) {\n  const t = resolve(m[1]);\n  if (t && isGuarded(t, false)) return true;\n}\nif (DESTRUCTIVE_HEADS.has(seg.head) && paths.some((p) => isGuarded(p, true))) return true;\n```\n\nInterpreters 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.\n\nI 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.\n\nThe same commit made `--help` exit 0, since a usage screen should not look like a failure.\n\nIf you run agents with approvals off, you will write hooks like this. Two lessons transfer.\n\nFirst, 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.\n\nSecond, 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.\n\n`;`, `&&`, `||` 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.", "url": "https://wpnews.pro/news/my-agent-guard-blocked-its-own-health-check", "canonical_source": "https://dev.to/igorganapolsky/my-agent-guard-blocked-its-own-health-check-2kk8", "published_at": "2026-11-19 17:05:13+00:00", "updated_at": "2026-11-19 17:15:04.332481+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-safety"], "entities": ["ThumbGate", "Mac YOLO Safeguards", "Claude Code", "Codex", "Cursor"], "also_reported_by": [], "takeaway": "Judge each segment of a shell command separately rather than the whole string, since a guard that denies any command naming both an interpreter and a protected path blocks its own `node ... doctor` health check.", "recommendation": {"advice": "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.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/my-agent-guard-blocked-its-own-health-check", "markdown": "https://wpnews.pro/news/my-agent-guard-blocked-its-own-health-check.md", "text": "https://wpnews.pro/news/my-agent-guard-blocked-its-own-health-check.txt", "jsonld": "https://wpnews.pro/news/my-agent-guard-blocked-its-own-health-check.jsonld"}}