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.2.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.2-py3-none-any.whl (65.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polyhook-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f4630e7b329ea7c9e3b574bb90983b4716e4c5b852cf1ef0a5871f377b3f438e
MD5 a1c14a29dd2fe30f82244a334ec31d82
BLAKE2b-256 8da4416a08e7a470900413f3454db795fee5b3d52db37eca1d703c2a7f8be216

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polyhook-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 65.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f05df62a9a160a4ed17e1c3e808efd3b7948ce384ef59c4776ebe4b3ff1e5ae
MD5 63401a49010635045031876196a1fa4a
BLAKE2b-256 b59a309f859788a7b05febd3a8054efbc8b8ca6a824722947c8eadee74cbeadb

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