A free plugin: the first checks in three commands
mainstay is my open set of checks for projects where an AI agent writes the code. The checks read the code itself and fail when a rule is broken. The plugin sets them up in your project through Claude Code. Free.
How to install
In Claude Code, connect the catalogue with the plugin.
/plugin marketplace add Kamtomir/mainstayInstall the plugin.
/plugin install mainstay@mainstayOpen your project and run the setup.
/mainstay:setup
The setup first asks what to install. Only then does it write anything.
What it does
- Asks what you need: the checks, the order they run in, the rules for the agent.
- Writes the first checks for your project. Every API address checks that the person is signed in. Server keys do not get into the code for the browser. Neither does anything that breaks older iPhones.
- Counts how many times type checking is switched off in the code (
as any,@ts-ignore). And sets a rule: fewer is fine, more is not. - Adds a run of the checks on every change, a check before the code is sent, and a rules file,
CLAUDE.md. - Runs all of it and shows what it found.
What it does not do
- It fixes nothing and saves nothing without your yes.
- It does not touch the product code. A red check is a finding for you, not a task for the agent.
- It does not overwrite your files. It compares, shows the difference and asks.
- It adds nothing extra. Installing it installs no packages and adds no hooks or MCP servers to your sessions.
- It does not send code or open a pull request unless you ask.
What a found mistake looks like
The check says three things: which rule is broken, in which file, and what to write instead.
GuardViolation: 1 violation: every API route checks the session
app/api/orders/export/route.ts [require] does not call requireUser(request)
What to do: call requireUser(request) first and return its response when it fails,
or add the route to `allow` with the reason it is public.What it needs
- A project in git with a
package.jsonfile. - Node 20 or newer.
- Vitest. If it is missing, the setup offers to add it.
- Claude Code, to run the plugin.
If you do not use Claude Code
The same setup can be done by hand. These are ordinary files: you copy them, and they are yours. The project is not on npm, on purpose. The README has a step-by-step setup that takes 15 minutes for a TypeScript project. Below is the first check from it. Open the setup.
import { surfaceGuard } from "./surface-guard";
surfaceGuard({
name: "every API route checks the session",
root: "src/app/api",
files: /(^|\/)route\.ts$/,
require: /\brequireUser\(/,
requirement: "call requireUser(request)",
allow: { "health/route.ts": "liveness probe: answers 200 and returns no data" },
});What the whole system is made of
There are six parts. The plugin sets up three: the rule checks with a counter for old debt, the order they run in, and the rules for the agent. The rest are in the open project, ready to take.
Checks for the main rules
Tests that read the code itself and fail when a rule is broken. For example: every page checks that the person is signed in.
In the open project:
guards/A counter for old debt
Old problems are counted file by file. Fewer is fine, more is not. A new problem is visible at once.
In the open project:
guards/ratchet.tsThe order of checks
The fastest and cheapest first, the slow ones after: whether to run at all, the rule checks, the tests and the build, the tests on a real database. A separate watchdog checks that the new version is really live.
In the open project:
ci/Checks for your own AI agent
If the product has its own AI agent, the check is on the program, not on the agent: what the program does with each of its requests. It refuses, shows a person a card to confirm, or allows. Any action that changes something goes through such a card.
In the open project:
evals/Rules for the coding agent
A file the agent reads before every task: look first, do not write straight into the main version, every change has a test. Plus a check before the code is sent and a list for whoever accepts the change.
In the open project:
agent/It broke, so a check appeared
Every mistake that reached people ends with a check in the same change as the fix. That kind of mistake does not come back. Six numbers show whether things got better.
In the open project:
metrics/
Questions about the plugin
Why checks and not lint rules?
Does the plugin download or send anything?
Which frameworks does it know?
A check complains about a file where this is intended. What do I do?
Why is the project not on npm?
Where everything is
- The open project on GitHub — the checks, the plugin and their tests
- README.md — the six parts of the system and the setup by hand
- CASE.md — the numbers of my project and how to check them again
- LICENSE — the MIT license
And the rules of your product?
The plugin sets up the general checks. The rules about your money, your access and your data have to be found first. That is the paid work.
20 minutes on a call. Your code stays on your screen. The button opens Telegram, @K_Damiroff.