feat: support prompt/agent hook types for PreCompact/PostCompact events

Resolved 💬 3 comments Opened Mar 20, 2026 by zhixianio Closed Apr 30, 2026

Problem

When using the auto-memory system, important information discovered during long conversations can be lost during context compaction if not saved to memory files in time. The PreCompact and PostCompact hooks exist, but they only support command type hooks — not prompt or agent types.

This means there's no way to have Claude take action (like writing memory files) before or after compaction. The current workaround is a command hook that returns additionalContext to remind Claude to flush memory after compaction — but this is indirect and unreliable compared to having Claude actually execute the flush as part of the hook.

Proposed Solution

Allow prompt and/or agent hook types for PreCompact and PostCompact events, similar to how they work for PreToolUse/PostToolUse.

This would enable configurations like:

{
  "hooks": {
    "PreCompact": [
      {
        "hooks": [
          {
            "type": "agent",
            "prompt": "Review the conversation for important information not yet saved to memory files. Write any unsaved discoveries, configurations, milestones, or decisions to the appropriate memory files before compaction occurs."
          }
        ]
      }
    ]
  }
}

Use Case

Users with the auto-memory system enabled want to ensure no information is lost during compaction. Currently:

  1. Long conversation accumulates important context
  2. Auto-compaction triggers
  3. Details are lost because they weren't saved to memory
  4. User has to repeat information or it's gone forever

With agent type hooks on PreCompact, Claude could automatically flush unsaved memories before compaction, similar to how OpenClaw handles this natively.

Current Workaround

Using a command hook on PostCompact that returns additionalContext to remind Claude to check for unsaved memories:

#!/bin/bash
cat <<'INNER_EOF'
{
  "hookSpecificOutput": {
    "hookEventName": "PostCompact",
    "additionalContext": "Context compaction just occurred. Review the summary and save any important unsaved information to memory files."
  }
}
INNER_EOF

This works but is less reliable than a direct agent action.

View original on GitHub ↗

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