Skip to main content

Stop repeating yourself to Claude.

Project description

captain-hook

Stop repeating yourself to Claude. captain-hook mines your transcripts for the corrections you keep giving and opens PRs that turn each one into a typed, tested Python hook.

CI PyPI License: PolyForm Noncommercial

Get started

uvx capt-hook init

init scaffolds .claude/hooks/, wires Claude Code's settings, and arms the session reviewer. One block_command later, a force-push dies at PreToolUse and the hook's inline tests run green:

Terminal running 'uvx capt-hook test' — a hook blocks git push --force and both inline tests pass

Driving with an agent? Paste this:

/plugin marketplace add yasyf/captain-hook
/plugin install captain-hook@captain-hook
Prefer a prompt over the plugin?
Run `uvx capt-hook init` in this repo, write one hook that blocks force-pushes,
and verify it with `uvx capt-hook test`. Read https://yasyf.github.io/captain-hook/
if you get stuck.

Use cases

Block force-push and rm -rf before they run

One bad Bash call rewrites shared history or eats a directory, and by the time you spot it in the transcript it already ran. Declare the block once, tests inline:

# .claude/hooks/safety.py
from captain_hook import Allow, Block, Input, block_command

block_command(
    ["git", "push", "--force"],
    reason="Force-pushing rewrites shared history",
    hint="Use `git push --force-with-lease` instead",
    tests={
        Input(command="git push --force"): Block(),
        Input(command="git push origin main"): Allow(),
    },
)

The next git push --force never executes: the agent sees BLOCKED: Force-pushing rewrites shared history plus the hint, and reaches for --force-with-lease instead. rm -rf is one more block_command away.

Turn repeated corrections into rules Claude can't forget

You've typed "use uv, not pip" in a dozen sessions, and session thirteen makes the same mistake. After init, the session reviewer reads each transcript as the session ends, keeps the corrections that are standing rules, and — once a pattern proves itself across sessions — opens a PR that codifies it as a hook. Watch the pipeline:

uvx capt-hook status

The dashboard lists every correction it's tracking, staged from first sighting to open PR. You review the PR like any other; merged hooks enforce the rule from then on.

Gate "done" until the tests actually pass

The agent declares victory while the suite is red. A Stop gate holds the line:

# .claude/hooks/quality.py
from captain_hook import RanCommand, TouchedFile, gate

gate(
    "You edited Python files but never ran the tests. Run `uv run pytest` before finishing.",
    only_if=[TouchedFile("**/*.py")],
    skip_if=[RanCommand(r"\bpytest\b")],
)

The agent can't end the turn until a pytest run shows up in the transcript, and the gate stands down on its own once one does.

More in the docs

  • Session reviewer — the full corrections lifecycle, from transcript to merged hook PR — guide
  • Conditions — typed filters over tools, files, commands, and transcript history — guide
  • LLM hooks — gate on a model's verdict when a regex can't decide — guide
  • Workflows — multi-step Stop gates with artifact checks and checklists — guide
  • Packs — the shipped general, python, and go hook packs — guide
  • Testing — run uvx capt-hook test --json in CI so a regressed hook fails the build — guide

Read the docs for the full guide. Licensed under PolyForm Noncommercial 1.0.0, free for noncommercial use.

Project details


Release history Release notifications | RSS feed

This version

8.8.0

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-8.8.0.tar.gz (216.4 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-8.8.0-py3-none-any.whl (271.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for capt_hook-8.8.0.tar.gz
Algorithm Hash digest
SHA256 d7602f243675323ed2619cc8a7ee90b71bf53c73672d4920af34d0dc2f3a1cfc
MD5 c11cb71969b825d0e2c12c99f0e02182
BLAKE2b-256 5513b153be0d27d5c410f70e62fa57bde1e5e163c6f2ed09678f5fbb817829b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for capt_hook-8.8.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-8.8.0-py3-none-any.whl.

File metadata

  • Download URL: capt_hook-8.8.0-py3-none-any.whl
  • Upload date:
  • Size: 271.2 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-8.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b381164b32028fa882097210d166d7a164c74e3878b63b18358037c8ad51551a
MD5 02efb3eba5d5b000d058c49ff61cb536
BLAKE2b-256 d3bf78cb6f46a7ef9881e416651d1e733d4af9ec7837c46a61c15f25ae0dcbec

See more details on using hashes here.

Provenance

The following attestation bundles were made for capt_hook-8.8.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