Skip to main content

Declarative hook framework for Claude Code

Project description

captain-hook

PyPI Python Docs License: PolyForm Noncommercial

Declarative hook framework for Claude Code. Write hooks as data, test them inline, and ship them to CI in the same shape they run in production.

Install

No install needed — run everything through uvx:

uvx capt-hook init

uvx fetches captain-hook into a throwaway environment and runs it, so you never add it to pyproject.toml. Every command below works the same way: prefix it with uvx.

First hook

Scaffold a project and drop a hook into .claude/hooks/:

uvx capt-hook init
# .claude/hooks/my_first.py
from captain_hook import Allow, Block, Input, block_command

block_command(
    ["git", "stash"],
    reason="Use the team's VCS workflow for shelving changes",
    hint="Commit a WIP change instead of stashing",
    tests={
        Input(command="git stash"): Block(),
        Input(command="git stash pop"): Block(),
        Input(command="git status"): Allow(),
    },
)

Run the inline tests (from your project root, --hooks defaults to .claude/hooks):

capt-hook test

Wire the hook into Claude Code's settings:

capt-hook generate-settings > .claude/settings.local.json

The next time Claude tries git stash, captain-hook returns a deny with your reason and hint.

What problems does this solve?

  • Block dangerous tool calls before they execute (PreToolUse) — force-push, package-manager footguns, raw rm -rf.
  • Drive the agent with feedback that fires on patterns it actually emits — repeated failures, weakened tests, missed conventions.
  • Enforce multi-step workflows with stop-gates and artifact validation, so the agent can't declare "done" without running tests / writing a report / completing a checklist.
  • Keep all of the above testable — every hook ships with inline tests = {...} that capt-hook test runs in CI, so you catch broken hooks the same way you catch broken code.

Docs

Read the docs for the full guide: conditions, primitives, LLM hooks, workflows, state, and real-world patterns.

Working on captain-hook itself? See the development guide.

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

capt_hook-0.3.0.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.

capt_hook-0.3.0-py3-none-any.whl (90.0 kB view details)

Uploaded Python 3

File details

Details for the file capt_hook-0.3.0.tar.gz.

File metadata

  • Download URL: capt_hook-0.3.0.tar.gz
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for capt_hook-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e1de84b21145f940bd40c387f6006cdee2f59a3a5a5aa7223a7565a9d9d391c9
MD5 6a74d319269df51d4c8f9dab90ac0f98
BLAKE2b-256 0be65e67ad94f78c0bc372caf9437926afcf250815d760e5fdeb2938768e2da7

See more details on using hashes here.

Provenance

The following attestation bundles were made for capt_hook-0.3.0.tar.gz:

Publisher: release-pypi.yml on yasyf/captain-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file capt_hook-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: capt_hook-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 90.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for capt_hook-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06fd2ea1ddcf41cbee7c6c01ec295a6ce8c6ef1da1976113c1f39274754972fb
MD5 672d902620abd74bdbe909b21eed8cb6
BLAKE2b-256 437f27149ae0dd78d9e1e38e7667c04d61880f6d12af586a135a36de71a06389

See more details on using hashes here.

Provenance

The following attestation bundles were made for capt_hook-0.3.0-py3-none-any.whl:

Publisher: release-pypi.yml on yasyf/captain-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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