r/opencodeCLI • • 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

23 comments sorted by

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)

6

u/arcanemachined 5d ago

I've had agents write fucking tests that asserted that my AGENTS.md file contained specific lines.

Kill me please.

3

u/Starks1293 5d ago

ha yes, thats the trap. the test has to fail when the code breaks the rule, not when a sentence goes missing from AGENTS.md. i ask for it that way too: "write a test that fails if anyone does X in the code", never "test that the rule exists"

1

u/Ok-Buyer-9421 6d ago

Definitely. Especially on keeping the model-as-judge part small. In one of my audits, 97.6% of checks were handled by glob and grep alone.
Really like your approach of AGENTS.md pointing to the tests that enforce each rule. Will check out AI Bridge :)

1

u/Praistaly 5d ago

yeah the commit hook point is spot on, trying to prompt away deterministic stuff just wastes tokens and still fails half the time

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.

1

u/Ok-Buyer-9421 5d ago

Really like your point about not just blocking but explaining why and what to do instead. The challenge with layered enforcement is keeping the rules consistent across hooks, CI and different agent harnesses. Ideally, you'd define the rule once and enforce it at different stages. Thanks for sharing :)

2

u/seventyfivepupmstr 5d ago

This shows that you don't understand how LLM use their context...

1

u/Ok-Buyer-9421 5d ago

Could you elaborate? I'm not suggesting AGENTS.md is useless or that models don't use their context. I'm questioning whether providing instructions is sufficient to guarantee they're followed. Those seem like two different problems to me.

1

u/seventyfivepupmstr 5d ago

The larger the context, the more confusion it causes in the LLM reasoning. Its counter-intuitive in some senses, but you need clear and concise instructions if you want consistent behavior. The reason the LLM is ignoring your instructions is because they are generic instructions and not relevant to the task its actually working on

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.

1

u/Ok-Buyer-9421 5d ago

That's a good point. I believce that models learn a more from the patterns they see in the codebase than from instructions in a context file. If the code contradicts the rule, the rule is fighting the strongest signal. I think the distinction is between rules the code should already embody and decisions that can't be inferred from existing patterns. The latter still need to be documented and enforced. Makes me wonder if the best starting point is to make the codebase compliant first, then use tests to prevent it from drifting back.

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/Ok-Buyer-9421 5d ago

read through the paper - i love the empirical approach.
It's very mucha ligned with the idea behind Agentests, a project i am building. It turns written rules into executable checks rather than relying on the agent to follow them (if you wanted to check the approach: https://github.com/feuersteiner/agentests. Curious on your take here. We're trying to make it easy to turn both architectural and behavioural rules into checks that run automatically regardless of who wrote the code.

2

u/SirRobinBlibs 5d ago

Turning rules into checks is the right direction, whatever runs them. The thing I'd look at with any rule-to-check tool is where the check runs: if it's a hook the agent can skip or a CI job that only warns, you're back to a wishlist, so I'd make it a required check that blocks the merge.

1

u/rm-rf-rm 5d ago

have you heard of CI?

1

u/Ok-Buyer-9421 5d ago

Yes, that's exactly the point. CI only catches what you've explicitly encoded as a check. I'm exploring how to turn the rules that currently only live in AGENTS.md into those checks, including the ones that require semantic judgment rather than a conventional linter.

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/asanabria6910 5d ago

I created https://github.com/linuxdynasty/debrief in order to help me be more efficient with my worlflows.

1

u/Ok-Buyer-9421 5d ago

Yeah, hooks are probably the right enforcement point when you need something deterministic across different agents. Skills and subagents can guide behaviour, but they can't guarantee it. Cool for Debrief, I'll check it out.

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.