Feature request: PreCompact / PostCompact hook events

Resolved 💬 2 comments Opened Mar 26, 2026 by shokuro708 Closed Mar 26, 2026

Summary

Add PreCompact and/or PostCompact hook events that fire before and after conversation context compaction.

Motivation

When working on long, multi-step tasks (e.g., vibe coding sessions), context compaction can cause loss of important working state — current progress, remaining tasks, key decisions made, etc.

Currently, there is no way to programmatically react to compaction. A PreCompact hook event would allow users to trigger scripts that preserve critical state before the context window is compressed. For example:

  • Writing a progress summary to a file (e.g., plans/ directory or memory)
  • Saving current task state to an external system (Notion, Linear, etc.)
  • Logging what was in context before compaction for debugging

Current workaround

The only option today is to add instructions in CLAUDE.md asking Claude to proactively save progress when the conversation gets long. This is unreliable because:

  • Claude doesn't know exactly when compaction will happen
  • It depends on Claude choosing to act, rather than being triggered automatically

Proposed hook events

| Event | Fires when | Use case |
|---|---|---|
| PreCompact | Just before context compaction begins | Save progress, dump state |
| PostCompact | After compaction completes | Verify state was preserved, reload context |

These would follow the same pattern as existing events (Stop, PreToolUse, etc.).

Environment

  • Claude Code on Windows 11
  • Using existing hooks (Stop event for Notion session logging)

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗