Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(openai-codex): apply filterIdentity to the Codex instructions field
Jack Rudenko54ed3f5e3af9
diff --git a/packages/cli/src/adapters/codex-api-format.ts b/packages/cli/src/adapters/codex-api-format.tsindex 0036f55e..79f5773a 100644--- a/packages/cli/src/adapters/codex-api-format.ts+++ b/packages/cli/src/adapters/codex-api-format.ts@@ -12,6 +12,7 @@*/import { mapToolChoiceToResponsesAPI } from "../handlers/shared/format/openai-tools.js";+import { filterIdentity } from "../handlers/shared/openai-compat.js";import { log } from "../logger.js";import type { StreamFormat } from "../providers/transport/types.js";import { type AdapterResult, BaseAPIFormat } from "./base-api-format.js";@@ -103,8 +104,21 @@ export class CodexAPIFormat extends BaseAPIFormat {...(this.codexExtras ? { store: false, include: ["reasoning.encrypted_content"] } : {}),};+ // Flattened (a block array joined with "\n\n", as the Chat Completions+ // converter does) and identity-filtered, as Gemini filters its system+ // instruction. Sent raw before, the field carried Claude Code's "You are+ // Claude Code, Anthropic's official CLI" identity to a non-Claude model;+ // the filtered system message convertMessages builds never reaches the+ // Responses payload (convertMessagesToResponsesAPI skips it).if (claudeRequest.system) {- payload.instructions = claudeRequest.system;+ const system = Array.isArray(claudeRequest.system)+ ? claudeRequest.system+ .map((block: { text?: string } | string) =>+ typeof block === "string" ? block : block.text || ""+ )+ .join("\n\n")+ : claudeRequest.system;+ payload.instructions = filterIdentity(system);}if (tools.length > 0) {diff --git a/packages/cli/src/behavior/middleware-payload.test.ts b/packages/cli/src/behavior/middleware-payload.test.tsindex c196c443..42ff3982 100644--- a/packages/cli/src/behavior/middleware-payload.test.ts+++ b/packages/cli/src/behavior/middleware-payload.test.ts@@ -52,6 +52,8 @@ describe("middleware mutations before adapter.buildPayload", () => {expect(serialized).toContain(MESSAGE_MARKER);expect(serialized).toContain(TOOL_MARKER);- expect(serialized).toContain(`"instructions":"${SYSTEM_MARKER}"`);+ const payload = JSON.parse(serialized);+ expect(payload.instructions).toContain(SYSTEM_MARKER);+ expect(payload.instructions).not.toBe(SYSTEM_MARKER);});});