Skip to main content

agent-guard

Guardrails for AI coding agents. agent-guard refuses an agent's shortcuts the moment it tries them: skipped tests, silenced type checkers, TODO instead of code, exit codes hidden behind | tail, and "all tests pass" with no passing run. It also gates completion claims on real checks, and proves behaviour for guarded builds. Its hooks work with Claude Code and Codex, and guarded builds run with Claude Code. It needs no dependencies, and runs on your machines.

CI License: Apache 2.0 Python 3.10+ Dependencies: none Status: alpha Sponsor Website

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.
These rules apply inside repositories only: put probes and scratch scripts in your scratch folder outside the repository.
Do the real work instead. Don't work around this check through another tool or command: that is refused too, and it is logged. If you believe this is a false positive, stop and report the rule and the line to the coordinator.

Why

Coding agents optimise for the check they can see. Under pressure they game the test instead of fixing the code, a failure mode called reward hacking or specification gaming:

  • weakening an assertion, or skipping the failing test;
  • casting to any, or adding @ts-ignore;
  • swallowing the error;
  • writing a check that always returns true;
  • copying the repo to /tmp to test outside the gate;
  • reporting success without having run anything.

Code review catches some of it, late. agent-guard catches it before the edit or command happens, tells the agent what to do instead, and keeps the evidence.

What it does

Layer When it runs What you get
Hooks Before every file edit and shell command, and when the agent stops (Claude Code and Codex hook events) 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; an unbacked claim is refused, then recorded as an unresolved verdict.
Runner scan In CI or your full check, before merge agent-guard scan BASE applies the content rules, and the rules about test, gate and guard files, to the branch diff: additions, edits, deletions and renames. The shell and claim rules run only in the hooks.
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, in a sandbox, the base reproduces the defect, the change passes every behaviour case, and a planted bad implementation is caught. The check is re-run on the exact commit before landing.

What it catches

There are 23 data-driven rules, plus 8 built-in rules; run agent-guard rules for the full list.

Family Rules
Silencing the checker suppress-checker (@ts-ignore, eslint-disable, # type: ignore, # noqa…), type-escape (as any, as unknown as), ts-expect-error, checker-weakened (--ignoreConfig, --passWithNoTests, vitest -u)
Placeholders instead of code placeholder (TODO, "for now", "in production this would…"), placeholder-code (throw new Error('not implemented')), elision (// ... existing code ...), commented-out-code, shortcut-unreferenced
Gaming tests skipped-test (.skip, .only, xit, @pytest.mark.skip), assertion-drop, test-removed, test-lock (builders may not touch tests), test-file-mutation (rewriting committed tests from the shell)
Fake implementations vacuous-guard (verify…() { return true }), vacuous-gate-list (…_CHECKS = []), swallowed-error, test-env-branch (if (NODE_ENV === 'test')), sandbox-probe
Getting around the gate masked-exit (|| true, | tail without pipefail), hook-bypass (--no-verify, core.hooksPath), gate-config (CI, lint, tsconfig and dependency files), guard-tamper, force-push, repo-copy
Claims unbacked-claim ("all tests pass" with no passing test run since the last edit), forbidden-claim ("production-ready")

Design choices that keep the agent from gaming the guard itself:

  • Content rules check only the lines the agent adds, so existing code is never blocked. The test, gate and guard rules also look at what an edit removes, or at which file it touches.
  • No inline overrides. An override written in a comment is just another comment an agent can write. Exceptions live in the operator's policy: an allow entry carries an expiry date, a reason and an approver, and disabled_rules turns a rule off for every path. Neither can turn off guard-tamper.
  • The policy belongs to the operator. The system policy wins over anything in the agent's environment, and the hooks pin it.
  • Evidence is a check the agent ran, not text it printed. A claim needs a matching check whose result shows no failure: for Claude Code, a tool result that isn't flagged is_error and doesn't open with failure text such as Exit code 1; for Codex, tool output that holds none of the failure markers the hook recognises, such as Process exited with code 1. Printed text like rc=0 does not count.

Quick start

git clone --branch v0.3.2 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
echo '{"tool_name":"Bash","cwd":".","tool_input":{"command":"pnpm test || true"}}' | bin/agent-guard hook pre; echo "exit $?"

See it work with your real clients, without changing anything on the machine. Each client runs against a scripted model on loopback; no account and no network are used.

bin/agent-guard prove --disposable enforce

Install as a package (Python 3.10+). On PyPI it is ravenrepo-agent-guard; the command it installs is agent-guard:

pipx install ravenrepo-agent-guard
agent-guard selftest

The agent-guard package on PyPI is a different project. To install from this repository instead, use a release tag: pipx install git+https://github.com/RavenRepo/agent-guard.git@v0.3.2.

Upgrading from 0.3.1 or earlier, whose package was named agent-guard: remove it first, because both packages install the agent-guard command. With pipx, run pipx uninstall agent-guard before pipx install ravenrepo-agent-guard; otherwise pipx leaves the command pointing at the old version. In a shared virtual environment, run pip uninstall agent-guard before installing the new package; uninstalling it afterwards removes the command the two share. Then check that agent-guard version prints the new version.

agent-guard runs inside every agent session, so check what you install: see Verifying what you install.

Set up the hooks

One developer

Claude Code: add to ~/.claude/settings.json.

{
  "hooks": {
    "PreToolUse": [{"matcher": "Edit|Write|MultiEdit|NotebookEdit|Bash",
                    "hooks": [{"type": "command", "command": "agent-guard hook pre", "timeout": 10}]}],
    "Stop": [{"hooks": [{"type": "command", "command": "agent-guard hook stop", "timeout": 10}]}],
    "SubagentStop": [{"hooks": [{"type": "command", "command": "agent-guard hook stop", "timeout": 10}]}]
  }
}

Codex: add the same hooks object, without SubagentStop and with "matcher": "*" for PreToolUse, to ~/.codex/hooks.json. Then trust the hooks in /hooks. Codex skips user hooks until they are reviewed.

A team host or a fleet of agents

This is the recommended setup. It is a root-owned install with system hooks (Claude Code managed settings, and /etc/codex/hooks.json, which Codex trusts by policy). It runs an activation proof with the real clients and rolls back the hook registrations if the proof fails.

sudo bash install/install.sh install --agent-user agent --enforce-paths /srv/work

Start in warn mode, read the event log, then switch to enforce. In warn mode the hooks refuse nothing, but an unbacked success claim found by a block rule is still recorded as an unresolved verdict when the event has a session id, and the user sees a message. See docs/DEPLOY.md.

CI

Add the runner scan to your full check, so a shortcut that slipped past the hooks is caught before merge. The scan diffs against the base branch, so the checkout needs its history (fetch-depth: 0):

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  with:
    fetch-depth: 0
    persist-credentials: false
- run: pipx run --spec ravenrepo-agent-guard==0.3.2 agent-guard scan origin/main

Grow the rules

A rule is data: a pattern, plus examples of the shortcut and of the honest code next to it. To add one:

  1. Write the rule, with both kinds of example.
  2. Run agent-guard rules check pack.json to prove it refuses the faults and allows the clean twins.
  3. Run agent-guard replay to measure it against recorded sessions.
  4. Ship it in warn mode, and promote it to blocking.

See docs/ADDING-RULES.md.

Documentation

Guide Covers
docs/DEPLOY.md Install, activation proof, configuration, rollout from warn to enforce, completion verdicts, undo
docs/ADDING-RULES.md Rule format, self-test, replay, exceptions
docs/CONTRACTS.md Guarded-build contracts, the sandbox, landing checks
CHANGELOG.md Release history

FAQ

Does it send anything anywhere? Not from the hooks or the runner scan: they make no network calls. prove runs the clients against scripted models on loopback. A guarded build launches Claude Code, which talks to whatever model you have configured for it. The event log holds rule ids, paths, line numbers and hashes, and each event's host name, session id, working directory, tool and, for a subagent, agent id, never your code.

How much does it slow the agent down? One short-lived process per tool call: about 120 ms median on a laptop, mostly Python start-up.

What if the guard itself has a bug? It fails open. The action proceeds and the error is logged, so a guard bug never stops every agent. The runner scan is the backstop.

How do I stop an agent from claiming "all tests pass" when they don't? The Stop hook checks the 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 doesn't count. A claim that stays unbacked is recorded as unresolved, so your controller can refuse to mark the work done.

Can it judge code quality? No. It refuses named, mechanical shortcuts, and proves behaviour you specify. Design and readability still need review.

Limits

  • The pattern rules are scanners, not parsers. A determined agent can still hide a change; the runner scan and human review stay.
  • Guarded builds suit bounded tasks (functions, scripts, CLIs). A probe gets no network, 384 MiB, one CPU and 6 seconds.
  • The Stop hook doesn't decide completion. It records verdicts; your controller decides, using the verdict and the runner's own result.
  • Tested on Linux with Claude Code 2.1.332 and Codex 0.168.0.

Author

agent-guard is built and maintained by Amit Kumar (@growthperclick), a founder and AI engineer who builds open tooling around AI coding agents: guardrails, model routing, evals and governance. Also by the author: ladder, which runs recurring LLM work on the cheapest model that still passes a cross-family verifier. More at growthperclick.com.

Sponsor the project

agent-guard is free and open source. Sponsorship pays for the work that keeps it useful:

  • growing and tuning the rule catalogue as new shortcuts turn up;
  • re-testing the hooks against each new release of the supported clients;
  • triaging false positives quickly.

If it keeps your agents honest, please consider sponsoring on GitHub.

Contributing and security

Contributions are welcome. False positives and shortcuts no rule catches help most. See CONTRIBUTING.md. To report a way around the guard, follow SECURITY.md.

License

Apache License 2.0

Metadata

Release files for ravenrepo-agent-guard 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ravenrepo-agent-guard 0.3.2
File Size Uploaded Provenance Actions
ravenrepo_agent_guard-0.3.2.tar.gz 89.3 kB With provenance Details for ravenrepo_agent_guard-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ravenrepo-agent-guard 0.3.2
File Interpreter ABI Platform Actions
ravenrepo_agent_guard-0.3.2-py3-none-any.whl Python 3 none any Details for ravenrepo_agent_guard-0.3.2-py3-none-any.whl

Total release size: 152.8 kB

Release files / ravenrepo_agent_guard-0.3.2.tar.gz

Download URL ravenrepo_agent_guard-0.3.2.tar.gz
Size 89.3 kB
Tags Source
SHA-256 checksum
How to use checksums
314fb4e39c62b16501f1a5b31e686e808e3aa4282f2aa9e33c6b0e231b19e07f
BLAKE2b-256 checksum
How to use checksums
e18ae621a566174a9aec9d99af50116304b3ec14e93a406fdde4fbefa4426cf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / ravenrepo_agent_guard-0.3.2-py3-none-any.whl

Download URL ravenrepo_agent_guard-0.3.2-py3-none-any.whl
Size 63.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8fbfbd50e477e7d762470010805b52b004252c47ce1cd2c332bd612c9630168
BLAKE2b-256 checksum
How to use checksums
d785186f54edb99f711e32c8c6843d46c552bb3c55ebfeb19f5c27f9206cf990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Security for ravenrepo-agent-guard 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ravenrepo_agent_guard-0.3.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page