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

  1. In Claude Code, connect the catalogue with the plugin.

    /plugin marketplace add Kamtomir/mainstay
  2. Install the plugin.

    /plugin install mainstay@mainstay
  3. Open 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.

checks1 failing
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.
Then there are two honest ways: fix the code, or write down why this file is allowed. Weakening the check itself to get green is not one of them.

What it needs

  • A project in git with a package.json file.
  • 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.

  1. 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/

  2. 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.ts

  3. The 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/

  4. 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/

  5. 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/

  6. 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?
Where a linter is enough, use a linter. A check is an ordinary test of about twenty lines, in the same language as your tests. It sees many files at once, SQL and settings. And the exceptions are written next to the rule, each with a reason.
Does the plugin download or send anything?
No. It is one instruction for Claude Code and a copy of the files it installs. The files come from the plugin's own folder; it pulls nothing from the network. It runs inside your Claude Code session, like any task of yours.
Which frameworks does it know?
For the check of API addresses: Next.js, SvelteKit, Express, Fastify and Hono. With others it first describes what it found and asks before it writes.
A check complains about a file where this is intended. What do I do?
Put the file into the exceptions and state the reason. Without a reason the exception is not accepted. And when it is no longer needed, the check says so itself.
Why is the project not on npm?
On purpose. These are files you copy and read in full. No updates from someone else, and no dependence on me.

Where everything is

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.