claude-code-karma / captain-hook
CLAUDE.md328 starsChanged 4 months agoApache-2.0View on GitHub
Captain Hook is a type-safe Pydantic model library for Claude Code hook events. It provides models for all 24 hook types that fire during Claude Code sessions, with forward compatibility via extra="allow" configuration. The codebase follows a modular package structure under src/captain_hook/: The root models.py is a backward compatibility layer that re-exports from src.captain_hook. Parsing hook events: All hooks inherit from BaseHook and use ConfigDict(extra="allow") for forward compatibility. Hook capabilities vary: - Can block (exit code 2): PreToolUse, UserPromptSubmit, PermissionRequest,…
In this repository4 other files it gives its agents.
- api/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- frontend/CLAUDE.mdCLAUDE.md
- link-ticket-to-sessionSkill
The file
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Captain Hook is a type-safe Pydantic model library for Claude Code hook events. It provides models for all 24 hook types that fire during Claude Code sessions, with forward compatibility via extra="allow" configuration.
Commands
# Run all tests
pytest tests/test_models.py -v
# Run specific test class
pytest tests/test_models.py::TestPreToolUseHook -v
# Run with coverage
pytest tests/test_models.py --cov=src/captain_hook
# Verify imports work
python3 -c "from captain_hook import parse_hook_event, PreToolUseHook"Architecture
The codebase follows a modular package structure under src/captain_hook/:
base.py- Foundation:BaseHookclass with 5 common fields (session_id,transcript_path,cwd,permission_mode,hook_event_name) and all Literal type definitions__init__.py- Entry point: exports all models, containsparse_hook_event()dispatcher andHOOK_TYPE_MAPregistry- Hook modules - Grouped by category:
tool_hooks.py- PreToolUseHook, PostToolUseHook, PostToolUseFailureHookuser_hooks.py- UserPromptSubmitHook, PermissionRequestHook, NotificationHook, PermissionDeniedHook, ElicitationHook, ElicitationResultHooksession_hooks.py- SessionStartHook, SessionEndHookagent_hooks.py- StopHook, SubagentStartHook, SubagentStopHookcontext_hooks.py- PreCompactHook, InstructionsLoadedHooksetup_hooks.py- SetupHookfs_hooks.py- CwdChangedHook, FileChangedHookteam_hooks.py- TaskCreatedHook, TaskCompletedHook, TeammateIdleHook (experimental Agent Teams)worktree_hooks.py- WorktreeCreateHook, WorktreeRemoveHook
outputs.py- Response models for hooks that return JSON (PreToolUseOutput, StopOutput, PermissionRequestOutput, PermissionDeniedOutput)
The root models.py is a backward compatibility layer that re-exports from src.captain_hook.
Key Patterns
Parsing hook events:
from captain_hook import parse_hook_event
hook = parse_hook_event(json_data) # Returns typed hook based on hook_event_nameAll hooks inherit from BaseHook and use ConfigDict(extra="allow") for forward compatibility.
Hook capabilities vary:
- Can block (exit code 2): PreToolUse, UserPromptSubmit, PermissionRequest, Elicitation, ElicitationResult, TeammateIdle, WorktreeCreate
- Can block (
{"continue": false}): TaskCreated, TaskCompleted - Can modify input: PreToolUse
- Can modify environment: SessionStart
- Can override worktree path (HTTP hook): WorktreeCreate
- Can request retry: PermissionDenied
- Can force continuation: Stop, SubagentStop
- New PreToolUse permission decisions:
allow,deny,ask,defer
Documentation
Each hook type has detailed documentation in docs/hooks/[HookName]-info-available.md describing all available fields and behaviors.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

