polyhook Python SDK — write AI coding agent hooks once, run them everywhere
Project description
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, or Amp 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 |
| Continue | 🚧 In progress |
| Aider | 🚧 In progress |
| Copilot | 📋 Planned |
Documentation
Full docs and API reference: https://github.com/tupe12334/polyhook
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polyhook-0.1.6.tar.gz.
File metadata
- Download URL: polyhook-0.1.6.tar.gz
- Upload date:
- Size: 66.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3ea7c888930241f3c9c7e84aaebdfc21350b7c5fbf2bb84a3330982bba659a4
|
|
| MD5 |
0e97c2b5ed9835ec4db2fad8e025f12c
|
|
| BLAKE2b-256 |
e1e252b6f2b8d541be2cd55b9c8761c9ef72b8fbb6c8bf29b7e23ad1b0dc8506
|
File details
Details for the file polyhook-0.1.6-py3-none-any.whl.
File metadata
- Download URL: polyhook-0.1.6-py3-none-any.whl
- Upload date:
- Size: 65.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e74fb14b41dcedea321e46126157564a37c44e9a01322caacb13144b3df8e9b7
|
|
| MD5 |
c85b7a48b572e05cdd934b240e89b8f5
|
|
| BLAKE2b-256 |
7fca29545a8654a0713dc7325b9befa4cdcd9cbeedd0c180ee326250fae735c0
|