Skip to content

Install and deploy

Install

From PyPI, where the package is named agent-gate-hook (the command is still agent-gate):

pipx install 'agent-gate-hook[model]'

The model extra adds the Anthropic SDK, which only the anthropic backend of the model gate needs; leave it off to use the rules alone or a local model.

From a clone, for development:

git clone https://github.com/Flux-Frontiers/agent_gate.git
cd agent_gate
poetry install --with dev --all-extras

--all-extras adds the Anthropic SDK, as above.

To contribute, install the pre-commit hooks. They run ruff, ty, detect-secrets and the tests with the coverage floor, the same checks CI runs:

.venv/bin/pre-commit install

Try a payload

agent-gate check judges one payload and prints the verdict without recording it in the ledger:

echo '{"tool_name":"Bash","tool_input":{"command":"git push"},"cwd":".","session_id":"t"}' \
  | .venv/bin/agent-gate check

Without a mandate, every consequential call asks a person, so this push answers ask.

Deploy as a Claude Code hook

Add this to a project's .claude/settings.json, or to ~/.claude/settings.json for every project. Use the absolute path of the installed command.

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "/abs/path/to/agent_gate/.venv/bin/agent-gate hook",
            "timeout": 30,
            "onFailure": "block"
          }
        ]
      }
    ]
  }
}
  • onFailure: "block" makes a hook timeout block the call. Without it a timed-out PreToolUse hook lets the call through.
  • The hook's timeout must exceed the model gate's timeout_seconds, or Claude Code cancels the hook before the gate can fall back to asking. The values above suit a fast model. A model as slow as Qwen3.8-27B needs both raised.
  • The gate itself always exits 0 and writes its decision as JSON. Any other non-zero exit would let the call through, which is why errors become a deny inside the gate rather than a crash.
  • When several PreToolUse hooks answer, Claude Code applies deny over defer over ask over allow, so another hook's allow cannot override this gate's deny.

Then write a mandate for the project.