Files
claude-foundations/HOOKS.md
Paul O'Reilly 00fa1af898 Move pre-compact hook into repo with HOOKS.md documentation
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>
2026-03-12 23:51:26 +13:00

51 lines
1.5 KiB
Markdown

# 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
1. Symlink each hook into `~/.claude/hooks/`:
```bash
mkdir -p ~/.claude/hooks
ln -sf "$(pwd)/hooks/pre-compact-backup.sh" ~/.claude/hooks/pre-compact-backup.sh
```
2. Add the hook configuration to `~/.claude/settings.json`:
```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
1. Create the script in `hooks/`
2. Add an entry to this file
3. Symlink into `~/.claude/hooks/`
4. Add the matcher config to `~/.claude/settings.json`