Hook source of truth now in hooks/, symlinked from ~/.claude/hooks/. HOOKS.md covers what each hook does and installation steps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1.5 KiB
1.5 KiB
Hooks
Claude Code hooks that run automatically in response to events. Source of truth lives here; symlinks point from ~/.claude/hooks/ back to this directory.
Available Hooks
| Hook | Event | File |
|---|---|---|
| Pre-compact backup | PreCompact (auto + manual) | hooks/pre-compact-backup.sh |
Pre-compact Backup
Saves a copy of the session transcript before context compaction so no conversation history is lost. Backs up to ~/.claude/transcript-backups/ with timestamped filenames. Auto-prunes backups older than 30 days.
Triggers: Both auto-compaction (context window full) and manual (/compact command).
Requires: python3 (for JSON parsing from stdin).
Installation
-
Symlink each hook into
~/.claude/hooks/:mkdir -p ~/.claude/hooks ln -sf "$(pwd)/hooks/pre-compact-backup.sh" ~/.claude/hooks/pre-compact-backup.sh -
Add the hook configuration to
~/.claude/settings.json:{ "hooks": { "PreCompact": [ { "matcher": "auto", "hooks": [{ "type": "command", "command": "~/.claude/hooks/pre-compact-backup.sh", "timeout": 15 }] }, { "matcher": "manual", "hooks": [{ "type": "command", "command": "~/.claude/hooks/pre-compact-backup.sh", "timeout": 15 }] } ] } }
Adding New Hooks
- Create the script in
hooks/ - Add an entry to this file
- Symlink into
~/.claude/hooks/ - Add the matcher config to
~/.claude/settings.json