Codex ignores its system prompt after the first message

Resolved 💬 11 comments Opened May 12, 2025 by arnaudstiegler Closed Aug 7, 2025
💡 Likely answer: A maintainer (bolinfest, collaborator) responded on this thread — see the highlighted reply below.

What version of Codex is running?

0.1.2504301751

Which model were you using?

o3

What platform is your computer?

Darwin 24.4.0 arm64 arm

What steps can reproduce the bug?

`
╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2504301751 │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: db26dfe84d514d62bbafaa469d78c4a5 │
│ ↳ workdir: ~/atlas-act-cli │
│ ↳ model: o3 │
│ ↳ provider: openai │
│ ↳ approval: suggest │
╰──────────────────────────────────────────────────────────────╯
user
As per your dev guidelines, how should you edit files?

codex
According to the developer guidelines, any time you need to change or add code you should:

• Perform the edit with an apply_patch tool call, for example:

{
"cmd": ["apply_patch", " Begin Patch\n Update File: path/to/file.py\n@@\n- old line\n+ new line\n*** End Patch"]
}

Key points:

  1. Always wrap changes between “ Begin Patch” and “ End Patch”.
  2. Specify the action (Add, Delete, Update, Rename) and the file path after the first marker line.
  3. Show only the minimal diff (- and + lines) needed for the fix.
  4. Let the system save the file; do not instruct the user to copy/paste it.

Using apply_patch keeps a clean git history and allows the sandbox to track and test your changes automatically.
user
What about grep?

codex
To search the repository you can invoke the shell tool with a grep (or ripgrep / rg) command. A typical pattern looks like this (remember: the function call itself must appear in the commentary channel, never the analysis
channel).

Example:

{"name": "shell",
"arguments": {
"command": ["grep", "-R", "-n", "search_term", "."]
}}

Guideline reminders:

  1. Use the shell tool only from the commentary channel.
  2. Keep the command minimal and safe (e.g., don’t pipe to destructive commands).
  3. You can adjust flags (-R, -n, --line-number, etc.) or switch to rg if available for faster searches.
  4. The tool returns the command’s stdout/stderr so you can inspect results and decide what to do next.

`

What is the expected behavior?

_No response_

What do you see instead?

The system prompt clearly outlines that grep should not be used and only ripgrep should be used. Codex will answer correctly the question "Is grep allowed?" if it's the first message, but not for any subsequent message

Additional information

_No response_

View original on GitHub ↗

11 Comments

bolinfest collaborator · 1 year ago

@arnaudstiegler Based on what you pasted in the PR, I believe you are using the default version of the CLI, which is in TypeScript.

The PR that you linked to is purely a Rust change, so I do not believe it could be related to this. How did you make that connection?

arnaudstiegler · 1 year ago

You're right! I did observe the same behavior on the rust side, and I thought the reason was the change on the instruction logic:

  let instructions = if is_first_turn {
      sess.instructions.clone()
  } else {
      None
  };

I observe the same issue with both rust and the TS implementation

bolinfest collaborator · 1 year ago

Looking at agent-loop.ts, it appears that the full instructions are always sent:

https://github.com/openai/codex/blob/55142e3e6caddd1e613b71bcb89385ce5cc708bf/codex-cli/src/utils/agent/agent-loop.ts#L730

https://github.com/openai/codex/blob/55142e3e6caddd1e613b71bcb89385ce5cc708bf/codex-cli/src/utils/agent/agent-loop.ts#L1112

so I think this is a mistake in the Rust code, though given that they are sent for every turn in the TypeScript, I'm surprised you're seeing this issue there...

bolinfest collaborator · 1 year ago

Also, looking at https://github.com/openai/codex/pull/642 (which introduced the codex-rs folder to the repo), I think this issue with the instructions only being sent on the first turn in the Rust version has been present since the initial import:

https://github.com/openai/codex/blob/31d0d7a305305ad557035a2edcab60b6be5018d8/codex-rs/core/src/codex.rs#L634-L637

bolinfest collaborator · 1 year ago

@arnaudstiegler if nothing else, this alerted me to a serious Rust issue, now fixed in https://github.com/openai/codex/pull/908, so thanks for that!

arnaudstiegler · 1 year ago

Thanks for the fix!

arnaudstiegler · 1 year ago

Looks like the issue is solved for the rust implementation, but the typescript implementation still has the same symptom (forgets system prompt after the first message). See screenshot (ran on latest main commit):

<img width="1327" alt="Image" src="https://github.com/user-attachments/assets/dd958a77-ec59-4498-8b50-72b27d7b5dd6" />

<img width="1362" alt="Image" src="https://github.com/user-attachments/assets/6a8d1137-cb45-4ffc-9662-a58fef9afc03" />

adriannieto-at-fortris · 1 year ago

We have the same issue here with typescript version, codex suggests a change, explains how is going to achieve it but never actually applies into the filesystem

bolinfest collaborator · 1 year ago

Given that we are changing our focus on the Rust version, I would encourage you to give it a shot (though I know there are still some features missing: I'm working on creating one large GitHub issue to track all of the individual issues): https://github.com/openai/codex/discussions/1174.

codex-maintainers · 11 months ago

Thank you for the feedback! Please try again with the latest version of Codex CLI. If the issue persists, let us know.