Declarative hook framework for Claude Code
Project description
captain-hook
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, rawrm -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 = {...}thatcapt-hook testruns 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file capt_hook-0.2.0.tar.gz.
File metadata
- Download URL: capt_hook-0.2.0.tar.gz
- Upload date:
- Size: 66.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ef08b68930a8276d51a391338283a3b0e8203be555baa70406938acfac19958
|
|
| MD5 |
48d0c142c9a1ac37172aac5502213652
|
|
| BLAKE2b-256 |
7e798870fd832c19e29f63a12ee19849f00eae9dee389fdc6659580b5020d21b
|
Provenance
The following attestation bundles were made for capt_hook-0.2.0.tar.gz:
Publisher:
release-pypi.yml on yasyf/captain-hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
capt_hook-0.2.0.tar.gz -
Subject digest:
3ef08b68930a8276d51a391338283a3b0e8203be555baa70406938acfac19958 - Sigstore transparency entry: 1736914420
- Sigstore integration time:
-
Permalink:
yasyf/captain-hook@7ae7493ce8f74cd6199d2a49d270340ccb462a60 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/yasyf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@7ae7493ce8f74cd6199d2a49d270340ccb462a60 -
Trigger Event:
push
-
Statement type:
File details
Details for the file capt_hook-0.2.0-py3-none-any.whl.
File metadata
- Download URL: capt_hook-0.2.0-py3-none-any.whl
- Upload date:
- Size: 89.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0fe22637e07837cf36b90d163b6b608854958f164f13e714afa215dde1189cb
|
|
| MD5 |
004af390d918befa1a05f333b66a4fd8
|
|
| BLAKE2b-256 |
c2bfe1bf5c6897e4767d3ff0a5ea8fcbb4fb87aa9b16b453b9a508382485eefb
|
Provenance
The following attestation bundles were made for capt_hook-0.2.0-py3-none-any.whl:
Publisher:
release-pypi.yml on yasyf/captain-hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
capt_hook-0.2.0-py3-none-any.whl -
Subject digest:
c0fe22637e07837cf36b90d163b6b608854958f164f13e714afa215dde1189cb - Sigstore transparency entry: 1736914469
- Sigstore integration time:
-
Permalink:
yasyf/captain-hook@7ae7493ce8f74cd6199d2a49d270340ccb462a60 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/yasyf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@7ae7493ce8f74cd6199d2a49d270340ccb462a60 -
Trigger Event:
push
-
Statement type: