Skip to content

Add session:pre-compact event hook #11617

@murilo

Description

@murilo

Currently there's no way for hooks to act before a session is compacted, resulting in permanent context loss.

Problem:
When a session reaches context limit and is compacted, all conversation history is lost. The agent must manually reconstruct context by re-reading memory files.

Proposed solution:

Add new event: session:pre-compact

Trigger: Before context compression begins

Use cases:

  • Save conversation summary before compaction
  • Export important decisions/context to memory
  • Alert user that context will be lost
  • Allow memory-autosave hook to capture final state

Example hook:

// hooks/bundled/pre-compact-save/handler.ts

const handler: HookHandler = async (event) => {
  // 1. Extract current context
  // 2. Summarize with LLM
  // 3. Save to memory/YYYY-MM/DD-{channel}.md
  // 4. Optionally keep "hot" context for re-injection
};

Related: This would solve the context recovery problem and enable better memory continuity.

Priority: 🟠 High

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions