A guard that protects itself by keyword ends up blocking you from reading it A developer added a credential guard to Mac YOLO Safeguards, a hook that screens shell commands and file reads made by AI coding agents on macOS, denying access to the keychain, browser credential stores, and quarantine-flag removal. The guard's initial self-protection rule matched keywords across the whole command line, which wrongly blocked harmless commands like running its own doctor after a cd or grepping ~/.claude/settings.json to confirm the hook was installed. The rule was rewritten to parse each command part and deny only writes targeting guarded paths, with Edit/Write checks that block only removal of the guard's marker, backed by 52 lines of new tests. Yesterday we added a credential guard to Mac YOLO Safeguards. It is a hook that runs before every shell command or file read an AI coding agent makes on your Mac, and it denies the ones that touch the keychain, copy a browser's credential store, or strip the quarantine flag from a download. A guard like that has to protect itself too, because the cheapest way for an agent to get around it is to edit its config or delete it. So the first version had a rule: deny any command that changes the guard's own settings. The rule was written the obvious way. Deny a command if it contains a write operation or an interpreter anywhere, and the guard's name or folder also appears anywhere. Two conditions, both checked against the whole command line as one string. Once the hook was live on the machine that built it, two harmless commands were refused as guard-config changes. One was running the guard's own doctor after a cd . The other was a grep of ~/.claude/settings.json to see whether the hook was installed. Neither writes anything. A string match over the whole command cannot tell the difference between mentioning a file and changing it. That is the general trap with self-protection by keyword. The guard ends up blocking the commands you use to check that it works, and the first time that happens you start thinking about turning it off. The check now looks at each part of a command separately and asks one question: does this part write to something the guard protects? The guard's own subcommands are split by what they do. install , uninstall and fix are denied, and so is work-folders with anything other than list . doctor , check and --help pass. Shell writes are denied only when the target is a guarded path: the config folder, the installed guard, or an agent's hook file. The target is found from the things that actually write: a redirect, rm , mv , ln , chmod , sed -i , jq -i , tee , the destination of a cp , or an interpreter that names the path. Relative paths are resolved through any cd earlier in the same command, so changing directory first does not hide the target. For Edit and Write calls to an agent's hook file, the rule is narrower still. An agent may edit its own settings. It may not remove the guard's entry from them. The check compares the old and new text and denies only if the guard's name goes missing: if current.includes MARKER && input.content.includes MARKER return true; // ... if edits.some e = text e.old string .includes MARKER && text e.new string .includes MARKER return true; One more case. The guard has a check --