Skip to main content

Module pre_compact

Module pre_compact 

Source
Expand description

spool hook pre-compact — persist self-tagged memories before context compaction so they survive the window trim.

§Pipeline

  1. Read active context from stdin (Claude Code passes the about-to-be- compacted conversation as a text blob).
  2. Run self_tag::detect to find explicit memory markers.
  3. Redact secrets, dedupe against existing ledger entries.
  4. Persist surviving signals as accepted via LifecycleService.
  5. Write <cwd>/.spool/last-pre-compact.unix marker.

§Why this matters

Context compaction is lossy. If the user said “记一下: X” early in a session and the compactor drops that turn, the memory is lost unless we capture it here. The Stop hook also captures self-tags, but it runs after the session ends — pre-compact fires during the session, before the window shrinks.

Structs§

PreCompactArgs
PreCompactReport

Functions§

run