DEV Community

Cover image for No code without a rule: keeping AI coding agents anchored to a specification
Vladimir Troyanenko
Vladimir Troyanenko

Posted on Edited on

No code without a rule: keeping AI coding agents anchored to a specification

Vibe coding works well for one-off and small projects, where technical expertise does not matter and the application can be treated as a black box. That is how the person who coined the term described it: you forget that the code even exists, and it is good enough for throwaway weekend projects.

Writing code by hand used to be the norm, and AI has changed that. Code gets written faster, but on long-lived projects the price is lost expertise and lost control over the code. This is worst where project documentation is thin and decisions that change the code are made in passing: in meetings, in chat threads, in email.
But even good documentation does not solve this. Studies show that documentation falls out of step with the code it describes (Lethbridge, Singer and Forward; Tan et al.). The two are not linked directly: they meet only from time to time, when something gets implemented.

Working on different projects, I arrived at an approach to these problems that fits the way software is built now, with agents writing much of the code. It is called SpecSheriff.

The idea

SpecSheriff is a spec-anchored development method, and the tools that enforce it. You work on the specification: the business logic, plus technical details where they are needed. The agent writes the code. The specification records what the system must do and why; the code shows how. Skills tell it how to work, and hooks check every edit it makes and every commit.
None of SpecSheriff's parts is new. What I could not find anywhere was all of them working together, each covering the gaps the others leave:

What it looks like

In SpecSheriff the specification is not a document in the usual sense. It is a set of small rules, each one a JSON node. Its precision comes from this structure rather than from its prose: permanent IDs, an approval tied to the exact wording, typed links between rules, and tags in code and tests that the checks follow.
Each rule has a permanent identifier (its sid), text stating what is required, and a separate reason that says why. The approval records who approved it and a fingerprint of the exact wording they approved. Change the wording, and the fingerprint no longer matches: the rule is a draft again.
Tests and code carry the rule's sid in an @spec tag, so from any line of code you can reach the rule that justifies it, and from any rule, the code that implements it and the tests that check it.
Why JSON? A schema describes the structure of the specification, and every file is checked against it on every change, so the specification stays structurally consistent as it grows. YAML can be checked against a schema too, but its parsers read some values in surprising ways: PyYAML, a widely used parser, reads NO as false. JSON is not pleasant for people to read, so an optional extension builds readable views from the nodes: a Markdown export, a map of the structure, and a web viewer that redraws itself after each change.

Six principles

  1. Specification first, in one direction
    Every change follows the same order: the rule first, then its test, then the code that makes the test pass. Never the reverse. If you want the code to behave differently, you change a rule; you do not change the code and promise to update the documents someday.
    The order is enforced, not just recommended. Before the agent edits a file, a hook blocks any change to the code of a rule that has no test carrying its tag yet. That hook sees only edits made with the agent's file-editing tools, not with shell commands. Code that gets in by some other route is still checked at commit time: every rule whose code a commit changes must have a test with its tag.

  2. Rule, test and code share a permanent ID, and rules are linked
    The tag sits in a comment directly above each function or class, and in the name of each test. Files in a format without comments carry it in a comment property, such as $comment in JSON Schema, or in a bindings file. In the other direction, the rule's node lists its code and its tests. The tag on the code, the tag on the test and the node's lists must all agree, and the tools check that they do. A tag sits in a comment, but it is a link rather than a comment: changing it counts as changing code, while editing the comment around it does not.
    Rules are connected to one another by links of a few fixed types: one rule implements another, refines it, constrains it, exempts it from being implemented, checks it, or simply cites it. A rule declares its outgoing links, and the tools compute the incoming ones. The tools reject a rule that mentions another without declaring the link. They also reject a link to a rule that does not exist.
    The types matter because an untyped link only says that someone once thought of two rules together. A typed link has a meaning that a check can use. An agent changing a rule sees every rule linked to it. It knows in advance what else the change will affect, and it can be given the rules its task touches rather than the whole specification.

  3. Nothing unapproved is implemented
    Anyone may write or change a rule, an agent included. But a rule is implemented only once one of its owners has read it and approved it. Approving a rule is like approving a pull request, except that what gets approved is the wording of the rule, before a single line of code exists. While a rule is a draft, no commit may add or change code or tests bound to it.
    An agent may approve a rule on an owner's behalf in exactly three cases, and reports each such approval to that owner:
    • the only change to the rule's wording makes it state what an owner has already approved in another related rule;
    • the only change to the rule's wording leaves its meaning unchanged, as when clarifying a term;
    • the rule belongs to the technical appendix, and the agent wrote it while implementing an approved rule of the base specification and linked it to that rule.
    Any shell command that would record an approval stops and asks the user first.
    Anyone who finds an approved rule wrong can withdraw its approval. The rule becomes a draft, and no further change to its code can be committed until an owner approves it again. A large specification can name owners per domain or section, so that the people responsible for a part of the system approve its rules.

  4. Deterministic checks and an independent reviewer
    Deterministic checks run in the agent's harness after every edit, and in git hooks at every commit, on the machine of whoever commits.
    They reject each of the following, with a reason:
    • code with no tag;
    • code whose rule has no test;
    • code whose tag names a draft rule;
    • a commit that does not name the rules its code implements;
    • a change to an approved rule without a change to its tests and code in the same commit, unless the commit message states that none is needed.
    The system's tests must pass before a change reaches the shared branch. A rule of the project's own specification says whether they run on every push or on a server before a merge. The git hooks enforce the checks on every machine that has the plugin installed. To enforce them on machines without the plugin as well, run the same checks in CI.
    Some questions are beyond any deterministic check, so an independent model, the reviewer, answers them at every commit that changes code. It sees nothing from the session that wrote the code; all it gets is the commit message, the change, and the wording of two sets of rules: those the message names, and every rule that tags bind to the changed code or tests. Tests count as part of the system's code, so a changed test is judged too. The deterministic checks confirm only that a tagged test exists and that the tests pass; whether a test really checks its rule is for the reviewer to judge.
    The reviewer answers four questions:
    • whether the changed code does what its rules say, and nothing more;
    • whether each comment the commit adds or changes agrees with the code and its rules (on this point the reviewer only warns);
    • whether the commit message is right when it says that a rule's implementation needs no change;
    • whether a newly approved node of the technical appendix refines the business rules it implements and contradicts none of them.
    If the code does something no rule calls for, or leaves out what a rule requires, the reviewer rejects the commit and names the rule and the line. If the reviewer cannot produce a verdict the tools can read, the commit is rejected as well.

  5. A rule is self-sufficient
    Everything that bears on a rule lives in its node: its text and its reason, its links and the links to it, the decisions made about it, the comments on it and any deferred work on it. When someone asks a year later why the system behaves as it does, the answer is in the rule, not in a chat history.
    What about edge cases? An edge case is part of a rule. The boundary is written in the rule's text and checked by the rule's test.

  6. Three documents, three rates of change
    • The guidelines say how the specification is maintained and implemented. They ship with the plugin and hardly change. A project may extend them but not change them.
    • The base specification says what the system does, without naming any technology. It changes only when the business logic or the core functionality does.
    • The technical appendix says how the system is built, and changes most often. It is inseparable from the base specification: it refines the business rules and never contradicts or restates them.
    A new stack means a new appendix and new code, with no rule of the base specification rewritten. Things only some systems need, such as data formats or a division into domains, are kept in optional extensions of the guidelines that a project chooses.
    In practice, people work mainly on the base specification. The guidelines come with the plugin. The agent drafts the business rules after an ordinary discussion of the task, and a person approves their wording: that approval is the main point of control. The agent writes the technical appendix as it implements approved rules, and the reviewer checks it against the base specification.

Where SpecSheriff sits among spec-driven tools

Birgitta Böckeler divides spec-driven development into three levels:
• spec-first: a well-thought-out specification guides one task and is not kept afterwards;
• spec-anchored: the specification is kept after the task and used to evolve and maintain the system;
• spec-as-source: the specification is the main source, and people edit only the specification, never the code.

Kiro and BMAD-METHOD are spec-first in practice. In Spec Kit, each team decides what happens to a feature's specification once the feature ships. OpenSpec is spec-anchored: it merges each change into a specification of the whole system. In none of them does anything reject a commit whose code departs from the specification: keeping the two in step is left to the team.

SpecSheriff is spec-anchored, with the code held to the specification mechanically, at every edit and every commit. It is spec-as-source only in a narrow sense: if a project chooses the extension for data formats, the types and the run-time data checks are generated from the approved rules.

Böckeler compares spec-as-source with model-driven development, which never took off for business applications. She worries that spec-as-source and spec-anchored tools could end up with the downsides of both: the inflexibility of models and the non-determinism of LLMs. SpecSheriff does raise the level at which you work, from code to rules. But the code stays ordinary code in the repository, written once and changed rule by rule, not regenerated from prose. The agent's non-determinism is contained by the deterministic checks and by the reviewer at every commit.
She also found the Markdown that some of these tools generate tedious to review. In SpecSheriff, the unit of review is one rule's wording, approved by its owner, and the unit of code review is one commit judged against the rules it touches.

What it costs

It is not free. An owner reads and approves every rule whose meaning changes. Every function and class carries a tag; glue code that a framework needs is marked as technical rather than given a rule. The reviewer is a model call at every commit that changes code, paid for by whoever commits, with the model and reasoning effort they choose. The tools do the remembering, so nobody has to keep the rules of the method in their head. The reading and the deciding stay with people.
That is the point. In Fred Brooks's terms from "No Silver Bullet", the agent takes over accidental complexity, the mechanical writing of code. Essential complexity, deciding what the system must do, stays with a person.

Try it

SpecSheriff comes as a plugin for Claude Code and for Codex CLI, two agents whose harnesses offer the hooks it needs. Nothing stops anyone from implementing the method for another agent with hook support. You need git, with user.email configured, and Node.js 24 or later.

For Claude Code:

claude plugin marketplace add non4me/SpecSheriff#release
claude plugin install specsheriff@specsheriff-marketplace
Enter fullscreen mode Exit fullscreen mode

For Codex CLI:

codex plugin marketplace add non4me/SpecSheriff@release
codex plugin add specsheriff@specsheriff-marketplace
Enter fullscreen mode Exit fullscreen mode

Then, in your repository, ask the agent to run the spec-init skill. It sets up the git hooks and the agent's hooks, and asks where your code and tests live, which command runs the tests, and which settings the reviewer should use. You are recorded as the owner of the specification, under your git email. The skill also drafts the project's first rule, that the tests run before every push, for you to approve or change.
If you already have a project and want to try moving it onto the method, use the spec-adopt skill. It turns the project's documentation into draft rules without changing a word of it, goes over the rules with you, and then binds the existing code and tests to the rules you approve. The skill is still new and not yet thoroughly tested, so use it with care, preferably on a separate branch of your repository.

Details are in the repository and on specsheriff.com.

Top comments (0)