Skip to content

fix(codex): route Claude system prompts to Responses API instructions - #820

Open
Shanlans wants to merge 1 commit into
kittors:devfrom
Shanlans:fix/codex-system-to-instructions
Open

fix(codex): route Claude system prompts to Responses API instructions#820
Shanlans wants to merge 1 commit into
kittors:devfrom
Shanlans:fix/codex-system-to-instructions

Conversation

@Shanlans

Copy link
Copy Markdown

Problem

When translating Claude requests to the Codex Responses API, the ChatGPT OAuth upstream rejects system/developer role messages inside the input array with:

System messages are not allowed

Two sources produced such messages:

  1. The top-level Claude system prompt was emitted as a role:"developer" message inside input, while the top-level instructions field was hard-coded to "".
  2. Any role:"system" message injected into the conversation (e.g. by Claude Code Agent Teams, CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1, which adds an "Available agent types…" system message) was passed through verbatim into input.

Both caused upstream 400 System messages are not allowed.

Fix

internal/translator/codex/claude/codex_claude_request.go:

  • Fold the top-level system field (array or string) into the top-level instructions string.
  • During message conversion, fold any system/developer role message's text into instructions as well, instead of emitting it into input.
  • Never emit system/developer roles into input.

Result envelope now looks like:

{ "model": "...", "instructions": "<system prompt>", "input": [ { "role": "user", ... } ] }

Tests

Added to codex_claude_request_test.go:

  • TestConvertClaudeRequestToCodex_SystemBecomesInstructions — top-level system → instructions, no system/developer in input.
  • TestConvertClaudeRequestToCodex_InConversationSystemMessageFolded — in-conversation role:"system" message folded into instructions, absent from input.

go test ./internal/translator/codex/claude passes.

Verified end-to-end against a live Codex (gpt-5.6-sol) route with Agent Teams enabled: previously 400 System messages are not allowed, now 200.

🤖 Generated with Claude Code

@Shanlans
Shanlans force-pushed the fix/codex-system-to-instructions branch from afb101e to 09f7204 Compare July 30, 2026 09:35
@Shanlans
Shanlans changed the base branch from main to dev August 12, 2026 02:28
The Codex ChatGPT OAuth upstream rejects system/developer role messages
inside the Responses API `input` array ("System messages are not
allowed"). The translator previously emitted the top-level Claude
`system` prompt as a `role:"developer"` input message and left
`instructions` empty, and it also passed through any `role:"system"`
messages injected into the conversation (e.g. by Claude Code Agent
Teams) verbatim into `input`.

Fold both the top-level `system` field and any in-conversation
system/developer messages into the top-level `instructions` string, and
never emit system/developer roles into `input`. Add tests covering both
paths.
@Shanlans
Shanlans force-pushed the fix/codex-system-to-instructions branch from 09f7204 to 3777057 Compare August 12, 2026 02:40
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.

1 participant