It started with one question to a coding agent: “I’d like to use SonarQube to evaluate the pull requests my agents create. Good idea? Is it fast enough?”

By the end of the evening I had a shared quality gate, one release flow on five repositories, 40 merged pull requests and 7 releases of the gate itself, from v0.1.0 to v0.5.0. This series is about that evening. This first part is about the answer to the question, because it changes how you think about checking an agent’s work.

Fast enough for whom?

SonarQube is a good CI gate: a quality gate on new code, security hotspots, duplication. It’s a poor feedback loop for an agent.

An agent edits a file every few seconds. If the first signal that something is wrong arrives after a push, a CI queue and a full analysis, the agent has already built a dozen more edits on top of the mistake. Then it has to come back, reload the context, fix, push and wait again.

The waiting adds up. Take a task that needs thirty edits. If a third of them contain a mistake, and each mistake surfaces a minute late instead of a second late, the agent spends ten minutes waiting on that task. Then it spends more time unwinding whatever it built on top of each mistake.

So the useful question is: what is the earliest point where this check can run?

Order the checks by speed

The answer became a stack of layers. Each one runs the cheapest checks that make sense at that moment, and the slow ones wait for the end.

Layer When What runs Time
Agent hook after each edit vp check --fix on the edited file < 1 s
pre-commit staged files secretlint + vp check --fix 2–4 s
commit-msg each commit commitlint instant
pre-push before sharing full check, tests, Knip, jscpd ~1–30 s
CI each pull request the same gates + Semgrep, one report comment ~1 min

The agent hook: under a second

This is the layer that saves the most time, and the one most setups skip. My agent runs a hook after every file it writes. In Claude Code it’s a PostToolUse hook on Edit|Write:

cd "$CLAUDE_PROJECT_DIR" || exit 0
if ! output="$(vp check --fix "$file" 2>&1)"; then
  printf 'vp check --fix failed on %s:\n%s\n' "$file" "$output" >&2
  exit 2
fi

It formats and lints only the file that changed, with type-aware Oxlint. It stays silent when the file is clean. On failure it exits with code 2, so the errors go straight back to the agent, which fixes them in the same step, while the code is still in its context. No report to read, no push.

pre-commit and commit-msg: a few seconds

vp staged runs secretlint and vp check --fix on the staged files. A leaked token never reaches a commit. commitlint checks the message against Conventional Commits, and it checked me too: it rejected feat: README and CONTRIBUTING templates for its sentence-case subject. The hook did its job on the person who wrote it.

pre-push: the full check, before anyone else sees it

Before anything leaves the machine, the hook runs the same script CI runs, then dead code (Knip) and duplication (jscpd):

vp run verify
vp exec quality-gate deadcode
vp exec quality-gate duplication

Depending on the project, this takes a second to half a minute. That’s slow enough that you don’t want it on every edit, and fast enough that you never push something you already know is broken.

CI: one comment with every failure

CI runs the same gates again, adds Semgrep, and posts one report comment on the pull request. One detail saves a lot of round trips: the report runs every gate even when one fails, and lists each failure with its output. An agent that reads the comment gets the whole list at once. Without that, it would fix one error, push, wait a minute, and find the next one.

This is also where a SonarQube-style analysis belongs, if you want one: at the end of the chain, where a minute doesn’t matter.

Agents skip hooks

Good hooks don’t replace CI, because agents can bypass hooks. One git commit --no-verify and every local check is gone.

I tested it on purpose in a demo pull request. The hooks blocked a floating promise twice. Then a commit with --no-verify got it through, and CI caught the promise and flagged it in the report comment.

So each layer has a job:

  • Hooks are for speed. They catch most problems in seconds, before they cost anything.
  • CI is for enforcement. It’s the only layer the agent can’t skip.

If you only have CI, every mistake costs a minute or more. If you only have hooks, the agent decides which checks apply to it.

A fresh checkout shouldn’t fail the first commit

One last source of wasted time: agents often work in fresh worktrees. My site passed every check locally and failed in CI. Astro generates its content types, and a fresh checkout doesn’t have them yet, so the type check failed before it even looked at my code.

Two fixes. The shared report got a setup step that runs first and shows up as its own gate (setup: vp run astro sync). And astro sync stays in the project’s prepare script, so a new worktree generates its types on install and its first commit passes. An agent that hits a red check in a fresh worktree will start “fixing” code that works.

Takeaways

  • Ask “how early can this check run?” before “which tool should I use?”
  • Hook the agent’s edits: format and lint the changed file in under a second, and send failures straight back to it.
  • Run the full check before pushing, with the same script CI runs.
  • CI is the enforcement layer, because agents will use --no-verify.
  • Report every failure at once: one comment, not one fix and one push per error.
  • Make fresh checkouts pass: generated files are created on install, not left for CI to discover.

In part 2, I describe the setup behind these layers: one stack and one shared config for five repositories, and how I work with agents on it.

Share this post

← All posts