fix(composed-handler): strip inline system messages for Anthropic-transport providers#134
Open
jsboige wants to merge 1 commit into
Open
fix(composed-handler): strip inline system messages for Anthropic-transport providers#134jsboige wants to merge 1 commit into
jsboige wants to merge 1 commit into
Conversation
…nsport providers Claude Code v2.1.153+ injects role:"system" messages inline in the messages array (e.g. system-reminders). Anthropic-compat providers like Z.AI and GLM reject role:"system" in messages -- only user/assistant are accepted. This strips them from the messages array and merges their content into the top-level system prompt field. Also handle inline system messages in the OpenAI message converter so they are properly merged rather than silently dropped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
Claude Code v2.1.153+ injects
role: "system"messages inline in the messages array (e.g., system-reminders injected between turns). Anthropic-compat providers like Z.AI and GLM reject these with HTTP 400 because they only acceptuserandassistantroles in messages.Changes
packages/cli/src/handlers/composed-handler.tsAfter step 4 (buildPayload), add a new step 4b that detects
anthropic-ssetransport format and strips anyrole: "system"messages from the payload's messages array. Their text content is merged into the top-levelsystemprompt field instead (appended to any existing system prompt).packages/cli/src/handlers/shared/format/openai-messages.tsAdd a handler for
msg.role === "system"in the message processing loop. System messages are merged into the existing system prompt (prepended or appended to the first system message) rather than silently dropped or causing a protocol error.Providers affected
How to test
claudish --model zai@glm-4.7 "hello"