Feature request: add a PreCompact hook event

Resolved 💬 3 comments Opened Feb 19, 2026 by jaseemts Closed Feb 19, 2026

What feature would you like to see?

Add a dedicated PreCompact hook event that runs immediately before conversation compaction (manual or auto).

Why this matters

Today, compaction can happen automatically when token usage crosses model_auto_compact_token_limit. There are hook events for AfterAgent and AfterToolUse, but no hook for the compaction boundary itself.

For users who maintain external memory/state, this means there is no deterministic point to capture full pre-compaction context.

Proposed behavior

Add a new hook event, for example:

  • PreCompact

Triggered when compaction is about to run (both manual and auto).

Suggested payload fields:

  • session_id
  • thread_id
  • turn_id (if applicable)
  • reason (manual or auto)
  • total_usage_tokens_before_compaction
  • auto_compact_limit
  • triggered_at
  • cwd

Failure behavior

Please make failure policy explicit and configurable (same style as existing hook outcomes):

  • continue on error
  • abort compaction on error

Example use cases

  • extract important memory facts before summary compaction
  • persist custom checkpoints to external systems
  • emit telemetry about compaction quality and timing
  • run a user-defined “last chance” context snapshot

Additional context

This request is specifically for Codex hooks (not Claude-specific behavior).

If helpful, I can propose a concrete schema and tests aligned with the existing hook event design.

View original on GitHub ↗

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