Codecademy Logo

Introduction to Codex CLI and AI-Assisted Development

Related learning

  • Learn to build maintainable projects with AI using Codex CLI in this course on agentic coding, specs, TDD, and context engineering.
    • With Certificate
    • Beginner Friendly.
      3 hours
  • Learn Python programming with AI tools. This course takes you from fundamentals to best practices using Codex CLI for serious development.
    • Includes 4 Courses
    • With Certificate
    • Beginner Friendly.
      9 hours

Starting Codex CLI

We begin a Codex CLI session by entering codex in our terminal. The CLI automatically detects the project structure and initiates an interactive dialogue.

Persistent Preferences in Codex

Codex CLI reads AGENTS.md from the project root at the start of every session, making our preferences and instructions persistent across conversations. The file can hold coding style, project conventions, and commands Codex should know about, such as how to run tests. Keeping it in the project root means every session starts already calibrated, with no need to re-explain how we work.

# AGENTS.md
## Conventions
- Use descriptive variable names.
## Commands
- Run tests with `pytest`.

Initialize With /init

We can generate a starter AGENTS.md with /init, which analyzes the project and produces a first draft to refine. The /status command confirms which configuration files Codex CLI has loaded for the session. Together, /init gets the configuration started and /status verifies Codex is actually picking it up.

File References in Prompts

In a prompt, we use @ to point Codex at a specific file — for example, @spec.md — so it works from exact context instead of searching the whole project. The ! prefix runs a shell command inline, like !node --test, executing it directly without routing the request through Codex. Together they let us control both the context Codex sees and the commands we run, right from the prompt.

Review @spec.md and tell me what is missing.
! node --test

Next in Codex Workflow

A “next” workflow captured in AGENTS.md tells Codex to find the first unchecked item in our spec file, implement just that item, and mark it complete. Because the steps live in AGENTS.md, we can move through an entire feature list with a single instruction instead of re-explaining the process each session. The spec says what to build; the workflow says how to step through it.

## Next Task Workflow
When I say "do the next task":
1. Read `spec.md`.
2. Find the first unchecked item.
3. Implement only that item.
4. Mark it complete in `spec.md`.
5. Stop for review.

Interview Technique in Codex

With the interview technique, we ask Codex to question us before it generates any code or spec. Those answers let it tailor the output to our experience level, preferences, and the project’s actual requirements, rather than guessing. It’s especially useful for turning a vague idea into concrete requirements, since the questions surface details we might not have thought to specify.

Ask me questions about the utility we are building.
After I answer, turn my answers into a spec.md checklist.

Codex CLI Overview

Codex CLI is a terminal-based AI coding agent that works directly in our environment. Rather than just returning suggestions to copy-paste, it reads our project files and runs commands on our behalf, taking concrete action in the workspace. Thinking of it as a pair programmer in the terminal, rather than a chatbot, captures how it’s meant to be used.

Learn more on Codecademy

  • Learn to build maintainable projects with AI using Codex CLI in this course on agentic coding, specs, TDD, and context engineering.
    • With Certificate
    • Beginner Friendly.
      3 hours
  • Learn Python programming with AI tools. This course takes you from fundamentals to best practices using Codex CLI for serious development.
    • Includes 4 Courses
    • With Certificate
    • Beginner Friendly.
      9 hours