Skip to main content

hapax-agentgov

Governance hooks for AI coding agents. Extracted from a production system running 47 hooks across 200+ agents.

Works with Claude Code hooks. Enforces safety, git hygiene, and project rules automatically — before the agent acts, not after.

Quick start

pip install hapax-agentgov
cd your-project
agentgov init

This scaffolds .claude/hooks/ with safety hooks and registers them in .claude/settings.local.json.

What it does

Hooks intercept Claude Code tool calls (file edits, bash commands) and block dangerous actions before they execute:

Hook Category What it blocks
pii-guard safety Email addresses, SSNs, phone numbers, home directory paths in tracked files
secrets-guard safety AWS keys, GitHub tokens, API keys, private keys
conflict-marker-scan safety Warns when <<<<<<< markers appear after git merge/rebase
safe-stash-guard git git stash pop (use apply + drop instead — pop can't recover from conflicts)
push-gate git Autonomous git push, gh pr create/merge without user approval
no-stale-branches git Creating new branches when unmerged work exists
work-resolution-gate workflow Editing code on branches with no open PR
pkg-manager-guard tooling Direct pip install (enforces uv or poetry)
protected-paths workflow Writes to *.pem, *.key, and other sensitive file patterns

CLI

agentgov init

Scaffold hooks into your project.

agentgov init                    # "safe" preset (recommended 6 hooks)
agentgov init --preset strict    # all 9 hooks
agentgov init --preset minimal   # just pii-guard + conflict-marker-scan
agentgov init --force            # overwrite existing hook scripts

agentgov check

Validate your hook configuration.

agentgov check
# agentgov: 6 hooks configured and valid
#   OK  pii-guard.sh (PreToolUse)
#   OK  secrets-guard.sh (PreToolUse)
#   ...

agentgov report

Show governance coverage.

agentgov report
# agentgov: 6/9 hooks active (67% coverage)
#
# Active:
#   [safety] pii-guard: Block writes that introduce PII patterns
#   [safety] secrets-guard: Block writes containing API keys and tokens
#   ...

agentgov report --json    # machine-readable output

Enterprise adoption

Start with an advisory pilot before enforcement in production. In this release, installed hooks enforce their checks; advisory means using a sandbox, fork, or low-risk repository to inspect findings before promotion. The enterprise guide covers a safe pilot shape, license and attribution expectations, security readiness checks, and the boundary between free adoption and paid support:

How hooks work

Claude Code hooks are shell scripts that run before (PreToolUse) or after (PostToolUse) tool calls. They receive the tool name and input as JSON on stdin:

{
  "tool_name": "Edit",
  "tool_input": {
    "file_path": "/path/to/file.py",
    "new_string": "API_KEY = 'sk-abc123...'"
  }
}

A hook exits 0 to allow, exits 2 to block (with a message on stderr).

Writing custom hooks

Drop any .sh script in .claude/hooks/ and register it in .claude/settings.local.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": ".claude/hooks/my-hook.sh" }]
      }
    ]
  }
}

Origin

Extracted from hapax-council, a personal operating environment running 200+ AI agents with 47 governance hooks enforcing safety, privacy, git discipline, and project rules across all agent sessions.

License

MIT

Metadata

Release files for hapax-agentgov 0.3.1

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

Source distribution (sdist)

Source distribution for hapax-agentgov 0.3.1
File Size Uploaded
hapax_agentgov-0.3.1.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hapax-agentgov 0.3.1
File Interpreter ABI Platform
hapax_agentgov-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 41.7 kB

Release files / hapax_agentgov-0.3.1.tar.gz

Download URL hapax_agentgov-0.3.1.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
63316a6025ef9af6a39822fc9ccc2530bbe1493c5d86c84ac7c40fc6ecfd3cec
BLAKE2b-256 checksum
How to use checksums
423244eefabd34c82e4311a4614abfc7367208b80a6843d4cd931b290ac85eb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / hapax_agentgov-0.3.1-py3-none-any.whl

Download URL hapax_agentgov-0.3.1-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3aee46ddcac4da61181246f787eda315c29ed94085493cd1880dda26028f248a
BLAKE2b-256 checksum
How to use checksums
795c485e95c3a8902186ee1b8d641e6ea508a1f07178d9c7d13a10c0b80c4601
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

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