Skip to main content

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

brew install --formula yasyf/tap/captain-hook
uvx capt-hook helper install
uvx capt-hook init

The formula fills the Cellar and helper install deploys the fixed, signed host at ~/Applications/Captain Hook.app; init scaffolds .claude/hooks/, wires Claude Code's settings, and arms the session reviewer. Every event runs the exact capt-hook build the installed app names — nothing resolves "latest" mid-session, and the app keeps itself current in the background. One block_command later, a force-push dies at PreToolUse and the hook's inline tests run green:

Animated terminal: a hook blocks git push --force at PreToolUse, then 'uvx capt-hook test' passes both inline tests

Driving with an agent? Paste this:

/plugin marketplace add yasyf/captain-hook
/plugin install captain-hook@captain-hook
Prefer a prompt over the plugin?
Install the `yasyf/tap/captain-hook` Homebrew formula, run `uvx capt-hook helper install`,
then 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. And when a pattern can't decide, walk the parse — this is the heart of the shipped rm guard:

for call in evt.command.calls("rm"):
    if call.targets.expand().exhausted:
        return evt.block("rm targets too broad to verify")
    return call.sub("rm", "trash", args=call.targets)

evt.command is the parsed command line: every rm across && and pipes, each target resolved against the working directory, the rewrite quote-safe.

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, Regex, 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(Regex(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

  • Interactive tutorial — block your first command in the browser, verified against the real engine — start it
  • 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
  • The inspiration — where this came from, and why steering agents belongs in tested hooks instead of prompts — check out the blog post

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

Metadata

Release files for capt-hook 12.88.26

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

Source distribution (sdist)

Source distribution for capt-hook 12.88.26
File Size Uploaded
capt_hook-12.88.26.tar.gz 624.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for capt-hook 12.88.26
File Interpreter ABI Platform
capt_hook-12.88.26-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / capt_hook-12.88.26.tar.gz

Download URL capt_hook-12.88.26.tar.gz
Size 624.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d78c9c5e0963827ed60f83add785a496bfa643b19bc73d5c7d6e6102c9b7f99d
BLAKE2b-256 checksum
How to use checksums
7188d542849902a63a270497df453b80fadc42b1d933a06aa4fbe3c8b6727cd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Oct 7, 2026.

Transparency log

Release files / capt_hook-12.88.26-py3-none-any.whl

Download URL capt_hook-12.88.26-py3-none-any.whl
Size 748.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d73c8351ba84b32abcbdf9bd08a9d925eae5643152f0911b1c92939926a290c
BLAKE2b-256 checksum
How to use checksums
81108a494a374669f331921070c07276f8e393681c9ead95488fcd6bd787f45e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Oct 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

12.88.26 This release

2 release files

12.9.0

2 release files

12.8.0

2 release files

12.7.2

2 release files

12.7.1

2 release files

12.7.0

2 release files

12.6.0

2 release files

12.5.0

2 release files

12.4.0

2 release files

12.3.0

2 release files

12.2.0

2 release files

12.1.0

2 release files

12.0.1

2 release files

12.0.0

2 release files

11.0.0

2 release files

10.7.0

2 release files

10.6.0

2 release files

10.5.0

2 release files

10.4.0

2 release files

10.2.0

2 release files

10.1.0

2 release files

10.0.0

2 release files

9.31.0

2 release files

9.28.0

2 release files

9.27.0

2 release files

9.26.0

2 release files

9.25.0

2 release files

9.24.0

2 release files

9.23.0

2 release files

9.22.0

2 release files

9.21.0

2 release files

9.20.0

2 release files

9.19.0

2 release files

9.18.0

2 release files

9.16.0

2 release files

9.15.0

2 release files

9.14.0

2 release files

9.13.0

2 release files

9.12.0

2 release files

9.11.0

2 release files

9.10.0

2 release files

9.9.0

2 release files

9.7.1

2 release files

9.7.0

2 release files

9.6.0

2 release files

9.5.0

2 release files

9.4.0

2 release files

9.3.0

2 release files

9.2.1

2 release files

9.2.0

2 release files

9.1.0

2 release files

9.0.0

2 release files

8.19.0

2 release files

8.18.0

2 release files

8.17.0

2 release files

8.16.0

2 release files

8.15.0

2 release files

8.9.0

2 release files

8.8.0

2 release files

8.7.0

2 release files

8.6.0

2 release files

8.5.1

2 release files

8.5.0

2 release files

8.4.1

2 release files

8.4.0

2 release files

8.3.0

2 release files

8.2.0

2 release files

8.1.0

2 release files

8.0.0

2 release files

7.0.0

2 release files

6.5.0

2 release files

6.4.0

2 release files

6.3.0

2 release files

6.2.0

2 release files

6.1.0

2 release files

6.0.0

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.1

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.21.0

2 release files

3.20.0

2 release files

3.19.0

2 release files

3.18.0

2 release files

3.17.0

2 release files

3.16.0

2 release files

3.15.0

2 release files

3.14.0

2 release files

3.13.0

2 release files

3.12.0

2 release files

3.11.1

2 release files

3.11.0

2 release files

3.10.1

2 release files

3.10.0

2 release files

3.9.1

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

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