Skip to main content

polyhook — Python SDK

Write AI coding agent hooks once. Run them everywhere.

polyhook detects which AI coding tool invoked your hook binary, deserializes the event into a normalized struct, and serializes your response back in the format that tool expects. Your hook runs unchanged whether Claude Code, Cursor, Windsurf, Cline, Amp, or Pi invoked it.

Install

pip install polyhook

Quick Start

import sys
import re
import polyhook

event = polyhook.read()

if (
    event.tool == "bash"
    and re.search(r"rm\s+-rf\s+/", event.input.get("command", "") if event.input else "")
):
    polyhook.respond(polyhook.block("Refusing to delete from root"))
else:
    polyhook.respond(polyhook.approve())

More examples: examples/

Supported Tools

Tool Status
Claude Code ✅ Supported
Cursor ✅ Supported
Windsurf ✅ Supported
Cline ✅ Supported
Amp ✅ Supported
Gemini CLI ✅ Supported
Hermes Agent ✅ Supported
Pi ✅ Supported
Continue 🚧 In progress
Aider 🚧 In progress
Copilot 📋 Planned

Pi uses the Claude Code-compatible hook payload format; set if you want it labeled explicitly.

Documentation

Full docs and API reference: https://github.com/tupe12334/polyhook

License

MIT

Metadata

Release files for polyhook 0.2.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 polyhook 0.2.1
File Size Uploaded Provenance Actions
polyhook-0.2.1.tar.gz 76.2 kB Without provenance Details for polyhook-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 152.0 kB

Release files / polyhook-0.2.1.tar.gz

Download URL polyhook-0.2.1.tar.gz
Size 76.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2ff929c9698c161455d89b931e5b5b1d43f3d6b9afc458f63c843235e7f3c663
BLAKE2b-256 checksum
How to use checksums
5d00b75490b8dbc22e7e2953f8756fec83baafb80b1879585d2f8ab9fafd28b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / polyhook-0.2.1-py3-none-any.whl

Download URL polyhook-0.2.1-py3-none-any.whl
Size 75.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbb0cba01d749ad0a5213f152f5b38f7fc458d32fb158115a72a859f9a819ee8
BLAKE2b-256 checksum
How to use checksums
e65fc0d29ee41994640e387c0d5ae7fc8661f40003559479c1d1120e53ca622c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for polyhook 0.2.1

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.

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