Skip to content

Feature: Compaction event hooks (onCompactionComplete, onSummaryCreated) #134

@KalebCole

Description

@KalebCole

Problem

There's no way for consuming applications to react to compaction events. When LCM compacts context, the CompactResult is returned to the caller but not broadcast to any hook/event system. This prevents use cases like:

  • Triggering self-improvement evaluation after compaction
  • Writing compacted knowledge to external stores (Obsidian, Notion)
  • Notifying users when significant context was compacted
  • Metrics/telemetry on compaction frequency and efficiency

Proposed Solution

Add optional callback hooks to the plugin config:

  1. onCompactionComplete(result: CompactResult) — fires after compact() succeeds, with the full summary content, token delta, and message IDs that were compacted
  2. onSummaryCreated(summary: Summary) — fires when a new summary node is inserted into the DAG
  3. beforeCompaction(context: CompactionContext) — fires before compaction starts, allowing pre-processing

These could be implemented as:

  • Config-defined webhook URLs
  • Shell command hooks (like Claude Code's hook system)
  • Event emitter on the ContextEngine interface

Workaround

Currently polling the SQLite DB directly for new summaries, which works but is fragile and doesn't give real-time notification.

Context

The engine.ts compact() method and compaction.ts are the natural insertion points. The CompactResult type already contains all the data needed for hooks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions