[FEATURE] PreCompact Hook also for /compact

Resolved 💬 3 comments Opened Mar 20, 2026 by dsrednicki Closed May 26, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

Extend the PreCompact hook to also fire when the user manually runs /compact, not only during auto-compact triggered by context window l imits.

Why it matters: Any hook registered on PreCompact is silently skipped when users compact manually, making the hook unreliable for use cases like saving state, logging, or reminders before context is lost.

Proposed Solution

Current behavior: PreCompact only fires during automatic context compaction (when the context window limit is hit).

Desired behavior: PreCompact fires on both auto-compact and manual /compact.

Optionally pass a flag to distinguish trigger source (e.g. COMPACT_TRIGGER=manual vs COMPACT_TRIGGER=auto) so hooks can handle both cases differently if needed.

Alternative Solutions

_No response_

Priority

Medium - Would be very helpful

Feature Category

CLI commands and flags

Use Case Example

  1. I've a PreCompact hook to save my critical state into a dedicated memory file
  2. When running a session the hook save my state before autocompact happens
  3. If I clear the context manually by /compact or /clear, it is not triggered
  4. I lose my critical state

Additional Context

_No response_

View original on GitHub ↗

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