Duplicate system prompt sent for Codex GPT-5 sessions #5574

Closed
opened 2026-02-16 17:54:18 -05:00 by yindo · 0 comments
Owner

Originally created by @hannesrudolph on GitHub (Jan 13, 2026).

Originally assigned to: @thdxr on GitHub.

Summary

For Codex OAuth sessions using GPT-5, the same ~300-line prompt content is sent twice:

  1. In the instructions API parameter (from codex_header.txt)
  2. As the first user message (from codex.txt)

Evidence

The two files are effectively identical (only trailing whitespace differences):

$ diff packages/opencode/src/session/prompt/codex_header.txt packages/opencode/src/session/prompt/codex.txt
137c137
< - Use the \`edit\` tool to edit files
---
> - Use the \`edit\` tool to edit files 
191c191
< If the codebase has tests or the ability to build or run, consider using them to verify that your work is complete.
---
> If the codebase has tests or the ability to build or run, consider using them to verify that your work is complete. 

Code Path

  • codex_header.txt is loaded via PROMPT_CODEX_INSTRUCTIONS at packages/opencode/src/session/system.ts:17
  • codex.txt is loaded via PROMPT_CODEX at packages/opencode/src/session/system.ts:16

For Codex sessions (provider.id === "openai" && auth?.type === "oauth"):

  1. codex_header.txt → set as options.instructions at llm.ts:103
  2. codex.txt → included in the system array which becomes the first user message at llm.ts:191-197

Impact

Wasteful token usage—sending the same ~5K tokens twice per request.

Suggested Fix

Either:

  • Differentiate the files: codex_header.txt should be lightweight operational guidance, codex.txt the full prompt
  • Or skip one when both would be identical
  • Or clarify if this duplication is intentional (caching/prioritization reasons)
Originally created by @hannesrudolph on GitHub (Jan 13, 2026). Originally assigned to: @thdxr on GitHub. ## Summary For Codex OAuth sessions using GPT-5, the same ~300-line prompt content is sent twice: 1. In the `instructions` API parameter (from `codex_header.txt`) 2. As the first user message (from `codex.txt`) ## Evidence The two files are effectively identical (only trailing whitespace differences): ```bash $ diff packages/opencode/src/session/prompt/codex_header.txt packages/opencode/src/session/prompt/codex.txt 137c137 < - Use the \`edit\` tool to edit files --- > - Use the \`edit\` tool to edit files 191c191 < If the codebase has tests or the ability to build or run, consider using them to verify that your work is complete. --- > If the codebase has tests or the ability to build or run, consider using them to verify that your work is complete. ``` ## Code Path - `codex_header.txt` is loaded via `PROMPT_CODEX_INSTRUCTIONS` at `packages/opencode/src/session/system.ts:17` - `codex.txt` is loaded via `PROMPT_CODEX` at `packages/opencode/src/session/system.ts:16` For Codex sessions (`provider.id === "openai" && auth?.type === "oauth"`): 1. `codex_header.txt` → set as `options.instructions` at `llm.ts:103` 2. `codex.txt` → included in the system array which becomes the first user message at `llm.ts:191-197` ## Impact Wasteful token usage—sending the same ~5K tokens twice per request. ## Suggested Fix Either: - Differentiate the files: `codex_header.txt` should be lightweight operational guidance, `codex.txt` the full prompt - Or skip one when both would be identical - Or clarify if this duplication is intentional (caching/prioritization reasons)
yindo added the perf label 2026-02-16 17:54:18 -05:00
yindo closed this issue 2026-02-16 17:54:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5574