Repository navigation
Conversation
…lows the user turn Claude Code 2.1.319 appends a `system`-role message after the user turn whenever a UserPromptSubmit hook or an output style emits text, so the compaction instruction sits in the final user message while `messages.last()` is that system message. With the normal (cache-safe) system prompt neither detection path matched and native compaction never triggered on such installs. Skip trailing `system` messages and check the last user message; any other trailing role still means "not a boundary". Fixes raine#204 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #204.
Claude Code 2.1.319 appends a
system-role message after the user turn whenever aUserPromptSubmithook or an output style emits text, so the compaction instruction (CRITICAL: Respond with TEXT ONLY…+Your task is to create a detailed summary…) sits in the final user message whilemessages.last()is thatsystemmessage.is_compact_messages_requestonly looked atmessages.last(), so with the normal (cache-safe) system prompt neither detection path matched and native compaction never triggered on such installs.Change: skip trailing
system-role messages and check the last user message. Any other trailing role (e.g.assistant) still means the request is not a compaction boundary, so the existing "markers must be in the final user message" behaviour is kept.Tests:
compact_request_detected_when_hook_system_message_follows_user(the captured 2.1.319 shape) andcompact_message_not_detected_when_assistant_message_follows_user; the existing compaction detection tests pass unchanged.Verified against a live Claude Code 2.1.319 session through the proxy:
/compactproduced zeroserver_compaction_*events before the change; the same request shape with the instruction as the finalusermessage triggersserver_compaction_triggered+server_compaction_completedin ~5 s.🤖 Generated with Claude Code