[FEATURE] Add OnCompaction hook event to reload context after memory compaction
Feature Request
Add a new hook event (e.g. OnCompaction or PostCompaction) that fires when Claude Code compresses/compacts the conversation context.
Problem
After context compaction, Claude frequently loses adherence to rules defined in CLAUDE.md files (both personal ~/.claude/CLAUDE.md and project-level). Instructions that were being followed correctly earlier in the session stop being respected after compaction occurs. There is currently no way to detect or respond to compaction events.
Proposed Solution
Add a hookable event that fires after context compaction completes. This would allow users to:
- Force re-reading of CLAUDE.md files so rules are re-injected into the active context
- Re-inject critical instructions or reminders that may have been lost
- Log when compaction occurs for debugging session quality issues
Use Case
Users with detailed personal settings (~/.claude/CLAUDE.md) and project instructions rely on these being consistently followed throughout a session. Long sessions that trigger compaction silently degrade instruction adherence, with no mechanism to detect or correct it.
Even without the hook, ensuring CLAUDE.md content survives compaction intact would address the root issue — but a hook would give users a general-purpose tool for maintaining session quality.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗