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.8.tar.gz (67.2 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.8-py3-none-any.whl (66.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polyhook-0.1.8.tar.gz
  • Upload date:
  • Size: 67.2 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.8.tar.gz
Algorithm Hash digest
SHA256 a5a49c194ada4b09b7f30d2174d062cb789e26c6009f716ae8e32cd07650f212
MD5 779796c88da1724f1db7b6f779aed98d
BLAKE2b-256 e8539fa95fdd57e2227341dfd384c9c4fcb3ee7e5b4469103ce2f860b5027f33

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polyhook-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 66.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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 53d278c2b77200198198d463e569d11dfc62d869bfd9b6012471fe8b3b56c95e
MD5 a28b4ad5abf2bc60d8acec044e9af803
BLAKE2b-256 42d24408ead89b487af191773ef96ebde87d866f3fef73ae6bce9cadc0d359f0

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