Guide · Fast feedback

Give your agents instant feedback — before they push

An agent improves only as fast as it learns it's wrong. Put deterministic checks as close to the edit as possible, write failure messages for the agent, and keep the slow checks for later.

Mio Nilsson, creator of AerunitBy · Last updated

A glowing crystal ladder of light rings, cyan at the base rising to purple
The idea

The feedback ladder

If an agent's first signal is a red CI run twenty minutes after the push — or a human review the next day — every mistake costs a full round trip. The same mistake gets cheaper the earlier it's caught. Claude Code's own best practices put it first on the list: "Give Claude a check it can run: tests, a build, a screenshot to compare. It's the difference between a session you watch and one you walk away from." [1]

This isn't new. Continuous integration has always been about fast feedback — Martin Fowler calls a ten-minute build "perfectly within reason" [9] and DORA describes CI as getting feedback within a few minutes. [10] Agents just make the round trip more frequent. Arrange the checks as a ladder:

On every edit — agent hooks

Format and lint the changed file the moment it's written: Cursor's afterFileEdit hook, Claude Code's PostToolUse hook.

When the agent thinks it's done — a stop hook

Run the checks; if they fail, send the agent back to work. Cursor's stop hook can return a followup_message; Claude Code's Stop hook can block the stop.

At commit — a git pre-commit hook

Build, type-check, format check, complexity check. Fail fast and block the commit.

At push / pull request — CI

Full tests with coverage thresholds, workflow linting.

Before merge — the expensive part

End-to-end suites, automated review, then a human.

Both Cursor and Claude Code document these hooks. [3] [2] GitButler's walkthrough is a good tour of how Cursor's hooks fire in practice. [4]

Rules vs gates

Instructions are advice, hooks are guarantees

A rule in AGENTS.md, CLAUDE.md or Cursor rules is something the agent should do. A hook that blocks the commit is something it can't avoid. Claude Code's docs say it plainly:

"Unlike CLAUDE.md instructions which are advisory, hooks are deterministic and guarantee the action happens." [1]

So put "always" rules in hooks. Keep the instructions file for judgment — how you name things, which patterns to prefer — and let code enforce the rest. And say in your agent instructions that --no-verify is never allowed, with CI as the backstop for anything that gets through anyway.

The agent is the reader

Write failure messages for the agent

A failing check should say what to do, not just what's wrong. "Formatting failed" sends the agent hunting; "Run npm run format then stage the changes" gets fixed in one step.

An example from our own repositories: our complexity check uses FTA, the Fast TypeScript Analyzer, with a threshold of 60. FTA's own scale labels scores "OK", "Could be better" and "Needs improvement" — its docs show 64.17 as "Needs improvement". [8] When a file goes over, the check doesn't just fail — it prints a ready-to-run refactor brief naming the worst file:

Complexity check output (shortened)
✖ FTA score 71.4 > 60 in src/billing/invoice.ts

Refactor brief:
1. Plan first: list the responsibilities in this file.
2. Separate routing, business logic and data access.
3. Keep behavior unchanged — no new features.
4. Re-run: npm run complexity
5. Then: npm run format && npm run typecheck

The agent reads that and fixes the problem in the same run. The message is the cheapest prompt you'll ever write, because it arrives exactly when it's needed.

Speed

Keep the commit hook fast

Seconds, not minutes. A slow hook teaches agents — and people — to bypass it. Lint and format only the files being committed: that's exactly what lint-staged is for, running tasks against staged files only. [7] Hook managers like Husky make the hook part of the repository so it installs with the project. [6]

Push everything slow further up the ladder. In CI, cancel runs a newer push has superseded with cancel-in-progress: true [11] and enforce coverage with thresholds — set a line threshold to 90 and the run fails below 90%. [12]

A real gotcha

Make sure the hooks actually run in the agent's environment

Git looks for hooks in .git/hooks by default, but core.hooksPath can point it somewhere else. [5] We hit this the hard way: in our Cursor Cloud Agent environments, core.hooksPath pointed at the agent's own hooks directory, which then chained to .git/hooks. Husky relies on core.hooksPath too — so our pre-commit gate silently stopped running.

Our fix was a small script that writes .git/hooks/pre-commit to chain to the Husky hook, run on install and again every time the environment starts. Cursor now also runs project hooks in cloud agents: "Cloud agents run command-based hooks from your repository" via .cursor/hooks.json. [3]

Whichever route you take, verify it: inside the agent environment, make a commit that should fail, and check that it does.

Put together

Example: a gate-zero setup

Here's the shape we run in every repository. A pre-commit gate of build → type-check → format check → complexity check, failing on the first error with a one-line fix hint. CI then runs lint, tests with coverage thresholds (95% statements, lines and functions) and workflow linting. End-to-end tests run only on pull requests labelled ready to merge.

.cursor/hooks.json
{
  "version": 1,
  "hooks": {
    "afterFileEdit": [{ "command": "./scripts/hooks/format-changed.sh" }],
    "stop": [{ "command": "./scripts/hooks/gate.sh", "loop_limit": 3 }]
  }
}

A stop hook sends the agent back by printing a followup_message, not by failing; loop_limit caps how many times it can do that (Cursor's default is 5). [3]

scripts/hooks/gate.sh
#!/bin/sh
# Cursor stop hook: run the checks; if they fail, send the agent back with the output.
if ! out=$(npm run --silent check 2>&1); then
  msg=$(printf 'Checks failed. Fix these before finishing:\n%s' "$out")
  jq -n --arg msg "$msg" '{followup_message: $msg}'
fi

afterFileEdit receives the edited file's path as JSON on stdin (file_path), so format-changed.sh should read it from there — for example with jq -r .file_path.

.husky/pre-commit
npm run build      || { echo "Build failed. Fix the errors above."; exit 1; }
npm run typecheck  || { echo "Type errors. Fix them before committing."; exit 1; }
npm run format:check || { echo "Run \"npm run format\" then stage the changes."; exit 1; }
npm run complexity # prints a refactor brief when a file scores > 60

Our gate runs a whole-project build and type-check because both are fast in our repositories. If yours take more than a few seconds, move them to the stop hook or CI and keep pre-commit to staged files.

Treat the scripts as a starting point, not a drop-in. The pattern matters more than the tools: the same checks, at every rung, getting slower and more thorough as you climb.

Where we come in

Where Aerunit fits

Fast checks decide how many round trips a pull request takes, and round trips decide how many agents you can keep busy. Aerunit's stories carry the definition of done — including which checks must pass — so the agent knows the bar before it starts. When the agent opens a PR, Aerunit reviews it automatically and can send the findings back to the agent's session: the last automated rung before a human looks.

Team conventions — like "never use --no-verify" or "run the complexity check before committing" — live once in Aerunit's shared context and skills and are fed into every story and run. More on that last rung in our guide to reviewing agent pull requests.

Done, defined

Stories state which checks must pass before the agent starts.

Automatic review

Every agent PR reviewed, findings sent back to the same session.

Shared conventions

Rules like "never use --no-verify" written once and fed into every story and run.

Quick answers

Common questions

Won't pre-commit hooks slow the agent down?

Only if they're slow. Keep the commit hook to seconds: check staged files only, and leave the full test suite for CI. A fast hook saves time, because the agent fixes the problem in the same run instead of waiting for a red CI build and pushing again. [7]

Pre-commit hook or agent hook — which one?

Both, for different jobs. Agent hooks (Cursor's afterFileEdit and stop, Claude Code's PostToolUse and Stop) give feedback during the run. A git pre-commit hook guards the commit for every author, human or agent. CI is the backstop for anything that skips both. [3] [2]

What should never be in a pre-commit hook?

Anything slow, flaky or networked: end-to-end suites, full builds of unrelated packages, calls to external services. Those belong later in the ladder — in CI, or only when a pull request is marked ready to merge.

How do I make the same checks work for people and agents?

Put the checks in the repository, not in any one tool: package scripts, a git hook installed on setup, and CI running the same commands. Then agent hooks and human commits call the same scripts, and nobody has a private version of the rules.

Aerunit

Keep the agents busy. You do the thinking.

Sign-up is open — create an account and start with pay-as-you-go credits. No subscriptions, and teams share one credit pool at no extra cost.

Create account