Agentic Code Generation with OpenAI Codex CLI
A step-by-step walkthrough of using OpenAI’s agentic coding tool to scaffold, solve, test, and visualise the classic Knight’s Tour chess problem — entirely through natural language prompts.
This post assumes you have Codex CLI installed and authenticated. If not, check out the previous post in this series for setup instructions. We’ll be working in three phases, each driven by a carefully crafted Codex prompt.
💡 Why prompt Codex to write AGENTS.md instead of writing it yourself? Two reasons. First, you describe your intent conversationally rather than worrying about format. Second, it sets the right mental model for the rest of the guide — Codex writes the files, you review the diffs.
You can also update it at any time: “Add a rule that all functions must have docstrings” or “Update AGENTS.md to say we’re now using FastAPI instead of Flask” — Codex will edit the file in place and show you the diff.
💡 Approval Flow: In Codex’s default Auto mode, you’ll see a diff for each file before it’s written. Press A to accept or R to reject. If Codex proposes something you don’t want, reject it and follow up with a corrective prompt — it retains full context.
📁 Final Project Structure
knights-tour/
├── AGENTS.md
├── .gitignore
├── requirements.txt ← flask
├── knight_tour.py ← solver + display logic
├── main.py ← CLI entry point
├── app.py ← Flask web app
└── tests/
└── test_knight_tour.py
What’s worth noticing in this walkthrough is the workflow rhythm: each Codex prompt builds on the last without re-explaining context, and the AGENTS.md file silently enforces project conventions so you don’t have to. The three phases took roughly 15 minutes end-to-end, most of which was reviewing diffs and running tests rather than writing code.
The Knight’s Tour is just the illustration. The same prompt-iterate-commit loop applies to any project — and the more you invest in a good AGENTS.md upfront, the more useful each Codex session becomes.