PreCompact hook not triggered when /compact command runs
Description
The PreCompact hook configured in ~/.claude/settings.json is not being triggered when the /compact command is executed.
Environment
- User type: Claude Max subscriber
- OS: Ubuntu Linux 6.8.0-88-generic
- Claude Code version: Latest (as of Dec 10, 2025)
Configuration
The hook is properly configured in ~/.claude/settings.json:
"PreCompact": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "/home/mputz/.claude/hooks/v2/pre-compact.sh"
}
]
}
]
Expected Behavior
When /compact is run, the pre-compact.sh script should execute before compaction occurs, outputting checkpoint information to the terminal.
Actual Behavior
/compactruns and shows:[2mCompacted (ctrl+o to see full summary)[22m- The PreCompact hook is not invoked
- No new recovery checkpoint is created in
~/.claude/recovery/ - Running
/hook:statusconfirms the hook is configured, but it doesn't execute
Verification Steps
- Hook script exists and is executable:
````
-rwx--x--x 1 mputz mputz 2635 Nov 29 13:30 /home/mputz/.claude/hooks/v2/pre-compact.sh
- Hook runs correctly when invoked manually:
``bash``
$ /home/mputz/.claude/hooks/v2/pre-compact.sh
═══════════════════════════════════════════════════════
PRE-COMPACT SAFETY CHECKPOINT
Time: 2025-12-10T11:39:14-05:00
═══════════════════════════════════════════════════════
✓ Environment saved
✓ Working directory saved
✓ Recovery manifest created
- Recovery directory shows last checkpoint was from earlier session (02:21 AM), not from the /compact that just ran (11:35 AM):
````
$ ls -lt ~/.claude/recovery/ | head -3
-rw-r--r-- 1 mputz mputz 404 Dec 10 02:21 manifest-20251210-022122.json
Impact
PreCompact hooks are useful for creating recovery checkpoints before context compaction. Without this hook firing, users lose the ability to save state before compaction occurs.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗