Coding agents
Coding agents leave the same marks on every codebase they touch: a second copy of code that already exists, arithmetic that does nothing, and tests that cannot fail. Ur’s check can run at the end of each of an agent’s turns and send it back to work until the check is clean.
Setting a project up
From the project’s root:
ur init
ur init adds ur check --hook <agent> --fix as the stop hook in the project’s settings for each
coding agent with stop hooks, creating the settings file where there is none and leaving a hook that
already runs ur check alone:
| Agent | Settings | Event |
|---|---|---|
| Claude Code | .claude/settings.json |
Stop |
| Codex | .codex/hooks.json |
Stop |
| Gemini CLI | .gemini/settings.json |
AfterAgent |
| Factory Droid | .factory/hooks.json |
Stop |
| GitHub Copilot’s CLI | .github/hooks/ur.json |
agentStop |
Cursor runs Claude Code’s hooks, so Claude Code’s settings cover it too. ur init writes no
ur.toml: a project without one is configured by its ecosystem’s files, as its current tools are.
Commit the settings files, so every agent working on the project runs the check.
What the hook does
When the agent ends its turn, the hook runs ur check --fix over the project: it writes the fixes
of the findings that have one and checks the files changed since the last clean check. A clean check
lets the agent stop. Otherwise the hook blocks the stop and hands the agent Ur’s report as the
reason, so the agent reads the findings and fixes them.
An agent that cannot fix what the check finds would never stop, so when the agent is already continuing because of the hook, the same findings a second time let it stop.
The rules’ instructions
Each rule gives an instruction for an agent to follow while it writes code, so the agent avoids the
mistake rather than fixing it after the check. ur lint --rules prints them, and they can go in a
project’s AGENTS.md or CLAUDE.md.
These are the instructions of the rules on by default; an optional rule's page gives its own.
- Never write shared state after an `await` from a value read before it; read it again after the `await`. (`await-race`)
- List in `attr_accessible` only attributes any user may set, never privileges or foreign keys. (`dangerous-accessible-attribute`)
- Guard every access to a variable that threads share with one mutex, or make the variable atomic. (`data-race`)
- Take locks in one fixed order everywhere, and never take a lock the same thread already holds. (`deadlock`)
- Write no test that the tests before it on every path already decide, such as `n > 3` inside `if n > 5`. (`decided-condition`)
- Draw a route for each action; never route `:action` or `:controller` from the path. (`default-routes`)
- Before writing out a set of literal values or a particular constant, look for a definition that already holds them and refer to it instead. (`duplicated-data`)
- Never add an editor's swap or backup file, an operating system's folder metadata, a compiled or cached file, or a crash log to the project; delete it, and ignore its pattern in .gitignore. (`junk-file`)
- Never add to or remove from a collection inside a loop that walks it; walk a copy or build a new collection. (`mutated-while-iterating`)
- Write `x not in xs` and `x is not y`, never `not x in xs` or `not x is y`. (`negated-operator`)
- Write `enclosing(n, Kind)` for the nearest ancestor of a kind, not a list match over `ancestors(n)`. (`rsc-ancestor-walk`)
- Write `/Kind x := t` for the parts of a node of one kind, not `x <- descendants(t), x is Kind`, wherever `t` itself cannot be a `Kind`. (`rsc-descendant-filter`)
- Do not declare `data Language`, `data Check`, `data Change`, `data Insert`, `data Commented`, `data Field`, `data Rewrite`, `data Classify`, or `data Rank`, nor `param` the host's name and type functions such as `definition(Tree n)`: Ur declares them. (`rsc-implied-declaration`)
- Write `xs[-1]` for the last item of a list, never `xs[size(xs) - 1]`. (`rsc-last-item`)
- Compare a node with a string literal, or a set of them, directly: write `x == "pub"`, not `unparse(x) == "pub"`. (`rsc-spelled-comparison`)
- Before writing a function, look for one that already computes the same result and call it instead of writing another. (`semantic-clone`)
- In a signal handler, only set a `volatile sig_atomic_t` flag and call only async-signal-safe functions. (`signal-handler`)
- Read and write environment variables only in the project's env file, such as src/env.rs or env.py, and pass the values on from there. (`stray-env-var`)
- Never check a file by its path before using it; use it and handle the error, or work through one open handle. (`toctou`)
- Write no operation or conditional whose result is a constant or one of its own operands, such as `x * 1` or `a if c else a`. (`trivial-expression`)
- Anchor a format validation's pattern with `\A` and `\z`, never `^` and `$`. (`unanchored-format-validation`)
- Write each `.rsc` module so that it parses and every module it imports is there. (`urscal-error`)
- Generate RSA keys of at least 2048 bits, and encrypt with RSA only with OAEP padding. (`weak-rsa`)
- State the value a test expects as a literal rather than computing it, so the test cannot share the code's mistake. (`circular-expectation`)
- Give each test files of its own under the framework's temporary directory; never read or write a fixed absolute path. (`fixed-path`)
- Compare floating-point values within a tolerance, with the framework's approximate assertion, never for exact equality. (`float-equality`)
- Never replace a library function by assigning to it in a test; pass the replacement to the code under test, or use the framework's patching, which restores it. (`global-stub`)
- Write a test as straight-line code: no loop that asserts and no conditional around an assertion. Write each case out or parametrize the test, and compare whole collections with one assertion. (`logic-in-test`)
- Give every test an assertion on the result of the code it calls; a test that only calls code can fail only by crashing. (`missing-assertion`)
- Make at most two test doubles in a test and stub at most two methods of each; past that, use the real collaborator or a fake. (`mock-count`)
- Never make a test double return another test double; use a real object or a fake for the one in the middle. (`mock-returns-mock`)
- Write the values a test checks in the test itself, so it can be verified by reading it. (`opaque-test`)
- Keep a test inside its own process: replace a server or a program it would reach with a fake or an in-memory implementation. (`outside-process`)
- When verifying a call on a test double, state only the arguments the behavior under test depends on and let the rest vary with the framework's argument matchers. (`over-specified-verify`)
- End a test after checking the outcome of the call it is about; put each later call and its checks in a test of its own, with the setup they share in a helper. (`overloaded-test`)
- Never read the current time in a test; give the code under test a fixed time, as a parameter or through a fake clock. (`real-clock`)
- Store the result of the code under test in a variable, and use that variable in both the assertion and its message. (`recomputed-in-message`)
- Give each parameter of a call under test a different value, so a test fails when the code swaps or confuses them. (`repeated-argument`)
- Never sleep in a test; wait for the condition the test is waiting for, with an event, a latch, or the framework's synchronization, or advance a fake clock. (`sleep-in-test`)
- Never catch every exception around a test's assertions; catch only the exception the test expects, and assert outside the handler. (`swallowed-failure`)
- Compare the result of the code under test with a value stated independently of it, never with the same expression. (`tautological-assertion`)
- Pass the code under test values other than its types' defaults, such as 7 or "apple" rather than 0 or "", so a test fails when the code ignores its input. (`trivial-inputs`)
- Pass the two values to an assertion that compares them, such as assert_eq! or assertEquals, rather than asserting that a comparison holds. (`uninformative-assertion`)
- Make every assertion able to fail: compare the result of the code under test with a value stated separately, and call the matcher or assertion method rather than only naming it. (`vacuous-assertion`)
- Give every blocking wait in a test a timeout, and fail the test when it runs out. (`wait-without-timeout`)
- Before citing a lemma in a Lean proof, check that the lemma is proved, and prove it first if it is not. (`rests-on-unproved`)
- Prove every Lean theorem: leave no `sorry` or `admit`, declare no `axiom`, and prove decidable goals with `decide` rather than `native_decide`. (`unchecked-proof`)
- Give each construct condition tags that, with those around it, hold for some release, dialect, or set of features. (`grammar-dead-condition`)
- Tag a construct with a condition only where it narrows what the constructs around it already allow. (`grammar-redundant-condition`)
- In an ordered choice, put no alternative after an earlier one that matches wherever it would. (`grammar-shadowed-alternative`)
- Define a sort only when a start rule reaches it, directly or through other sorts. (`grammar-unreachable-sort`)