Documentation menu

Local and agents

Git hooks, Claude Code and Codex hook recipes, and the MCP server, all calling CodeVeto with a trust anchor captured before the agent starts.

On this page
  1. The absolute interpreter
  2. Trust anchors
  3. Git hooks
  4. Claude Code
  5. Codex
  6. MCP server
  7. Sources

Recipes for running CodeVeto before a commit or push, from a coding agent's hooks (Claude Code, Codex), and as an MCP server the agent can call.

These are conveniences, not enforcement. Every local hook can be skipped: git commit --no-verify and git push --no-verify bypass Git hooks, and an agent with a shell can edit or delete hooks, settings and scripts. The required CI check is the enforcement point. Local hooks only catch problems earlier.

The absolute interpreter

Every recipe calls CodeVeto as <python> -I -m codeveto with the absolute path of the interpreter CodeVeto is installed in: never uv run, a bare codeveto found on PATH, or a path inside the repository, since the change under review could provide any of those. -I (isolated mode) ignores PYTHON* variables, the user site directory and the current directory.

Find the interpreter of an installed codeveto command (pip, pipx and uv tool install all write it on the first line of the script):

shell
sed -n '1s/^#!//p' "$(command -v codeveto)"
# e.g. /home/you/.local/share/uv/tools/codeveto/bin/python

The examples below write it as /absolute/path/to/python.

Trust anchors

Configuration and ignore rules are read from the trust anchor, a commit the change under review cannot have produced (Trust model). Only an anchor passed as a full commit ID resists an agent that can write .git, so every recipe here captures one before the agent starts and passes it on every review:

  • codeveto mcp resolves the anchor once when it starts (which a harness does at session start) and uses it for every tool call.
  • The agent hooks record HEAD at session start in a file outside the repository and pass it as --anchor.
  • The Git hooks need no capture: pre-push anchors at the remote's commit, and pre-commit uses the default resolution (upstream merge base, else origin/HEAD, else HEAD; the output notes which).

Git hooks

shell
codeveto hook install --pre-commit [--repo PATH]
codeveto hook install --pre-push   [--repo PATH]
codeveto hook uninstall --pre-commit   # removes only CodeVeto's own hook

install writes a POSIX sh script (Git for Windows runs it the same way) into the effective hooks directory, core.hooksPath if set, else .git/hooks. It refuses, unless --force, when:

  • that directory is inside the work tree or holds tracked files, so a change under review could rewrite the hook;
  • a hook that CodeVeto did not write is already there (with --force it is kept as <hook>.codeveto-backup, and uninstall puts it back).

core.hooksPath = /dev/null (hooks disabled) or any other path that is not a directory is refused. CodeVeto recognises its own hooks by the line # codeveto-hook: <name> v1; reinstalling replaces them in place.

What the hooks run, with no AI pass (--ai none):

  • pre-commit: review --staged --format agent, the content git commit is about to record. git commit -a and git commit <paths> stage through a temporary index that CodeVeto cannot read as staged content yet, so for those the hook reviews the working tree against the anchor instead (a superset of the commit, including untracked files) and says so.
  • pre-push: reads Git's update records from stdin (validated and bounded: at most 128 KiB and 256 records, well-formed refs and object IDs, nothing reviewed if any record is invalid). For each branch or tag update it runs review --base <remote oid> --head <local oid> --comparison direct --anchor <remote oid>. A new remote branch is compared from its merge base with refs/remotes/<remote>/HEAD; without one (run git remote set-head origin --auto), the push is incomplete and blocked. Deletions and other refs (notes) are skipped. Every update is reviewed; the worst result wins.

Exit codes are the review's: 0 clear, 1 vetoed, 2 incomplete. Git aborts the commit or push on 1 and 2.

Claude Code

Claude Code runs hooks from settings files and blocks on exit code 2, showing the hook's stderr to Claude (hooks reference):

  • SessionStart records the anchor. Its stdin JSON has session_id and source (startup, resume, clear, compact, fork).
  • Stop with exit 2 keeps Claude working instead of ending its turn; the input has stop_hook_active: true when Claude is already continuing because of a Stop hook. Claude Code ends the turn after 8 consecutive Stop-hook continuations (CLAUDE_CODE_STOP_HOOK_BLOCK_CAP).
  • PreToolUse with "matcher": "Bash" and "if": "Bash(git commit *)" runs only before a git commit (each subcommand of a chained command is checked); exit 2 blocks the tool call.

Put the hook configuration in user settings, ~/.claude/settings.json, not in the repository's .claude/settings.json, which the change under review could edit (CodeVeto reports such edits as agent/tool-config-changed).

The hook script

Save this as ~/.config/codeveto/agent-hook.sh (outside every repository), set PY, and chmod 755 it. It serves Claude Code and Codex alike.

shell
#!/bin/sh
# CodeVeto agent hook for Claude Code and Codex. Usage: agent-hook.sh start|stop|commit
#   start   SessionStart: remember HEAD as this session's trust anchor
#   stop    Stop: review everything since the anchor; block the stop on a veto
#   commit  PreToolUse on Bash: the same review before a `git commit` runs
# Keep this file outside every repository an agent works in.

PY=/absolute/path/to/python   # the interpreter CodeVeto is installed in (see above)
STATE="${XDG_STATE_HOME:-$HOME/.local/state}/codeveto/sessions"
mode=$1
dir=${CLAUDE_PROJECT_DIR:-$PWD}

# Read the hook input (bounded) and print: session id, stop_hook_active, and
# whether a Bash command runs `git commit` (Codex has no per-command filter).
info=$(head -c 1048576 | "$PY" -I -c '
import json, re, sys
try:
    data = json.load(sys.stdin)
except ValueError:
    data = {}
data = data if isinstance(data, dict) else {}
sid = data.get("session_id")
ok = isinstance(sid, str) and re.fullmatch(r"[A-Za-z0-9_-]{1,128}", sid)
tool = data.get("tool_input")
cmd = tool.get("command") if isinstance(tool, dict) else None
commit = isinstance(cmd, str) and re.search(r"\bgit\b[^;&|]*\bcommit\b", cmd)
print(sid if ok else "-", "yes" if data.get("stop_hook_active") is True else "no",
      "yes" if commit else "no")
')
set -- $info
sid=${1:--} active=${2:-no} commit=${3:-no}

if [ "$mode" = start ]; then
  [ "$sid" = - ] && exit 0
  oid=$(git -C "$dir" rev-parse --verify --quiet 'HEAD^{commit}') || exit 0
  umask 077
  mkdir -p "$STATE" || exit 0
  # The first anchor of a session wins: resuming or compacting must not move it.
  [ -e "$STATE/$sid" ] || printf '%s\n' "$oid" > "$STATE/$sid"
  exit 0
fi

[ "$mode" = commit ] && [ "$commit" != yes ] && exit 0
anchor=
[ "$sid" != - ] && [ -f "$STATE/$sid" ] && anchor=$(head -c 64 "$STATE/$sid")
case $anchor in *[!0-9a-f]*) anchor= ;; esac
if [ -n "$anchor" ]; then set -- --anchor "$anchor"; else set --; fi

out=$("$PY" -I -m codeveto review --repo "$dir" --format agent "$@" 2>&1)
code=$?
if [ "$code" -eq 0 ] || { [ "$mode" = stop ] && [ "$active" = yes ]; }; then
  # Clear, or this stop was already blocked once: let the agent stop (CI enforces).
  [ "$mode" = stop ] && printf '{}\n'
  exit 0
fi
printf 'CodeVeto blocked this (exit %s). Fix every finding, then continue:\n%s\n' \
  "$code" "$out" >&2
exit 2

Notes:

  • The review is worktree mode: everything since the anchor, committed or not, including untracked files. Worktree mode is POSIX-only in 0.1; on Windows it ends incomplete, so the hook blocks every time (use the Git pre-commit hook there instead).
  • A Stop is blocked once per stop: when stop_hook_active is true the hook lets the agent stop even if the review still fails, so a finding the agent cannot fix does not loop. Delete the active condition to block until the review is clear.
  • Without a recorded anchor (the session started before the hook was set up, or the repository had no commits), the review falls back to the default anchor resolution, which an agent can influence; the report says so.
  • git rev-parse at session start runs before the agent has changed anything.

Settings

~/.claude/settings.json:

json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          { "type": "command", "command": "$HOME/.config/codeveto/agent-hook.sh start" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "if": "Bash(git commit *)",
            "command": "$HOME/.config/codeveto/agent-hook.sh commit",
            "timeout": 300
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.config/codeveto/agent-hook.sh stop",
            "timeout": 300
          }
        ]
      }
    ]
  }
}

timeout is in seconds. Leaving out a matcher on SessionStart runs the hook for every source; the script keeps the first anchor of a session, so a resumed or compacted session keeps the anchor it started with.

Codex

Codex reads the same hook layout from ~/.codex/hooks.json (or inline [[hooks.<Event>]] tables in ~/.codex/config.toml); hooks are on by default (Codex hooks). Command hooks receive one JSON object on stdin with session_id, cwd, hook_event_name, tool_input.command for shell commands (matched as Bash) and stop_hook_active for Stop. Exit 2 with the reason on stderr blocks a PreToolUse call or makes a Stop continue; Stop ignores matcher and expects JSON on stdout when it exits 0 (the script prints {}). Commands run in the session's working directory. Codex runs a new or changed non-managed hook only after you review and trust it with /hooks.

Codex has no per-command if filter, so the script itself skips Bash commands that do not run git commit. ~/.codex/hooks.json:

json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          { "type": "command", "command": "$HOME/.config/codeveto/agent-hook.sh start" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.config/codeveto/agent-hook.sh commit",
            "timeout": 300,
            "statusMessage": "CodeVeto review before commit"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.config/codeveto/agent-hook.sh stop",
            "timeout": 300,
            "statusMessage": "CodeVeto review"
          }
        ]
      }
    ]
  }
}

Keep it in ~/.codex/, not a repository's .codex/, for the same reason as Claude Code's user settings.

MCP server

codeveto mcp --repo PATH [--anchor OID] [revision flags] is a stdio MCP server with no dependencies. The repository, the revision flags (worktree mode by default; --staged, --base REF [--head REF] [--comparison ...] or --commit REF) and the trust anchor are fixed when it starts: --base and --commit are resolved to commit IDs, --head keeps following the name it was given, and the anchor is resolved once to a full commit ID (or taken from --anchor) and reported on stderr. No tool argument can change the repository, revisions, anchor, configuration, models or endpoints.

Tools:

Tool Arguments Result
review none --format agent lines (path:line rule severity message, then verdict ... exit N), with the JSON report as structured content
get_ai_packets none harness AI step 1: packets, instructions and answer schema (harness mode)
submit_ai_review responses (the responses document, at most 2 MiB) harness AI step 2: the verified review

A vetoed or incomplete review is a normal result; read the verdict line. The server speaks MCP 2026-07-28 (per-request _meta, server/discover) and the handshake revisions 2025-11-25, 2025-06-18, 2025-03-26 and 2024-11-05 (MCP versioning, stdio transport). Messages are capped at 4 MiB, JSON is parsed strictly, and stdout carries only protocol messages.

Use the absolute interpreter and an absolute --repo. Register the server in your own configuration, not in a file inside the repository (such as a project .mcp.json), which the change under review could edit.

Claude Code (MCP); the default local scope is stored in ~/.claude.json for this project only:

shell
claude mcp add --transport stdio codeveto -- \
  /absolute/path/to/python -I -m codeveto mcp --repo /absolute/path/to/repo

Codex (MCP):

shell
codex mcp add codeveto -- \
  /absolute/path/to/python -I -m codeveto mcp --repo /absolute/path/to/repo

or in ~/.codex/config.toml, with a longer tool timeout than the default 60 seconds:

toml
[mcp_servers.codeveto]
command = "/absolute/path/to/python"
args = ["-I", "-m", "codeveto", "mcp", "--repo", "/absolute/path/to/repo"]
tool_timeout_sec = 300

Both harnesses start the server at session start, so its anchor is captured before the agent changes anything. To pin the anchor across restarts, add --anchor <full commit ID>.

Sources

Checked on 2026-11-28: