Feature Request: PreContextCompaction hook event
Resolved 💬 2 comments Opened Jan 4, 2026 by sandrop Closed Jan 4, 2026
Feature Request
Add a PreContextCompaction hook event that triggers before the context window is automatically compacted/summarized.
Use Case
I created a /retro skill that analyzes session collaboration patterns and recommends improvements to CLAUDE.md and workflows. Currently, this skill must be run manually via slash command.
Ideally, this retrospective analysis would run automatically before context compaction to ensure:
- Session insights are captured before context is summarized
- Collaboration improvements are identified even when the user forgets to run
/retro - A history of retrospectives is maintained across sessions
Current Hook Events
The current hook system supports these events:
bash- Bash tool commandsfile- Edit, Write, MultiEdit toolsstop- When agent wants to stopprompt- When user submits promptsall- All events
Proposed Addition
Add a new hook event:
PreContextCompaction- Triggers before context window is automatically compacted
Example Usage
{
"hooks": {
"PreContextCompaction": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo 'Context compaction starting...'"
}
]
}
]
}
}
Or for skill invocation, the hook could trigger a slash command or skill before compaction occurs.
Benefits
- Enables automatic session retrospectives
- Allows saving session state/notes before context loss
- Supports automated logging or metrics collection
- Gives users a chance to preserve important context
Environment
- Claude Code CLI
- macOS Darwin 25.2.0
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗