PreCompact hook: add blocking mode for interactive turn before compaction
Problem
When context compaction triggers (manual /compact or auto), there's no way to run a skill or give the model an interactive turn before compaction begins. The PreCompact hook fires during compaction and its stdout becomes a system-reminder in the post-compaction context — but by then, conversation history is already lost.
This means workflows like /handoff (saving session state before context is discarded) can't be triggered automatically before compaction.
Proposal
Add a blocking mode to PreCompact hooks that:
- Pauses compaction before summarization begins
- Gives the model an interactive turn with the hook's stdout as context
- Lets the model run skills (e.g.,
/handoffto save session state) or ask the user a question - Resumes compaction after the interactive turn completes (or user approves)
Example config
{
"PreCompact": [
{
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/pre-compact-handoff.sh",
"blocking": true
}
]
}
]
}
When blocking: true, the hook's stdout triggers a model turn before compaction proceeds. The model can then invoke skills, interact with the user, or perform cleanup — then compaction continues.
Alternative: lifecycle-event-to-skill binding
A more general solution would be native event-to-skill triggers:
{
"lifecycle": {
"preCompact": ["/handoff"]
}
}
This would allow skills to run automatically on lifecycle events without needing shell command intermediaries.
Use case
Session handoff (/handoff) generates a .handoff.md file capturing goal, decisions, changed files, and next steps — so a fresh session can resume with full context in ~2K tokens. Running this automatically before compaction would prevent context loss without requiring the user to remember to run it manually.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗