gener8v code-quality rules for agents
Coding agents write code faster than people can review it. This repository gives an agent the rules for where code goes, how large it gets, and how to work on a change, and it gives the agent a tool that measures those rules.
- The rules: 18 sections in two parts, each rule with a number, a measure, and the reason.
AGENTS.md: the index of all rules in one file, to copy into a repository.
cq-measure: a command-line tool that measures a repository against the rules. It has no dependencies, and it exits with code 1 on a fail finding so that CI can use it.
- A Claude Code plugin: two skills.
rules applies before the agent writes code, and self-check applies before the agent says "done".
What the rules cover
Part A: Structure. Most of these rules have a measure.
| Section | Examples of measures (warn / fail) |
|---|
| 1. Files | File length (300 / 500 lines), one concept per file, the file name matches the class, one role suffix per role, one case convention per language |
| 2. Directories | Root files (15 / 25), source files per directory (12 / 20), depth (5 / 7), no utils or helpers, paths that start with a domain function |
| 3. Packages | No deep imports, relative climbs (2 / 3), dependencies point inward, no import cycles, fan-out (12 / 20) |
| 4. Functions and classes | Function length (40 / 80), nesting (3 / 4), complexity (10 / 15), parameters (4 / 6), methods per class (15 / 25) |
| 5. Interfaces and abstraction | Interfaces with one implementation, interface size (7 / 12), pass-through layers, inheritance depth (2 / 3) |
| 6. Test placement | Unit tests next to the tested file, test files named for their subject, files with no test |
| 7. Duplication and dead code | Copied blocks, orphan files, unused names, commented-out code |
Part B: Behavior. Most of these rules need judgment: scope of a change, read before you write, names in code, data and types, errors, test discipline, comments, third-party dependencies, security hygiene, performance, and the proof before "done". Five of them have a measure: type escapes, swallowed errors, TODOs without an issue, secrets in code, and debug output.
Use with any agent
Copy AGENTS.md into the root of your repository. Codex, Cursor, Copilot, Gemini CLI, and other agents that read AGENTS.md load it. For Claude Code, add it to CLAUDE.md, or install the plugin.
Measure a repository with no installation (Python 3.10 or later):
uvx --from git+https://github.com/gener8v/gener8v.guidelines.code-quality cq-measure .
Useful options:
| Option | Effect |
|---|
--changed-since origin/main | Measures the whole repository, and reports only findings in the changed files |
--format json | Gives JSON for an agent or a script |
--format sarif | Gives SARIF 2.1.0 for GitHub code scanning and other SARIF readers |
--write-baseline | Records every finding of the repository in .code-quality-baseline.json |
--baseline FILE / --no-baseline | Uses a different baseline file, or reports every finding |
--fail-on warn | Exits with code 1 on a warn finding too |
--only file-lines,import-cycle | Runs only the named checks |
--list-checks | Lists each check with its rule and limits |
Adopt the rules in an existing repository
An existing repository usually has many findings on the first run. To fail only on new findings, record the current ones in a baseline, and commit the file:
cq-measure . --write-baseline
git add .code-quality-baseline.json
When .code-quality-baseline.json exists, cq-measure uses it. A finding in the baseline does not fail. A new finding fails as usual. These changes make a finding new:
- A second copy of a recorded finding in the same file.
- A finding that goes from
warn to fail, for example a file that grows from 341 lines to 520.
- A file that moves to a new path.
A line that moves, or a value that changes inside the same severity, does not make a finding new. When you correct baselined findings, the report says how many are fixed. Run --write-baseline again to record the gain, so that they cannot come back.
GitHub Action
jobs:
code-quality:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- uses: gener8v/gener8v.guidelines.code-quality@main
with:
fail-on: fail
The action measures the repository, writes the report to the job summary, and uploads the findings to GitHub code scanning, so that they show on the lines of a pull request. Private repositories need GitHub Advanced Security for code scanning. Without it, set upload-sarif: "false". Other inputs: path, changed-since (check out with fetch-depth: 0), baseline, and typescript.
TypeScript and JavaScript