Skip to content

fix(composed-handler): strip inline system messages for Anthropic-transport providers#134

Open
jsboige wants to merge 1 commit into
MadAppGang:mainfrom
jsboige:fix/strip-inline-system-messages
Open

fix(composed-handler): strip inline system messages for Anthropic-transport providers#134
jsboige wants to merge 1 commit into
MadAppGang:mainfrom
jsboige:fix/strip-inline-system-messages

Conversation

@jsboige

@jsboige jsboige commented May 30, 2026

Copy link
Copy Markdown

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 accept user and assistant roles in messages.

Changes

packages/cli/src/handlers/composed-handler.ts

After step 4 (buildPayload), add a new step 4b that detects anthropic-sse transport format and strips any role: "system" messages from the payload's messages array. Their text content is merged into the top-level system prompt field instead (appended to any existing system prompt).

packages/cli/src/handlers/shared/format/openai-messages.ts

Add 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

  • Z.AI (Anthropic transport)
  • GLM direct (Anthropic transport)
  • MiniMax, Kimi (Anthropic transport)
  • Any future Anthropic-compat provider

How to test

  1. Use Claude Code v2.1.153+ which injects system-reminders
  2. Route through claudish with an Anthropic-transport provider:
    claudish --model zai@glm-4.7 "hello"
  3. Without this fix: HTTP 400 from Z.AI ("invalid role: system")
  4. With this fix: System reminders silently merged into system prompt, request succeeds

…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>
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.

2 participants