Branchwell

Become a Pro / website · becomeapro.ai / content / lessons / knowledge-work / using-ai / codex-best-practices.mdx

Raw 6.2 KB on 807b8657974875ed44f307014cfbf8ce673dc5a6
1---
2title: "Codex best practices"
3description: "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."
4level: Beginner
5minutes: 7
6updated: 2026-12-03
7order: 5
8sources:
9 - https://learn.chatgpt.com/guides/best-practices
10 - https://learn.chatgpt.com/docs
11 - https://learn.chatgpt.com/docs/codex/cli
12 - https://learn.chatgpt.com/docs/codex/ide
13 - https://learn.chatgpt.com/docs/cloud
14 - https://learn.chatgpt.com/docs/agent-configuration/agents-md
15 - https://learn.chatgpt.com/docs/config-file/config-basic
16 - https://learn.chatgpt.com/docs/agent-approvals-security
17 - https://learn.chatgpt.com/docs/build-skills
18 - https://learn.chatgpt.com/docs/extend/mcp
19 - https://learn.chatgpt.com/docs/changelog
20 - https://developers.openai.com/blog/topic/codex
21 - https://developers.openai.com/cookbook/topic/codex
22 - https://openai.com/academy/codex/
23 - https://academy.openai.com/public/clubs/builders-etkn1/videos/codex-for-software-engineers-2026-03-13
24 - https://learn.chatgpt.com/videos
25 - https://developers.openai.com/learn/codex
26---
27
28Codex 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.
29
30<Diagram caption="A good Codex prompt has four parts. Done-when is the one people skip.">
31 <svg viewBox="0 0 600 200" role="img" aria-label="Four boxes in a row labeled goal, context, constraints and done when, joined by arrows">
32 <rect x="15" y="50" width="125" height="70" rx="10" fill="none" stroke="currentColor" strokeWidth="2" />
33 <text x="77" y="91" fontSize="16" textAnchor="middle" fill="currentColor">Goal</text>
34 <rect x="165" y="50" width="125" height="70" rx="10" fill="none" stroke="currentColor" strokeWidth="2" />
35 <text x="227" y="91" fontSize="16" textAnchor="middle" fill="currentColor">Context</text>
36 <rect x="315" y="50" width="125" height="70" rx="10" fill="none" stroke="currentColor" strokeWidth="2" />
37 <text x="377" y="91" fontSize="16" textAnchor="middle" fill="currentColor">Constraints</text>
38 <rect x="465" y="50" width="125" height="70" rx="10" className="soft" stroke="currentColor" strokeWidth="2" />
39 <text x="527" y="91" fontSize="16" textAnchor="middle" fill="currentColor">Done when</text>
40 <line x1="140" y1="85" x2="163" y2="85" stroke="currentColor" strokeWidth="2" />
41 <line x1="290" y1="85" x2="313" y2="85" stroke="currentColor" strokeWidth="2" />
42 <line x1="440" y1="85" x2="463" y2="85" stroke="currentColor" strokeWidth="2" />
43 <text x="300" y="165" fontSize="15" textAnchor="middle" fill="currentColor">What to change, what to read, what rules apply, how we'll know</text>
44 </svg>
45</Diagram>
46
47## Write prompts with four parts
48
49Every task prompt should cover:
50
51- **Goal:** what to change or build.
52- **Context:** the files, docs or error messages that matter. Paste the stack trace instead of describing it.
53- **Constraints:** the standards and conventions to follow, and what to leave alone.
54- **Done when:** what must be true at the end, such as a named test passing.
55
56Here is one filled in:
57
58```prompt
59Goal: Fix the CSV export so dates use the customer's time zone.
60Context: The export lives in src/export/csv.ts. The bug report says Tokyo customers see yesterday's date.
61Constraints: Don't change the public API. Follow the existing date helpers in src/lib/dates.ts.
62Done when: A new test for a Tokyo customer passes and npm test passes.
63```
64
65Match 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.
66
67## Plan before hard tasks
68
69For 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.
70
71## Keep AGENTS.md short and useful
72
73`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:
74
75- How to build, test and lint
76- The conventions and the "never do this" rules
77- What "done" means in this repo
78
79Keep 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.
80
81## Let it check its own work
82
83Ask 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.
84
85Start with the default approval and sandbox settings. Loosen them only for repos you trust or for a specific workflow you have tested.
86
87## Keep chats focused
88
89Use 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.
90
91- `/fork` splits a chat only when the work really splits in two.
92- `/resume` returns to a saved chat.
93- `/compact` summarizes a long chat so it takes less context.
94
95## Turn repeated prompts into skills
96
97When 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.
98
99Only 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.
100
101## Practice checklist
102
103- [ ] Write your next task prompt with all four parts
104- [ ] Use `/plan` once on a task you'd normally just start
105- [ ] Run `/init` and trim the result to the lines Codex needs
106- [ ] End every task with tests plus `/review`
107- [ ] Start a fresh chat for each new piece of work