Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polyhook-0.1.1.tar.gz (66.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polyhook-0.1.1-py3-none-any.whl (65.3 kB view details)

Uploaded Python 3

File details

Details for the file polyhook-0.1.1.tar.gz.

File metadata

  • Download URL: polyhook-0.1.1.tar.gz
  • Upload date:
  • Size: 66.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polyhook-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5df611cbc714d662a4d38a2914f235f155d9471a51e7183e5a8b1da4fe4b2b30
MD5 53dc99be387e0e631a9f9209e0e9dde9
BLAKE2b-256 4cb6fae2bba962ce32172381c905eac483b655a4e8d9eafb93c9d69defbca80d

See more details on using hashes here.

File details

Details for the file polyhook-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: polyhook-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 65.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polyhook-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d26fa8bb4c25c5426f8da1b4ddad04e07bd2870375d81312a6a6e251356b59b
MD5 27b40d9c09ebb00919b04509c7612134
BLAKE2b-256 d88c12c6091c2217cc399eb08982ac5bdbadc7c980c2458a6351834606b99701

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page