r/opencodeCLI • u/Ok-Buyer-9421 • 6d ago
Are agents.md essentially a wishlist?
I audited 20 open-source repos to see how often their written agent rules were actually followed. Four of them banned AI co-author lines in AGENTS.md.
But found that agent PRs added them anyway, 102 times in a month.
So, I've been working on an approach that turns AGENTS.md rules into executable checks:
- Glob selects the relevant files.
- Grep catches deterministic violations.
- A model judges anything that requires interpretation.
The checks live in the repo and don't depend on which coding agent you use.
How do you enforce your AGENTS.md rules beyond putting them in the agent's context?? Tips wanted :)
8
Upvotes
10
u/Starks1293 6d ago
rules in AGENTS.md are a wishlist, rules in tests arent. what works for me in a big repo: when a rule matters, it becomes a test that reads the source. "this module never imports that one" is a test that checks the imports. "every stylesheet sticks to the tokens" is a test that reads every css file. for ur co-author example, thats a commit-msg hook, not a sentence. the agent can ignore a sentence, it cant ignore a red build
what stays in AGENTS.md is the why and the where, which file owns what, so the agent knows where things go and which test will shout if it gets it wrong
id keep the model-as-judge part small, its the one that drifts. if a rule can be a grep, make it a grep
(context, i build a mac app for running these agents, AI Bridge, and most of its rules file by now points at the test that pins each rule)
4
u/vpz 5d ago
Anything in a context file is a suggestion. Doesn't matter what kind of context file. Enforcement depends on the harness. For example agent lifecycle hooks like PreToolUse, Stop, etc. If it's a custom harness/app, it can use deterministic code to apply enforcement at appropriate workflow gates like in a graph-based workflow. If working with git then pre-commit hooks in the local repo like format, lint, test, etc. And then CI related code/tests on PR submission which can include code to send evidence to a human reviewer like screenshots showing a rule was followed. It isn't one thing enforcing rules, it's a system of layered enforcement that tries to catch drift quickly and provide useful feedback to the agent every there is a violation. So don't just block, respond with why and what to do instead if possible.
2
u/seventyfivepupmstr 5d ago
This shows that you don't understand how LLM use their context...
2
u/Orlandocollins 5d ago
I have found that models will always align with patterns they find in the code base. So if you have a rule in an AGENTS.md file that is broken by the code it will continue to get ignored. So I have started shifting the way I think about things to first get the code naturally following the rules I want to enforce. From there you only have to put things in AGENTS.md that they cannot derive from the code itself.
2
u/SirRobinBlibs 5d ago
Pretty much, for hard rules. AGENTS.md is context the model weighs against everything else in the window, so "never do X" is a strong hint, not a guarantee. A recent paper (https://arxiv.org/abs/2611.29916) checked 3,602 AGENTS.md and CLAUDE.md files against their code: path claims were mostly right, but 18% of the dependency rules were already broken by existing code on the day they were written. For the co-author lines, put the check where the commit lands: a commit-msg git hook that rejects or strips Co-Authored-By trailers works whichever agent made the commit, and a CI check catches anyone who skips hooks. If some of those commits came from Claude Code, setting attribution.commit to an empty string stops it adding the line in the first place. Keep AGENTS.md as the map (paths, commands, conventions) and turn each hard "must not" into a check.
1
u/rm-rf-rm 5d ago
have you heard of CI?
1
u/asanabria6910 5d ago
This is why you have to leverage hooks. It doesn't matter if you use opencode or claude. Skills and subagents are all non deterministic.
1
u/sudoer777_ 4d ago
You need lints/commit hooks and enforcement in the allowed CLI/MCP tools/scripts you're using. For stuff that's too difficult to automate, then having an auditor agent on a cheap model can help too.