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:
- Auto-recover task context — Read recent memory files and re-inject relevant working state
- Notify the user — Session was compacted, here is what I was working on
- Save pre-compaction state — Persist important in-flight context to files before it is lost
- 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
Summary
Add a new hook event
session:compactedthat 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:compactedhook event, workspace hooks could:Current Workaround
The
agent:bootstraphook 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
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