--- title: "Codex best practices" description: "How to get good work out of OpenAI Codex: four-part prompts, plan mode, a short AGENTS.md, self-checks with /review, focused chats and skills." level: Beginner minutes: 7 updated: 2026-12-03 order: 5 sources: - https://learn.chatgpt.com/guides/best-practices - https://learn.chatgpt.com/docs - https://learn.chatgpt.com/docs/codex/cli - https://learn.chatgpt.com/docs/codex/ide - https://learn.chatgpt.com/docs/cloud - https://learn.chatgpt.com/docs/agent-configuration/agents-md - https://learn.chatgpt.com/docs/config-file/config-basic - https://learn.chatgpt.com/docs/agent-approvals-security - https://learn.chatgpt.com/docs/build-skills - https://learn.chatgpt.com/docs/extend/mcp - https://learn.chatgpt.com/docs/changelog - https://developers.openai.com/blog/topic/codex - https://developers.openai.com/cookbook/topic/codex - https://openai.com/academy/codex/ - https://academy.openai.com/public/clubs/builders-etkn1/videos/codex-for-software-engineers-2026-03-13 - https://learn.chatgpt.com/videos - https://developers.openai.com/learn/codex --- Codex is OpenAI's coding agent. It runs in your terminal as the Codex CLI, inside your code editor, in the desktop app and as cloud tasks. OpenAI's best-practices guide asks you to treat it less like a one-off assistant and more like a teammate you set up once and improve over time. This lesson puts that guide into plain steps. Goal Context Constraints Done when What to change, what to read, what rules apply, how we'll know ## Write prompts with four parts Every task prompt should cover: - **Goal:** what to change or build. - **Context:** the files, docs or error messages that matter. Paste the stack trace instead of describing it. - **Constraints:** the standards and conventions to follow, and what to leave alone. - **Done when:** what must be true at the end, such as a named test passing. Here is one filled in: ```prompt Goal: Fix the CSV export so dates use the customer's time zone. Context: The export lives in src/export/csv.ts. The bug report says Tokyo customers see yesterday's date. Constraints: Don't change the public API. Follow the existing date helpers in src/lib/dates.ts. Done when: A new test for a Tokyo customer passes and npm test passes. ``` Match the reasoning effort to the job. Use low effort for small, well-scoped tasks, medium or high for complex changes and debugging, and the highest setting for long, reasoning-heavy work. ## Plan before hard tasks For anything complex or fuzzy, switch on plan mode with `/plan` or `Shift`+`Tab`. Codex reads the code and proposes a plan before it edits anything, so you can correct the approach while it is still cheap. You can also ask Codex to interview you about the idea first. For long, multi-step work, OpenAI suggests keeping an execution plan in a `PLANS.md` file that Codex updates as it goes. ## Keep AGENTS.md short and useful `AGENTS.md` is a README for agents. Codex loads it automatically before it starts work. Run `/init` to scaffold one, then edit it to cover: - How to build, test and lint - The conventions and the "never do this" rules - What "done" means in this repo Keep it short. When Codex makes the same mistake twice, add a line. Our [AGENTS.md guide](/knowledge-work/using-ai/agents-md-codex) covers where the files go and how Codex combines them. ## Let it check its own work Ask Codex to write or update tests and run the checks before it says it is finished. Then run `/review`, which reviews the changes against your main line of work, your uncommitted changes, a specific commit or your own instructions. Read the diff yourself before you accept it. Start with the default approval and sandbox settings. Loosen them only for repos you trust or for a specific workflow you have tested. ## Keep chats focused Use one chat per piece of work, not one chat for the whole project. A chat that runs for days fills up with old context and gets worse over time. - `/fork` splits a chat only when the work really splits in two. - `/resume` returns to a saved chat. - `/compact` summarizes a long chat so it takes less context. ## Turn repeated prompts into skills When you type the same instructions again and again, package them as a skill: a folder with a `SKILL.md` file that says what the skill does and when to use it. Keep each skill to one job. Personal skills go in `~/.agents/skills`, and team skills can live in `.agents/skills` inside the repo. Codex's built-in `$skill-creator` skill can scaffold one for you. Only schedule a task to run on its own, from the desktop app's Scheduled page, after it works reliably when you run it by hand. ## Practice checklist - [ ] Write your next task prompt with all four parts - [ ] Use `/plan` once on a task you'd normally just start - [ ] Run `/init` and trim the result to the lines Codex needs - [ ] End every task with tests plus `/review` - [ ] Start a fresh chat for each new piece of work