Skip to main content

canarygate

A hook/gate liveness validator. It replays synthetic benign and canary (poison-pill) events through every hook in your settings.json and tells you which gates are wired-but-dead: the config is legal, the dashboard is green, but the gate never actually fires.

The motivating case, from a real dev.to postmortem by yuhaolin2005: "A gate that has quietly stopped discriminating is worse than no gate, because it still prints a verdict." Their hook returned green on every run — and had not actually executed in weeks.

Install

pip install canarygate

Zero dependencies — stdlib only. Requires Python 3.9+.

Usage

# Full check: static wiring scan + canary probes for every hook
canarygate run --settings ~/.claude/settings.json

# Static wiring analysis only (no hook execution)
canarygate scan --settings settings.json

# Probe a single hook
canarygate probe --settings settings.json --hook 'PreToolUse[Bash]#0'

# Machine-readable report for CI
canarygate run --settings settings.json --format json > gates.json

# Scaffold an example project (one alive gate, one dead gate) to try it on
canarygate init

Exit codes are CI-friendly: 0 = all gates alive, 1 = a gate needs attention, 2 = fatal error (e.g. unreadable config).

How it works

  1. Scan (static). Each (event, matcher, command) triple in the hooks section is checked: does the command resolve (binary on PATH, script file exists)? Is the matcher a valid regex? Plus light script heuristics — a hook script with no blocking branch at all is flagged as suspicious.
  2. Probe (dynamic). canarygate synthesizes two events per hook — a benign one and a canary one carrying a unique CANARYGATE-XXXX marker in its payload — and runs the real hook command with each event JSON on stdin (the Claude Code hook protocol: exit 0 = allow, exit 2 = block).
  3. Verdict. The verdicts are compared:
Status Meaning
ALIVE Benign allowed, canary blocked — the gate discriminates.
WIRED-BUT-DEAD Same verdict on both events; or the matcher never routes to the hook; or the command is missing, crashes, or hangs.
OVERFIRE Blocks the benign event too — a gate that says no to everything gets disabled, which is death by another name.
MISCONFIGURED The entry itself is broken (bad regex, empty command).

Every non-green result ships with the concrete evidence and a fix suggestion.

Example

canarygate liveness report
canary marker: CANARYGATE-9F2A1B3C

HOOK                             STATUS         EVIDENCE
------------------------------------------------------------------------------
PreToolUse[Bash]#0               OK             benign event allowed in 0.07s, canary event blocked in 0.07s
PreToolUse[Bash]#1               DEAD           hook returned 'allow' for both the benign event and the cana
PreToolUse[Bashh]#0              DEAD           matcher 'Bashh' does not match tool_name 'Bash' of the PreTo

2 of 3 gate(s) need attention:
  * PreToolUse[Bash]#1 [WIRED-BUT-DEAD]
      fix: Make the hook inspect its input and block when it sees the
      condition it exists for; then re-run `canarygate probe` until
      the canary is blocked.
  * PreToolUse[Bashh]#0 [WIRED-BUT-DEAD]
      fix: Fix the matcher (or the event registration) so the canary event
      actually routes to this hook.

Differentiation

This sits next to two sibling tools, and they test different things:

  • vs deny-probe (penetration tester for deny rules): deny-probe asks "do my rules stop the attack?" — it finds bypass routes around your policy. canarygate asks "is the wire even connected?" — it finds gates that look healthy but never execute. A perfect deny rule behind a dead hook still protects nothing.
  • vs agent-guard (runtime protection): agent-guard is the shield — hooks that watch the agent live. canarygate audits the shield rack itself: the wiring, the matchers, and whether each hook still discriminates.

CI example

- name: Check hook liveness
  run: |
    pip install canarygate
    canarygate run --settings .claude/settings.json

License

MIT — see LICENSE.

Metadata

Release files for canarygate 0.1.0

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

Source distribution (sdist)

Source distribution for canarygate 0.1.0
File Size Uploaded Provenance
canarygate-0.1.0.tar.gz 18.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for canarygate 0.1.0
File Interpreter ABI Platform
canarygate-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.4 kB

Release files / canarygate-0.1.0.tar.gz

Download URL canarygate-0.1.0.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6554e15c92fcf8f4334d425945491d550330a9a6e207ea775be4b225c38b6f6a
BLAKE2b-256 checksum
How to use checksums
254bcb7d4af92ebc2f47485e018a56327bfc7836c37ad39c4af380b23cd7badf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / canarygate-0.1.0-py3-none-any.whl

Download URL canarygate-0.1.0-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4675e35bd3ef47614ff688de964bcd565680f36b21081c5bb43569d232db04d
BLAKE2b-256 checksum
How to use checksums
94b0ce48215e77b7503276fde313cb36ee58fa1b605d11168c3f175c779a6353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for canarygate 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.1.0 This release

2 release files No 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