I Made My AI Agent Rule Files Read-Only. 5 of 8 Edits Still Bypassed It (And the Real Fix Broke Git)
Last weekend I ran chmod 444 on AGENTS.md , CLAUDE.md , .cursor/rules/safety.mdc , and .claude/skills/safe-deploy.md inside a local Git test repository, assuming read-only file permissions would stop a coding agent from rewriting its own guardrails. When I ran 8 ordinary file mutation commands against that repository on macOS 26.2, chmod 444 blocked only 3 of them. The other 5 commands, including…
In a recent experiment, the author attempted to secure a local Git repository by setting read-only permissions on specific guardrail files using the chmod 444 command. However, this approach only blocked 3 out of 8 mutation commands, leaving 5 commands unaffected. The author then switched to using OS-level immutable flags (chflags uchg), which successfully blocked all 8 mutation paths.
Despite this success, the use of immutable flags broke git merge and git checkout operations, leaving modified files in the working tree and preventing further actions.
The author highlights that plain repository files, such as AGENTS.md, CLAUDE.md, and skill files, are used by coding agents with the same user ID as the developer running them. When a coding agent has shell access or uses an atomic file editor, it can bypass the read-only restrictions placed on rule files located inside the directory tree the agent is allowed to touch.
Marking rule files as read-only with chmod 444 fails because POSIX permissions do not restrict unlink and rename operations to the target file itself. Instead, they check for write permission in the directory containing the old or new path. This means that atomic editor saves, sed -i, mv -f, and even git itself can succeed in modifying the files, even when they are marked read-only.
The author conducted a benchmark test on macOS 26.2, running 8 mutation vectors and comparing them to the default unprotected baseline. The results showed that chmod 444 blocked only 3 mutation vectors, while chflags uchg blocked all 8. However, chflags uchg also broke git merge and git checkout operations, leaving modified files in the working tree and causing issues when switching branches.
To effectively secure the repository, the author recommends locking individual files with chflags uchg, which blocks the majority of mutation vectors. However, subdirectories containing rule files and new skill files need to be locked separately to prevent bypassing the restrictions. The author also warns that an immutable file checkout can silently allow an agent to create rogue files in writable directories, bypassing the intended protections.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to