Open source · Python · Apache-2.0 · Claude Code and Codex

agent-guard: guardrails for AI coding agents

Coding agents game the check they can see: they skip the failing test, silence the type checker, leave a TODO where the code should be, and report "all tests pass" without a passing run. agent-guard refuses those shortcuts the moment the agent tries them, and tells it what to do instead.

View on GitHub Deployment guide Sponsor
agent-guard refused this action:
- [masked-exit] /work/api 'pnpm -F @acme/api typecheck 2>&1 | tail -3'
  This hides the check's exit code. Use `set -o pipefail;` before piping, and never `|| true` a check.

Three layers, one rule engine

Hooks

Before every file edit and shell command, and when the agent stops, in Claude Code and Codex. Shortcuts are refused with a reason the agent reads; a success claim needs a passing run of the matching check after the last code edit.

Runner scan

agent-guard scan BASE applies the same rules to the branch diff in CI: additions, edits, deletions and renames, so nothing that slipped past the hooks reaches main.

Guarded builds

For tasks you define with a contract, the agent can only read granted files and submit edits. A change is accepted only if every behaviour case passes in a sandbox and a planted bad implementation is caught.

What it catches

ShortcutExamples
Silencing the checker@ts-ignore, eslint-disable, as any, --ignoreConfig, vitest -u
Placeholders instead of codeTODO, "for now", throw new Error('not implemented'), // ... existing code ..., commented-out code
Gaming tests.skip, .only, removed assertions, deleted tests, rewriting committed tests from the shell
Fake implementationschecks that always return true, empty gate lists, swallowed errors, code that behaves differently under test
Getting around the gate|| true, | tail without pipefail, --no-verify, editing CI or lint config, force-push
Claims"all tests pass" with no passing test run since the last edit; "production-ready"

23 data-driven rules plus 8 built-in rules. Every rule ships with examples of the shortcut and of the honest code next to it, and is proven to refuse one and allow the other.

Quick start

git clone https://github.com/RavenRepo/agent-guard.git && cd agent-guard
tests/run.sh                                  # rule self-test plus the test suite
bin/agent-guard rules                         # what it refuses
bin/agent-guard prove --disposable enforce    # see your real clients get blocked, safely

Python 3.10+, no dependencies. Install as a package with pipx install git+https://github.com/RavenRepo/agent-guard.git.

FAQ

How do I stop an AI coding agent from skipping or weakening tests?

agent-guard runs as a hook before every file edit and shell command. It refuses added .skip and .only calls, edits that remove assertions or test cases, and shell commands that rewrite committed tests, and tells the agent to fix the code instead.

How do I stop an agent from claiming "all tests pass" when they don't?

The Stop hook checks the agent's final message against what actually ran. A tests claim needs a passing test run after the last code edit; printed text such as rc=0 does not count. Unbacked claims are refused and, if repeated, recorded as unresolved for your controller.

Does agent-guard work with Claude Code and Codex?

Yes. It uses the PreToolUse and Stop hook events of both clients. A team install registers system hooks and proves activation with the real clients before it reports success.

Does agent-guard send my code anywhere?

No. It makes no network calls. The event log holds rule ids, paths, line numbers and hashes, never your code.

Who built agent-guard?

agent-guard is built and maintained by Amit Kumar (@growthperclick), a founder and AI engineer who builds open tooling that makes AI coding agents trustworthy.

About the author

Amit Kumar spent 16 years in growth and go-to-market before building AI agent systems. He runs Claude Code and Codex agents every day and builds the tooling around them: guardrails, model routing, evals and governance. More at growthperclick.com.

Also by the author: ladder, which runs recurring LLM work on the cheapest model that still passes a cross-family verifier gate.

If agent-guard keeps your agents honest, please consider sponsoring its development.