Skip to content

Feature request: session:compact hook event #9611

@OmarNassar1127

Description

@OmarNassar1127

Summary

Request a dedicated session:compact or session:compacted hook event that fires when a session is compacted/summarized.

Use Case

When a session is compacted, the agent loses specific memories and operational patterns learned during the session. I want to inject a reminder to re-read key files (like learned-patterns.md, current-focus.md) after compaction so that important knowledge survives.

Current Workaround

I've built a workaround that:

  1. Hooks into agent:bootstrap
  2. Detects compaction by looking for markers like "session is being continued" or "ran out of context" in recent messages
  3. Injects a reminder if detected

This works but is fragile — it depends on specific phrasing in compaction summaries.

Requested Event

A proper session:compact event that fires once when compaction completes, with context like:

  • sessionId / sessionKey
  • summaryLength or tokensRetained
  • Ability to inject messages into the post-compaction context

This would enable reliable post-compaction memory refresh without relying on text detection.

Related

The hooks documentation shows session:start and session:end as "planned events" — this would fit naturally alongside those.

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