Skip to content

[Feature Request] Add session:compacted hook event with compact summary #11799

@gamer-mitsuha

Description

@gamer-mitsuha

Summary

Add a new hook event session:compacted that fires after a session is compacted, including the compact summary in the event context.

Motivation

When an agent session is compacted (e.g., hitting 200k context limit), the agent loses working context. With a session:compacted hook event, workspace hooks could:

  1. Auto-recover task context — Read recent memory files and re-inject relevant working state
  2. Notify the user — Session was compacted, here is what I was working on
  3. Save pre-compaction state — Persist important in-flight context to files before it is lost
  4. Audit/logging — Track compaction frequency and impact

Current Workaround

The agent:bootstrap hook fires on every turn (including post-compaction), but there is no way to distinguish a normal turn from a post-compaction turn. The compact summary is available internally but not exposed to hooks.

Proposed API

// Event type: 'session', action: 'compacted'
{
  type: 'session',
  action: 'compacted',
  sessionKey: string,
  context: {
    sessionId: string,
    compactSummary: string,      // The LLM-generated summary
    preCompactTokens: number,    // Token count before compaction
    postCompactTokens: number,   // Token count after compaction
    workspaceDir: string,
  }
}

Use Case

We are building an AI maid agent (Akari) that manages development workflows across long sessions. Compaction frequently interrupts active work (e.g., monitoring a CI pipeline, reviewing PRs). A session:compacted hook would allow automatic context recovery from workspace files.

Environment

  • OpenClaw 2026.2.6-3
  • macOS, using workspace hooks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions