These Codex prompts help you explore a codebase, fix bugs, add small features, refactor and review changes with OpenAI's coding agent. Copy one, swap the [brackets] for your details and paste it into Codex. OpenAI's own advice is to give every prompt a goal, context, constraints and a clear "done when" finish line.
Codex is OpenAI's coding agent. You don't just ask it a question and copy the answer: it reads your files, makes changes, runs commands and hands back a diff for you to check. That's brilliant for a small business owner who keeps a website, a booking script or a spreadsheet tool going without a developer on call.
Because it acts on your code, how you brief it matters more than with a chatbot. OpenAI's own guidance says a good Codex prompt covers four things: the goal, the context, the constraints and what "done" looks like. Every prompt below follows that shape. Swap the [brackets] for your details, review every change before you merge it, run your tests, and never paste passwords, secrets or API keys into a prompt.
Codex prompts for getting to know a codebase
Start here if you've inherited a project or you're coming back to something you built ages ago. These prompts ask Codex to read and explain, not edit.
Plain-English tour of a repo
Copy this prompt
Read this repository and explain in plain English what it does, how the main folders fit together and where [feature, for example the contact form] lives. Don't change any files.
Map the request path
Copy this prompt
Trace what happens when a visitor submits [form or page] on this site, from the first file that handles it to where the data ends up. List each file with one sentence on its role.
Spot the risky corners
Copy this prompt
Look through [folder] and list the parts most likely to break if I change [thing I want to change]. For each, say why and what I should test. Read only, no edits.
Draft an AGENTS.md for this project
Copy this prompt
Suggest a short AGENTS.md for this repo: how to install, how to run tests, code style we follow, folders to avoid touching. Keep it brief and only include what you can confirm from the files.
Codex prompts for fixing bugs
OpenAI's docs say repro steps and constraints matter more than a high-level description, so these prompts lead with exactly how to make the bug happen.
Bug with clear repro steps
Copy this prompt
Bug: when I [steps to reproduce], I see [what happens] instead of [what should happen]. Find the cause, fix it with the smallest change possible, then re-run the repro steps and tell me the result.
Error message hunt
Copy this prompt
I get this error when running [command]: [paste the error, with any keys or passwords removed]. Explain what's causing it, propose a fix, apply it, and show me the commands you ran to check.
Only on mobile
Copy this prompt
On phones narrower than a tablet, [element] on [page] overlaps the text below it. Fix the layout for small screens without changing how it looks on desktop. Tell me which styles you changed.
Broken after an update
Copy this prompt
Since updating [library or plugin], [feature] has stopped working. Compare how the code uses it with what the new version expects, fix the mismatch, and list anything else that might be affected.
Flaky test
Copy this prompt
The test [test name] passes sometimes and fails other times. Work out why it's unreliable, fix the root cause rather than adding retries, and run it several times to show it now passes consistently.
Codex prompts for adding small features
Keep each task small and give Codex a finish line. "Done when" is OpenAI's own phrase, and it stops the agent wandering off into changes you didn't ask for.
Add a field to a form
Copy this prompt
Add a [phone number] field to the contact form in [file]. Make it optional, validate the format, include it in the notification the form already sends, and follow the existing style. Done when the form test passes.
Simple export button
Copy this prompt
Add a button to [admin page] that exports the current list of [bookings or orders] as a CSV file. Reuse existing helpers where possible. Done when I can click it locally and open the file.
Friendly empty state
Copy this prompt
When [list or page] has no items, show a short friendly message and a link to [next action] instead of a blank space. Match the existing design and add a test for the empty case.
Plan first, then build
Copy this prompt
Want AI doing the heavy lifting in your marketing?
I build the systems that handle the boring 80 percent, so you get your week back. Done properly, with the human kept in.
I want to add [feature]. Before editing anything, investigate the code and propose a step-by-step plan with the files you'd change. Wait for my go-ahead before making changes.
Codex prompts for tidying and refactoring code
Refactors are where an agent can quietly change behaviour. Each prompt here says the behaviour must stay the same and asks Codex to prove it.
Split a giant file
Copy this prompt
[File] has grown too long. Split it into smaller, clearly named modules without changing what it does. Keep the public functions the same and run the full test suite afterwards.
Remove dead code safely
Copy this prompt
Find functions, styles and files in [folder] that nothing uses any more. List them with your evidence first, then remove only the ones I confirm.
Consistent naming
Copy this prompt
Rename the variables and functions in [file] so they follow the naming style used in the rest of the project. No behaviour changes. Show me a summary of each rename.
Replace copy-pasted logic
Copy this prompt
The same [date formatting or validation] logic appears in several places. Move it into one shared helper, update every caller, and run the tests to confirm nothing changed.
Codex prompts for tests, reviews and safety checks
OpenAI says Codex can help you test, check and review code, not just write it. These are the prompts I'd run before anything goes live.
Write the missing tests
Copy this prompt
Add tests for [function or feature] covering the normal case, an empty input and one obvious mistake a user might make. Follow the existing test style and report the results.
Review my uncommitted changes
Copy this prompt
Review my uncommitted changes as a careful senior developer would. Look for bugs, regressions, missing tests and anything confusing. List issues by severity and don't edit files yet.
Check for exposed secrets
Copy this prompt
Search this repository for anything that looks like a password, token or API key committed to the code. List the files and lines, but don't print the values themselves.
Accessibility pass on a page
Copy this prompt
Check [page or template] for basic accessibility problems: missing alt text, low colour contrast, unlabelled form fields and keyboard traps. Suggest fixes, apply the simple ones and list the rest.
Lint and smallest test run
Copy this prompt
Run the linter and the smallest relevant test suite for the files you changed. Report the exact commands and results, fix any failures you caused, and stop if something unrelated is broken.
How to get better results from Codex prompts
- Use OpenAI's four-part shape: goal, context, constraints and done when. If a prompt is missing one, that's usually where the result goes wrong.
- Point to the files. In the IDE extension your open files are included as context; in the command line, name the file paths so Codex isn't guessing.
- Ask for a plan on anything multi-step. OpenAI's docs mention /plan, which has Codex investigate and propose an approach before editing.
- Keep an AGENTS.md in your repo. OpenAI calls it a README for agents that loads automatically, so your house rules travel with every task. Keep it short and add a rule when the same mistake happens twice.
- Review the diff yourself and run the tests before you merge. The /review command can help, but you're the one shipping it.
- Never paste passwords, tokens or API keys into a prompt, and remove them from error messages before you share those too.
If you also use ChatGPT for the writing side of your business, my collection of everyday ChatGPT prompts covers the non-code jobs. And if you write specs for developers or agents, these prompts for product managers will help you turn a vague idea into a clear brief before you hand it to Codex.
Related guides live in the ChatGPT Prompts and Limits: 30 Guides to Fun Prompts, Photo Edits and Daily Caps. To write your own, try the free tool that writes the prompt for you.
Frequently asked questions
What is OpenAI Codex?
Codex is OpenAI's coding agent. It can read your code, make changes, run commands and help you test and review the result, from an IDE extension, the command line or the cloud.
What should a Codex prompt include?
OpenAI suggests four parts: the goal, the context (which files or errors matter), the constraints (standards or conventions to follow) and a done-when condition such as tests passing.
Is it safe to let Codex change my code?
OpenAI says local commands run in a sandbox that limits file and network access, and cloud tasks run in isolated environments. You should still review every change and run your tests before merging.
What is AGENTS.md?
It's a short file in your repository that tells coding agents how your project works. OpenAI says it loads into context automatically, so you don't have to repeat your rules in every prompt.
Can I paste error messages into Codex?
Yes, error messages are useful context. Just remove any passwords, tokens or API keys first, and never share secrets in a prompt.


