Feature Request: Add PostRewind hook event for plugins
Summary
Add PreRewind and PostRewind hook events that fire when the user executes /rewind, allowing plugins to react to conversation rollbacks.
Use Case
Plugins like claude-mem track session activity (observations, prompts, tool usage) in a timeline. When users rewind a conversation, the plugin's recorded history becomes inconsistent with the actual conversation state.
Current behavior:
- User submits prompt → UserPromptSubmit hook fires → plugin records the prompt
- Claude responds with tool calls → PostToolUse hooks fire → plugin records observations
- User runs /rewind → no hook fires → plugin still shows the now-undone activity
Desired behavior:
- User runs /rewind
- PreRewind hook fires → plugin can snapshot or reset state before context is removed (aligns with the existing PreCompact pattern)
- PostRewind hook fires → plugin can soft-delete records, inject post-rewind instructions, or update its timeline
Proposed Hook Inputs
export type PreRewindHookInput = BaseHookInput & {
hook_event_name: 'PreRewind';
rewind_target_message_id: string; // The message ID being rewound to
messages_to_remove: string[]; // IDs of messages about to be undone
files_in_context?: string[]; // Files currently in context (before rewind)
};
export type PostRewindHookInput = BaseHookInput & {
hook_event_name: 'PostRewind';
user_message_id: string; // The message ID that was rewound to
rewound_message_ids: string[]; // IDs of messages that were undone
files_changed?: string[]; // Files affected by the rewind
};
Why This Matters
- Data consistency: Plugins maintaining state need to know when that state becomes invalid
- Context tracking: Plugins tracking what's in context (e.g. read files, active tools) produce false positives after rewind — PreRewind lets them reset cleanly
- User experience: Timeline/history views showing "ghost" activity that was undone is confusing
- Ecosystem growth: As more plugins emerge, this becomes increasingly important
Existing Infrastructure
The SDK already has SDKControlRewindFilesRequest internally. This request is asking to expose corresponding hook events so plugins can observe when rewind happens. The Pre/Post pattern already exists with PreCompact/PostCompact.
Alternatives Considered
- Polling transcript file - Hacky, race-prone, inefficient
- Manual API call by user - Poor UX, users won't remember to do it
- Detecting via missing tool_result - Unreliable, doesn't capture all rewind scenarios
A proper hook event pair is the clean solution that aligns with the existing hook architecture.
---
_Re-opened from #18858, which was closed due to inactivity. The feature request remains valid and relevant._ _Updated to include PreRewind per community feedback._
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗