You’re Prompting Codex Wrong: OpenAI’s Official Guide to Better Coding Agents
You ask Codex to fix the login bug, and it returns a fluent patch that solves a different problem than the one you meant. What does a prompt need so Codex knows when the fix is done?

“Fix the login bug” sounds actionable, but it leaves out how to reproduce the bug, which code may change, which behavior must stay compatible and which tests must pass. Codex has to guess those requirements before editing. The resulting patch may look correct while solving the wrong problem.
OpenAI’s guidance is to give Codex a clearly scoped job and a way to demonstrate that it is finished. A concise engineering ticket with acceptance criteria gives the agent the requirements it needs to implement and verify the change.
Tell Codex what to change and how to verify it
A chatbot can finish when it produces an answer. Codex inspects files, runs tools, edits code, observes results and fixes failures. Its prompt therefore needs to describe the repository change and the evidence that will show it worked.
Let Codex inspect existing patterns and choose how to implement the change. Specify the product behavior, limits on what may change and acceptance criteria that it cannot infer from the repository.
- Outcome: the observable change users should see
- Scope: what may change and what must remain stable
- Evidence: tests, builds, screenshots or benchmarks
- Stop condition: what to report when permission or information is missing
The seven parts of a reliable Codex prompt
Start with an observable result. “Keep the save button visible at 320px without changing the desktop layout” gives Codex a more precise target than “improve settings.” Add the steps to reproduce the problem, the area it may change and the existing behavior it must preserve.
The remaining three parts are how to investigate the repository, how to verify the result and what to report when finished. A one-line change does not need seven headings. Include the decisions that would be costly for Codex to guess incorrectly.
- Read relevant code and existing tests before editing
- Preserve unrelated user changes when the working tree already contains edits
- Run tests appropriate to the change and investigate failures
- Report what changed, the verification results and any remaining risks
Turn a vague request into an executable brief
“Search is slow; optimize it and keep going” gives Codex neither a performance target nor requirements for preserving correct results. It could serve stale cached data or return fewer results and still report a speed improvement.
Name the performance threshold and benchmark, specify the API behavior that must remain unchanged and limit the files that may be edited. Codex can then choose experiments while you retain a clear way to judge completion.
Outcome: reduce product-search API p95 below 350 ms.
Scope: change only the search service and related tests; preserve the public response schema.
Explore: reproduce the benchmark and identify the bottleneck before editing.
Verify: run npm run benchmark:search and the related integration suite.
Report: explain the change, before/after numbers, tests run and remaining risks. Specify when Codex should search and run tests
Replace “search if needed” with “check official documentation before making claims about API behavior that may vary by version.” Replace “test it” with “run the changed package’s tests, then run the full type check if a shared type changed.” Each instruction states which action to take and when to take it.
Also define which actions Codex may take on its own. It may freely repeat a local test suite that uses disposable fixtures, while deployment, changes to production data and billable external calls require explicit authorization. A request to keep working does not grant permission for every available action.
Remove outdated instructions when upgrading models
OpenAI recommends reviewing accumulated planning instructions, repeated checklists and precautionary rules when moving to newer Codex models. Older instructions may conflict: one tells the agent to implement immediately while another requires plan approval every time.
Put the current deliverable in the task prompt, repository-wide rules in AGENTS.md, reusable procedures in Skills and an objective that persists across turns in a Goal. Each has a distinct role in the six-guide series.
A reusable Codex task template
Use the parts of this template that the task needs. A small edit may need only the outcome and verification instructions. For work with greater risks, add reproduction steps, explicit limits and a final report of the evidence.
Replace “works correctly” with something you can inspect: a named test, a URL, a screenshot at a specified viewport or a performance threshold. These give you a way to assess the result beyond Codex’s written claim that it succeeded.
[Outcome]
Describe the final observable behavior.
[Context / reproduction]
State the current behavior, error and relevant path.
[Scope / constraints]
Name allowed areas and behavior that must not regress.
[Workflow]
Inspect relevant code first, follow existing patterns, implement and test.
[Verification]
List tests, builds, benchmarks or manual checks.
[Final report]
Summarize changes, evidence and remaining risk. Use prompts for tasks, AGENTS.md for repository rules, Skills for procedures and Goals for objectives that span turns
Subagents handle independent parts of a task; MCP connects external tools and information. Giving each a distinct role keeps instructions shorter and execution more predictable.
Frequently asked questions
Are longer Codex prompts better?
No. Clear requirements and evidence of completion matter more than length. Copying information Codex can inspect in the repository can bury the actual constraints.
Should every prompt demand a plan first?
No. Plans help with complex work, but requiring plan approval can slow down small changes. Adjust the instructions to the current model’s guide and the risks of the task.
How is AGENTS.md different from a prompt?
A prompt defines the current deliverable. AGENTS.md contains repository rules that apply across tasks. Skills contain reusable procedures, while Goals maintain a completion objective across turns.
How do I make Codex run tests?
Specify which test command to run after each kind of change and what Codex should report if it cannot run that command.