claude-hooks
Programmatic management of Claude Code hooks.
Features
- install — Add hooks to
~/.claude/settings.jsonwith atomic writes - uninstall — Remove only hooks installed by this crate (ownership tracking)
- list — Show all hooks with managed/unmanaged status
Usage
use ;
// Install a hook
let handler = HookHandler ;
install?;
// List all hooks
for entry in list?
// Uninstall (only works for hooks we installed)
uninstall?;
Design
- Atomic writes: Uses temp-file-then-rename to prevent corruption
- Ownership tracking: Local registry in XDG data dir tracks which hooks we installed
- Non-destructive: Never modifies hooks installed by other tools or manually
Hook Events
Supports all Claude Code hook events:
Start,StopBeforePrompt,AfterPromptBeforeToolUse,AfterToolUseBeforeEdit,AfterEditBeforeRevert,AfterRevertBeforeRun,AfterRun
License
MIT OR Apache-2.0