Skip to content

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

@hannesrudolph

Description

@hannesrudolph

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)

Metadata

Metadata

Assignees

Labels

perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions