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
Release files for polyhook 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| polyhook-0.2.0.tar.gz | 71.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| polyhook-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 142.4 kB
Release files / polyhook-0.2.0.tar.gz
| Download URL | polyhook-0.2.0.tar.gz |
|---|---|
| Size | 71.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f178b5b3c0e785d9e5ff47881fc838e65d3b574192c2890d37c16557b123e247
|
|
BLAKE2b-256 checksum How to use checksums |
4160376b0ada4cb3514fd9c6359f6101b8459c9cf9dfa4bbf127be3dbfe7bc4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / polyhook-0.2.0-py3-none-any.whl
| Download URL | polyhook-0.2.0-py3-none-any.whl |
|---|---|
| Size | 70.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0866c80763d46d44d1071cd1cfa139780166b927bfe18d4d77e7ee8a9e0388f6
|
|
BLAKE2b-256 checksum How to use checksums |
3ca9c04f003226c6866a0cf141a28af773dfcc58d6e2547638c16f095ce183e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|