Skip to content
Rule files are not documentation; they are the team's interface

Rule files are not documentation; they are the team's interface

I deleted the seven-hundred-plus-line AGENTS.md at the repo root down to under a hundred lines. The PR description just had the diff, plus one line: I asked several people about every deleted item, and no one could say where it came from.

No one objected. That reaction is more alarming than what was deleted: a seven-hundred-line rule file that no one on the team owns, yet every day the model and new colleagues read it as fact.

The default assumption for documentation is that someone reads it start to finish; the default assumption for an interface is that the caller reads only the few lines they need, and may read them wrong or read an outdated version. Once a rule file is consumed by a model, it’s more like the latter. When writing docs we aim for completeness; when writing interfaces we aim for clear boundaries. If a rule file is treated only as documentation, the author tends to cram in everything they know; once it’s treated as an interface, the first reaction becomes: who calls this rule, in what scenario, and what happens if the call fails. Switch that perspective and a lot of “nice to have” entries drop out on their own.

Rule files don’t get written badly, they get copied badly

At first we had only one convention. Then we brought in a coding assistant, and there was an extra AGENTS.md; then we switched tools, and there was an extra .cursorrules; then I copied part of it into the onboarding doc, because new hires won’t go digging in the repo root.

The three files were really about the same thing, but said differently. The one in the repo said “commit messages in English, first line no more than 72 characters,” the onboarding doc said “commit messages uniformly in English,” and the assistant’s said “commit message in English, concise.” They looked consistent, but in practice everyone went in the loosest direction—who decides what counts as concise? In the end no one was constrained.

An even more common way to die is writing things that no longer exist into the rules. One entry said “new components go under src/components/legacy/,” and that directory had been deleted three months earlier. The model followed the suggestion and created a new legacy directory, and no one flagged it in review, because that’s what the rules said.

So I set a hard rule: a rule has only one physical source; everywhere else can only reference it, never copy it.

PLAINTEXT5 lines
1
2
3
4
5
repo/
├── RULES.md # 唯一来源,正文只在这里
├── AGENTS.md # 5 行:定位 + 指向 RULES.md + 禁止复制
├── .cursor/rules/*.mdc # 每条规则一个文件,frontmatter 用 glob 限定生效范围
└── docs/rules/CHANGELOG.md # 只记“为什么改”,不重复内容

A single source isn’t for looks. The problem with copies isn’t just space—it’s that each copy ages independently: one gets changed, another doesn’t, and the reader doesn’t know which version they got. What a rule file fears most isn’t being wrong, it’s having multiple versions of the same thing, each of which looks real.

I really like the .mdc approach of one file per rule—not because the tooling supports it, but because it naturally turns “a rule” into a unit that can be diffed, blamed, and deleted on its own. In a seven-hundred-line single file, you can’t assign an owner to a single line.

What an enforceable rule looks like

I gave a template, five sections; miss one and it gets sent back.

MARKDOWN6 lines
1
2
3
4
5
6
### R-014 新增接口必须带超时
- 场景:调用任何外部 HTTP 服务
- 动作:显式设置 connect 与 read 超时,默认各 2s / 5s
- 反例:`http.Get(url)` 直接调用;只设总超时不分段
- 负责人:@我
- 复查:2026-01 之前确认默认值是否还合适

“Scenario” and “counterexample” are the two most useful sections. A rule saying “code should be robust” is useless; a rule saying “when calling external services you must set a timeout, the counterexample being a bare http.Get“ is something people can check against. The counterexample matters especially—it clarifies the boundary: does setting an overall timeout without per-stage timeouts count? When there’s a question mark in your mind, review has something to talk about.

The “review” line was added later. A rule with no expiry date lives on until it becomes a burden. We now default to filling in six months out; at expiry you don’t have to change it, but someone has to look at it and say “still valid.”

The template has a side effect: it makes writing rules slow. Before, adding one took ten seconds; now you have to fill in scenario, counterexample, owner, and review date, and many people give up halfway. That friction is deliberate—most rules aren’t worth writing in the first place.

Review isn’t a vote, it’s finding out when it will hurt people

Rule-file PRs go through review like any other PR, but the template is different. I only ask three things:

  1. What has this rule stopped? A new rule must cite a real example that happened, or a requirement about to ship. If you can’t think of one, don’t write it yet.
  2. What does it overlap with? If it overlaps, change the old one, don’t add a new one.
  3. Who reviews it, and when?

These three questions apply to old rules too. Whenever someone proposes an addition, I flip through the existing entries to see if any of them no longer has anyone who can say what it stopped. If old rules aren’t cleaned up, new rules keep piling on, and eventually you’re back at seven hundred lines.

I also added a budget: the root rule file must not exceed 120 lines; go over and you have to delete first. It’s crude, but it works. Rule files don’t grow like code: code can be split into modules, but more rules just means no one reads them.

The budget system has an implicit premise: deleting is harder than adding, so it needs dedicated time. Otherwise every review is about “should we add,” and no one wants to say “this one can go” in the same meeting.

In review I’d rather hear “I don’t agree with this” than “looks good.” A rule that passes unanimously usually means no one actually read it. So the PR template has a field for “counterexample or objection”—leaving it blank is fine, but it makes the review look unfinished.

There’s also a fixed ritual: the last Wednesday of every month, 30 minutes, and the meeting is literally called “Delete Rules.” No additions, no discussion of new requirements, just three things: delete what no one references; renew or delete what’s expired; and pull out any rule that’s been violated more than three times to see if the rule itself is wrong.

This lesson was learned the hard way. If a rule is frequently violated, don’t rush to tighten enforcement—it’s probably unrealistic. We had a rule “all PRs under 400 lines,” but in practice a large batch of PRs sat around 600 lines. It wasn’t that people wouldn’t follow the rules; splitting cost more than it was worth. We changed it to “over 400 lines requires a sentence in the description explaining why,” and the violation rate dropped immediately, because it became an explanation cost rather than a hard wall.

What’s still unsettled

I still haven’t settled whether rule files should be read by the model or by people. The optimal writing differs: for the model, short, unambiguous, ideally with executable criteria; for people, context and “why” are fine. Right now the same file has both the rule and a sentence of why, with comments distinguishing priority. But that’s probably just a compromise, not an answer.

If forced to pick a default, I’d make sure people can understand it first, then have tooling generate the short model-side version. The reverse—writing only for the model—makes it hard for people to judge whether it’s right.

There’s a half-hour meeting already on the calendar for next week, with three words on it: Delete Rules. Only two people are attending, me and a new colleague—the only person who actually read it start to finish. I want to hear which entries he thinks are useless.

About this Post

This post is written by Lu's Blog, licensed under CC BY-NC 4.0.

#Documentation #Engineering Standards #Team Collaboration

Comments