Skip to content

Deliver compact SessionStart context at the compaction - #455

Merged
ilovepixelart merged 1 commit into
mainfrom
fix/compact-hook-context-in-run
Nov 15, 2026
Merged

ilovepixelart merged 1 commit into
mainfrom
fix/compact-hook-context-in-run

Conversation

@ilovepixelart

Copy link
Copy Markdown
Owner

The context of a SessionStart hook with matcher compact was queued until the next before_agent_start, which only a user prompt reaches. A run that compacted midway finished without the model reading it; in print mode the text was lost with the process.

The session_compact handler now sends the context itself: pi steers it into a running agent before its next request, and appends it to the session right after the compaction entry when idle, without starting a turn. Claude Code attaches the hook output right after the compact summary in both cases.

Not covered: with a routed (virtual) model pi compacts later in request preparation, so the steered message may arrive one request late there.

Closes #453

  • npm run check passes (Biome, strict tsc, Vitest)
  • Tests cover the change

A SessionStart hook with matcher "compact" had its context queued for
the next before_agent_start, which only a user prompt reaches. A run
that compacted midway finished without the model reading it, and in
print mode the text was lost with the process.

The context is now sent from the session_compact handler: pi steers it
into a running agent before its next request and appends it to the
session when idle. Claude Code attaches the hook output right after the
compact summary in both cases.
@sonarqubecloud

Copy link
Copy Markdown

@ilovepixelart
ilovepixelart merged commit 19c0972 into main Nov 15, 2026
13 checks passed
@ilovepixelart
ilovepixelart deleted the fix/compact-hook-context-in-run branch November 15, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hooks: SessionStart "compact" output is held until the next user prompt, so an agent that keeps working after compaction never sees it

1 participant