Codex ignores its system prompt after the first message
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:
- Always wrap changes between “ Begin Patch” and “ End Patch”.
- Specify the action (Add, Delete, Update, Rename) and the file path after the first marker line.
- Show only the minimal diff (- and + lines) needed for the fix.
- 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:
- Use the shell tool only from the commentary channel.
- Keep the command minimal and safe (e.g., don’t pipe to destructive commands).
- You can adjust flags (
-R,-n,--line-number, etc.) or switch torgif available for faster searches. - 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_
11 Comments
@bolinfest I think this is the commit that introduces the regression: https://github.com/openai/codex/commit/b323d10ea77c47b9fbf604cefd36355bb82981b2#diff-81c43c273518e6060612e02cf13bc1863785ee2316ce94ded66d624cf4621041L634-R692
@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?
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:
I observe the same issue with both rust and the TS implementation
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...
Also, looking at https://github.com/openai/codex/pull/642 (which introduced the
codex-rsfolder 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
@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!
Thanks for the fix!
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" />
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
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.
Thank you for the feedback! Please try again with the latest version of Codex CLI. If the issue persists, let us know.