Feature request: Hook for context auto-compact/restoration events
Problem
When context is auto-compacted mid-task, there's no way for the user or Claude to react to this event. This creates a gap:
- Claude is mid-process working on something (e.g., multi-step refactoring)
- Context auto-compacts (user sees this happen in the terminal)
- Claude continues from the summary, potentially missing critical context
- User can't easily interrupt because Claude is mid-task
- By the time Claude finishes (5-10 min in some scenarios), user forgets to tell Claude to re-read context
- Claude continues with stale/incomplete information
Current Workaround
I've added instructions to my CLAUDE.md that tell Claude to check for the phrase "This session is being continued from a previous conversation" and read session notes if detected. But this is fragile - it depends on Claude reading CLAUDE.md after the restore, and only triggers on the next action, not immediately.
Proposed Solution
Add a new hook type that fires when context is auto-compacted/restored:
{
"hooks": {
"ContextRestored": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "cat .claude/SESSION_*.md | tail -50"
}
]
}
]
}
}
Or alternatively, a system-level option to automatically include certain files after context restoration:
{
"contextRestoration": {
"alwaysIncludeFiles": [".claude/SESSION_*.md"]
}
}
Use Case
I maintain detailed session notes (.claude/SESSION_YYYY-MM-DD.md) that contain:
- Current state of work
- Critical context (IPs, credentials, decisions made)
- What was just completed
- What needs to happen next
When context compacts, the summary captures some of this but often misses details. Having a hook that automatically feeds session notes back into context after restoration would ensure continuity.
Environment
- Claude Code version: Latest
- OS: WSL2 (Ubuntu) on Windows 11
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗