I’ve worked in AI for over ten years and in big data for far longer. Since taking on those roles, Python has been the technical focus: building some models and some early AI research, but mostly it’s been understanding the parts of AI that are not the model; the best practices and peer review streams, and onward to producing real governance embedded into the pipeline.

But high-level policies need to convert into practices.

In the modern world of “Vibe” coding, this problem is a lot worse. Everyone “knows” that AI can hallucinate, and that having an AI code your model, your app, your business product has built-in dangers. Moreover, everyone knows that AI tokens are expensive and that the mandatory AI training suggests nebulous risks, but how – on an actual practical level – can they protect themselves from producing, at best, slop and, at worst, something that will blow up and break without being able to be fixed easily?

The answer is one of configuration. What follows is what I call “Rules and Locks”. It is a way to “slop-harden” your workflow against the risks of vibe-coding. On one level, it is a set of core best practices, but on another, it is setting up proper system checks before you push data out into the world, and perhaps a way of preventing the worst of AI getting out of hand in the wild.

How to ship AI software: let’s take a closer look, starting with agents.

Agentic AI is quite unlike many other “new shiny” things, and a real sea change in coding. However, as configured by default, AI agents often still get things wrong. The required control is in catching errors and, in the future, remembering them so (much like teaching one’s own children) they won’t repeat them.

Rules

Illustration for the Rules section

(This is for Claude. Codex is similar, using an AGENTS.md file, though in my pack Codex is the reviewer, not the main agent.)

At the start of each session, the agent loads a CLAUDE.md project file, which contains the architecture and conventions that make up the “lessons learned” log for your developments. These lessons trace back to the bug or issue that caused them and the commits involved in that learning; when they are fixed, the agent marks down what would have prevented the bug.

Some examples:

  1. Code that runs fine in the dev environment, but that crashes when “minified” for production (an activity the production build will do when compiling, often on the hosting server).
  2. Form saves that erase stored fields because collapsed sections of the page read as blank, causing the merge write to save over the currently stored values for that collapsed part of the page.

One thing to remember is that while a lesson tells the agent what to do (or, more often, not to do), it doesn’t actually show that the bug is gone. So, in my setup, we add a step after any fix. You take the finding, write a small test for it and then replay the check in three places:

  1. The buggy commit
  2. The fixed commit
  3. A later commit

Then you ensure it fails on the first, passes the second and informs you the bug has returned on the third. I built a lesson command that walks me through any of these steps.

How to keep that rulebook readable

We all know that AI chats degrade after a certain length. This is usually because the entire context window fills up. We also likely know that the coding chat loads the entire CLAUDE.md file into each session, and it hoovers up your tokens very quickly.

Indeed, Anthropic recommends keeping the CLAUDE.md file under 200 lines.

To resolve this, I apply path-scoped rules comprising Markdown files hosted in .claude/rules/ with paths: frontmatter. This means they load only when the agent reads or edits a matching file. This lets you group rules by area, with only a one-line version in the core file, and the agent accesses relevant files and loads the required rules as needed. For example, when you access a data-layer file, the “Save-path” rules load as lessons. This keeps the core file well within the recommended size, while enabling the benefits of rules. The pack checks that the core file stays within a size budget.

Keeping CLAUDE.md efficient as a way to save tokens without losing control is only half the story. The next is tiering.

A smaller startup rulebook, with the full lessons loaded as needed.

Two kinds of tiering

The first kind is to say that the size of any one change sets how hard the change is reviewed. Small, one- to three-line changes, such as a copy or config change, get “self-reviewed” and noted in the commit. Larger changes, one to two files and fewer than 50 lines, get an in-line review plus a grep for callers. Three to five files, on the other hand, trigger a separate reviewer agent, running on the cheaper model (Sonnet in my case). Six files or more, or anything touching architecture, gets two or more agents in parallel, with at least one on the mid-tier model (Opus), with Opus acting as orchestrator and final decider on the findings.

The bigger the change, the heavier the review.

These size values are designed to trigger how many reviewers look into a change, not how risky that change is. Each reviewer checks security first, then correctness, then data integrity, then performance, maintainability, and finally accessibility.

So, nothing is waved through just because it’s a small change.

The second type is accepting reality. By this I mean what I told my son the other day regarding his own Claude coding: This will pass.

I believe Anthropic has been spending more on providing me tokens than I have been paying them. This is a play for the market; a play which has an end. I suspect the IPO is the edge of that end. They have produced models which people switch to, which seemingly hose your weekly token allowance straight out the window at high pressure. This is unsustainable. If you don’t learn to produce lean developments, then you will end up spending a lot more money yourself.

So the “risk” rating of the work decides the model that tackles it. A lower-tier model handles the reading, searching, and filing actions, plus anything with a clear specification. The mid-tier model (Opus in my case) handles design, judgement, and whatever a customer actually pays for (e.g., an AI workout routine). The top models (such as Fable) are held back for more occasional jobs where the wrong answer would cost a lot of hassle, or when I’m doing something cutting-edge. It usually acts as a deciding orchestrator, not a doer: diagnosing, writing the plan for the tier down to build it, and the bottom tier to handle the mechanics.

This is what I mean by agentic AI in action.

Each task opens with a line naming its tier and the reason why; this lets me question the decisions and change the tiers as needed. The rules state that two failed lower-tier model checks get passed up a tier. A failed fix in the mid tier, such as a bug coming back, goes up to the top tier for diagnosis, and will drop down again as the pattern emerges.

Write down the tier and the reason before starting.

Those of you in IT support will recognise the AI version of the three lines of support, with “third line” often being the guy who has worked in the company for years and years who can actually research answers rather than search the support DBs. I merely evolved this approach into my AI developments.

While this is an efficient methodology, a cheap model only saves money when checking its work is cheap as well. For searching or sweeping, they produce file and line evidence with a flag on unconfirmed. For code editing, I have set up that build and test are done before the diff review and that the mid-tier model spot-checks evidence from work it has delegated. Therefore, one wrong sample means everything is rechecked.

This would work equally well in a team, where you would add a line to your pull requests and take a role in the hierarchy.

I don’t have another coder to work with, well – mostly:

The Post Office.

I have an entire other AI coding platform (Codex) installed. It provides for the next rule: everything gets a handoff Codex review before being pushed to main. The handoff has to review and provide evidence of the results back to the first. These handoffs travel through the “Post Office”, which is essentially an in-and-out shared folder on my NAS drive – in which every file has only one writer. Each handoff gets a folder, and the naming convention is “HANDOFF.md” and “RESPONSE.md” for the author and “REVIEW-codex.md” for the reviewer. If a review finds a lot of things to change or fix, then after the fixes, another review cycle.

This can go around a few times on a real pickle of a problem, but, as they say in the army: slow is smooth and smooth is fast.

The handoff template is designed so the specific branch of code, with a specific commit hash (not HEAD), ensures the review is “pinned” to a snapshot that cannot move beneath it. It includes what changed, why, which files, the “blast radius”, what was verified and what questions there are for the reviewer. The Reviewer can then request changes or approve. Once the change ships, the folder moves from open/ to closed/ with a copy attached to the repo. The pack includes the handoff template and the review steps. The shared folder on a NAS is my own addition.

Each handoff file has only one writer.

Codex handles replies in its own set shape (severity, file and line, problem, reason, fix) with the code quoted. RESPONSE.md notes each fix with its commit and each dismissal with its evidence. Only note secure files (such as API keys) in the handoff, and never print them.

In my first month of doing it like this, I dealt with 100 reviewed handoffs for my products, some with several passes, meaning closer to 500 findings were raised by the reviewer – half rated major.

The final control on all this is a simple rule for coding (and indeed for your life): “don’t believe anything until you have checked”. Each AI politely calls shenanigans on the other, and every pass includes friendly checks of each other’s work. Nothing gets fixed without being checked.

These are alike the rules I set for any real-life team of humans doing AI reviews. The detail in the handoffs helps us find what to check and where; if they cannot establish the detail, the finding is considered unverified. We know people need to be made to do things carefully; our brains are naturally excellent at rolling past procedures, but with AI being so confidently incorrect, we can forget that it’s doing it too.

From here, you turn your rules into a command. So, when a reviewer quotes any code, you can check the quote against the lines it came from. Anything not found by this is thereby marked unverified.

A file and line give you somewhere to start checking.

Here are my logs for one month running this system:

Tally of one month of review handoffs and findings
Having made some very nice keys, what was required were locks.

Good Rule, Weak Locks.

With AI, telling it not to do something is like telling my cat not to do something; she treats the most strident tone as a mere suggestion. Rules are lines of text, signs on unlocked doors saying “don’t open”. Nothing actually prevented pushing data up to the cloud architecture.

So, the other half of this is the Locks.

In Claude, this means creating PreToolUse hooks in the repo. The guard only allows a set list of Git commands and one exact push form, and it refuses things like rm. To push to main, it looks for a passed pre-push record for that exact commit. Anthropic notes that hooks still run in bypass permissions mode, and I provide a smoke test to check this.

The pre-push script runs lint, tests, a production build, and several module-load checks, and lists the results. The agent then recommends an action to me and waits for my command. Human-in-the-loop approvals. The hook then checks all that has passed before allowing the push. Then CI runs after the push and checks what has landed. The production deploy has its own trigger and doesn’t wait for that result, but the local hook can stop a push earlier. Then the system runs a stability check to review the CI, deploy health, and error logs. In the pack, /rl-stability asks the agent to do these checks and runs any steps you configure.

A stop hook itself prompts the agent after a push to main once per turn, and the repeatable workflows (handoffs, stability checks, etc.) are kept in Claude Code skills. Short descriptions help the agent find them, and the full instructions load on use.

The hook checks the agent’s Bash push. CI checks what landed.

Portability

This project setup lives in the repo: CLAUDE.md, .claude/rules/, .claude/skills, and .claude/settings.json. A clone gets those files, so a standard session can still load the project’s hooks; in a cloud session, check that they load before relying on them. My personal, cross-project setup lives in a private repo with an installer. It imports my rules from the user-level CLAUDE.md and loads the shared skills as plugins from a folder marketplace.

Of course, my systems for controlling safety bugs have their own bugs. My initial code review of the safety project went through twenty-one review rounds between Claude and Codex. The guard kept losing to new spellings of dangerous commands until I switched it to an allow-list. The upshot is that there are limits to how good locks can be made to perform, but this approach does enable the guard to only allow Git’s built-in commands and subcommands, with no aliases, and accept only one exact Bash push form.

A hook that reads a shell command stops common mistakes agents want to make, but it won’t stop a determined person or a very high-tier agent acting as one. Nor should it. Current AI design should always be able to be gainsaid by someone at some level.

Testing the AI within your product.

Of course, we are not merely using AI to produce our products; we are using AI within them too. Or at least, I certainly am. So my evaluation harness runs the model and grades the output green, amber, or red with coded checks. For changes impacting “generation”, I run a small audit of a few use cases per impacted group. Each group needs at least half green and no reds. But I also don’t truly believe in simple “green box ticking” approaches. This harness checks that output follows rules, which is a narrow check, but the human should decide what is “good”. My rule for the system is this: X-ray the AI prompt you’re going to build before touching it. Using this, I caught two prompts contradicting each other and resolved a tricky AI configuration. This is much better than “green means go”. So, alongside the harness sits a ledger of methodology claims that records where evidence supports a claim, where it doesn’t, and where claims are mixed or should be excluded from public wording.

I love the built-in browser testing, but I want to monitor this stuff from a second device. Which version is the pass? I can see it immediately on the browser “Evidence Station” running on my iPad. This dashboard runs on the local machine and keeps commits next to results. I can copy summaries for other systems; I do a lot of “deep research” because my primary product is fitness, and I need to ensure the AI in that system is properly checked against fitness rules.

The Station shown using Sidecar.

If this were a team, I would split out the lessons, one per owner and turn the Post Office into the pull request, with the handoff becoming the PR description. This would share any indication of the potential blast radius. Then, CI would be set up to run before merging. This means local checks specific to each human would run in CI, and any changes humans make would be gated the same as the agents. Then it’s a matter of the manager orchestrating the reporting MI with perhaps a rota for reviewing and ageing on findings. They could then evaluate (if you heard my keynote last year in Pune, you’d know I favour evaluators) and report on what rules passed.

My solo setup and what I’d try with a team.

So where to start?

  1. Make every bug a rule. But use a small rulebook.
  2. Decide the tier before the work.
  3. Install a reviewer from a different vendor.
  4. Treat all findings as claims.
  5. Anything that may cause an incident gets a hook.
  6. Allow hooks to enforce one right form.

Using these 6 ideas, you can ship AI-written code with a check before the push, an optional second reviewer, and a record of what was found or missed.

Getting my pack

I have the whole thing packed up to install:

  • A slim CLAUDE.md with path-scoped lessons, plus 16 starter lessons to choose from.
  • Review tiers, a review checklist and a handoff template, with an optional Codex second opinion if you have your own Codex account.
  • Quote checking and regression replay for the findings you accept.
  • The push guard and the exact-commit pre-push record.
  • Evidence Station for browser checks.
  • Removal you can preview before anything is deleted.

The tiers and review steps are instructions the agent follows. The guard, the push record and the stop reminder are the parts that are enforced. You’ll need Node 22 or later, and Git 2.45 or later for the evidence tools. The install is somewhat environment-aware and will install or prompt for most missing things.

If you want to use my system for all this, simply and with an installer, I invite you to look at rulesandlocks.com, where you can get a copy with my support.