Skip to main content

orchestkit-hook-contract

Pydantic v2 + JSON Schema contract for Claude Code hook events. Python sibling of the npm package @orchestkit/hook-contract. Both packages regenerate from the single source of truth at spec/hook-events.spec.yml in the repo root.

Status

  • M141-3: scaffold — Pydantic models, JSON schemas, structural validator, hand-rolled codegen from spec.
  • M141-4 (this change): HMAC signing protocol + reference verifier. Spec at ../hook-contract/docs/signing-rfc.md. Shared golden vectors at ../hook-contract/test-vectors/signing/.
  • M141-6: cross-language parity gate CI — diff this output against the npm side field-by-field.

Install

pip install orchestkit-hook-contract

Requires Python 3.11+ and pydantic>=2.5.

Usage

from orchestkit_hook_contract import (
    HookEvent,
    HOOK_EVENT_NAMES,
    PreToolUsePayload,
    validate_hook_event,
)

# Structural validation
result = validate_hook_event({"event": "PreToolUse"})
if result.valid:
    print("known event:", result.event)

# Typed payload access
p = PreToolUsePayload(tool_name="Bash", tool_input={"cmd": "ls"})
assert p.tool_name == "Bash"

# Pydantic envelope
e = HookEvent(event="PreToolUse", payload={"tool_name": "Bash", "tool_input": {}})

HMAC signing (M141-4)

Sign hook deliveries on the sender and verify on the receiver. Full spec: ../hook-contract/docs/signing-rfc.md.

from orchestkit_hook_contract import sign, verify, HOOK_SIGNATURE_HEADER

# Sender
import json, requests, os
body = json.dumps(event).encode("utf-8")
header = sign(body, os.environ["HOOK_SECRET"])
requests.post(url, headers={HOOK_SIGNATURE_HEADER: header, "Content-Type": "application/json"}, data=body)

# Receiver (Flask / FastAPI / etc. — capture raw body, NOT json.dumps(req.json))
result = verify(
    request.headers.get(HOOK_SIGNATURE_HEADER),
    request.get_data(),  # raw bytes
    os.environ["HOOK_SECRET"],
    tolerance_sec=300,
)
if not result.valid:
    abort(401, result.reason)  # "missing_header" | "malformed_header" | "stale" | "signature_mismatch"

Mirrors the npm sibling byte-for-byte against the same 13 golden vectors. Zero deps beyond hmac + hashlib from the stdlib.

Coverage

13 of the 19 hook events have typed payload classes (PreToolUsePayload, NotificationPayload, etc.). The remaining 6 events stay envelope-only — their CC payloads aren't documented enough to lock down: SessionEnd, Setup, InstructionsLoaded, WorktreeCreate, WorktreeRemove, ConfigChange.

Develop

cd packages/hook-contract-py
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest -v
python scripts/codegen-py.py --check   # drift gate
python scripts/codegen-py.py           # regenerate from spec
mypy src/
ruff check src/ tests/

Why this package exists

The hook event surface is the contract between OrchestKit's TypeScript hook fan-out and any Python receiver (yonatan-hq/platform, custom analytics consumers). When the contracts drift, fields go missing in transit and observability lies. This package + the npm sibling both regenerate from one spec, eliminating that drift class.

Metadata

Release files for orchestkit-hook-contract 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for orchestkit-hook-contract 0.1.2
File Size Uploaded Provenance Actions
orchestkit_hook_contract-0.1.2.tar.gz 18.1 kB With provenance Details for orchestkit_hook_contract-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for orchestkit-hook-contract 0.1.2
File Interpreter ABI Platform Actions
orchestkit_hook_contract-0.1.2-py3-none-any.whl Python 3 none any Details for orchestkit_hook_contract-0.1.2-py3-none-any.whl

Total release size: 31.2 kB

Release files / orchestkit_hook_contract-0.1.2.tar.gz

Download URL orchestkit_hook_contract-0.1.2.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
556e504394e76488ede7b49928ea14d10325119009238e29bf532e600622e04d
BLAKE2b-256 checksum
How to use checksums
c26f38025296e94be67bf4b726e191a4a5cd98ec73ec92f740da275bce453e87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 22, 2026.

Transparency log

Release files / orchestkit_hook_contract-0.1.2-py3-none-any.whl

Download URL orchestkit_hook_contract-0.1.2-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f20ff4bbc88642c8415df5964077793e993aa97e020b679852d25000cb175994
BLAKE2b-256 checksum
How to use checksums
54ba48b5c2f21a7f7666ce93253a2c843fe04f0d012aeb090e4c40cb15dffe41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 22, 2026.

Transparency log

Security for orchestkit-hook-contract 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for orchestkit_hook_contract-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page