Getting Started with Codex CLI
Learning Outcomes
- Launch Codex CLI from your terminal and start an interactive session
- Explain how Codex CLI differs from ChatGPT and other web-based AI tools
- Understand the approval flow and how to accept, reject, or modify suggestions
- Execute a basic task end-to-end using natural language instructions
- Navigate the Codex CLI interface including status indicators and output panels
Lesson Plan
| Segment | Duration | Topic |
|---|---|---|
| Intro | 3 min | What is Codex CLI, why use a terminal-based AI tool |
| Explain | 5 min | Codex CLI vs ChatGPT — key architectural differences |
| Demo 1 | 7 min | First launch, exploring the interface |
| Demo 2 | 6 min | Running a simple task with approval flow |
| Explain | 4 min | Understanding outputs — diffs, commands, and results |
| Demo 3 | 3 min | Rejecting and modifying suggestions |
| Wrap-up | 2 min | Key takeaways and next lesson preview |
Before You Begin
Pre-work:
- Complete the Installation guide
- Ensure you're authenticated (ChatGPT sign-in or API key configured)
- Have a terminal open in a test project directory
Shopping List:
- Codex CLI installed (
codexcommand available in your terminal) - Authentication configured (via
codex auth loginorCODEX_API_KEY) - A test project folder with a few files to work with
- Basic familiarity with the command line
Codex CLI is OpenAI's open-source command-line coding agent. Unlike ChatGPT (which runs in a browser), Codex CLI operates directly in your terminal with full access to your local file system. It can read your code, write files, and execute shell commands — all under your supervision.
Key characteristics:
| Feature | ChatGPT | Codex CLI |
|---|---|---|
| Interface | Web browser | Terminal |
| File access | Upload only | Direct local file system |
| Code execution | Sandboxed remote | Local machine (sandboxed) |
| Context | Conversation only | Your entire project directory |
| Workflow | Copy-paste code | Direct file editing |
| Open source | No | Yes (Apache 2.0) |
Why use a terminal-based AI tool?
- Zero context-switching — stay in your terminal workflow
- Full project awareness — Codex sees your entire codebase
- Direct execution — changes are applied to your real files
- Version control integration — works alongside git naturally
- Scriptable — can be integrated into automated pipelines
- Multi-provider support — works with OpenAI models and compatible APIs
Let's start Codex CLI for the first time. Open your terminal and navigate to a project directory.
# Navigate to your project
cd ~/projects/my-test-project
# Launch Codex CLI in interactive mode
codex
You should see the Codex CLI interface appear in your terminal with a prompt waiting for your input.
# Navigate to your project
cd ~/projects/my-test-project
# Launch Codex CLI in interactive mode
codex
You should see the Codex CLI interface appear in your terminal with a prompt waiting for your input.
What you see on launch:
The Codex CLI interface displays:
- Model indicator — which AI model is being used (default:
gpt-5.5) - Working directory — confirms the folder Codex is operating in
- Approval policy — shows the current safety level (default:
untrusted) - Input prompt — where you type your natural language instructions
Your first interaction:
Type a simple request to see Codex in action:
> List all files in this project and describe the structure
Codex will analyze your directory and provide a summary without making any changes. This is a read-only operation, so no approval is needed.
The approval flow is the core safety mechanism in Codex CLI. When Codex wants to make a change (edit a file, run a command), it shows you exactly what it plans to do and waits for your approval.
The approval cycle:
- You give Codex an instruction
- Codex proposes an action (file edit or shell command)
- You see a preview of the proposed change
- You choose: approve, reject, or edit
Try it — ask Codex to create a file:
> Create a file called hello.py that prints "Hello from Codex"
Codex will show you the proposed file content:
╭─ Creating file: hello.py ─────────────────────╮
│ │
│ print("Hello from Codex") │
│ │
╰────────────────────────────────────────────────╯
[a]pprove [r]eject [e]dit
Your options:
a(approve) — Codex creates the file exactly as shownr(reject) — Codex discards the proposal and you can give new instructionse(edit) — You can modify the proposed content before approving
Understanding the diff view:
For file edits (not new files), Codex shows a diff:
def greet(name):
- print(f"Hi {name}")
+ print(f"Hello, {name}! Welcome.")
return name
Lines with - are being removed. Lines with + are being added. Unchanged lines provide context.
Let's run through a complete task to see the full Codex workflow in action. We'll ask Codex to do something slightly more involved.
Task: Create a Python utility function with documentation
> Create a Python file called utils.py with a function that converts
> temperatures between Celsius and Fahrenheit. Include docstrings and
> type hints.
What happens step by step:
- Codex analyzes your request and determines it needs to create a file
- It generates the content and presents it for approval:
╭─ Creating file: utils.py ──────────────────────╮
│ │
│ def celsius_to_fahrenheit(celsius: float) │
│ -> float: │
│ """Convert Celsius to Fahrenheit. │
│ │
│ Args: │
│ celsius: Temperature in Celsius. │
│ │
│ Returns: │
│ Temperature in Fahrenheit. │
│ """ │
│ return (celsius * 9/5) + 32 │
│ │
│ def fahrenheit_to_celsius(fahrenheit: float) │
│ -> float: │
│ """Convert Fahrenheit to Celsius. │
│ │
│ Args: │
│ fahrenheit: Temperature in Fahrenheit. │
│ │
│ Returns: │
│ Temperature in Celsius. │
│ """ │
│ return (fahrenheit - 32) * 5/9 │
│ │
╰─────────────────────────────────────────────────╯
[a]pprove [r]eject [e]dit
- Press
ato approve - Codex creates the file and confirms:
Created utils.py
Following up:
You can continue the conversation with follow-up instructions:
> Now add a main block that demonstrates both functions with example values
Codex will propose an edit to the existing utils.py file, showing the additions in diff format.
Beyond natural language prompts, Codex CLI has several built-in commands and keyboard shortcuts for navigation.
Quick command reference:
| Command | Action |
|---|---|
/help |
Show available commands |
/model |
Display or change the current model |
/history |
View conversation history |
/clear |
Clear the conversation context |
/exit or Ctrl+C |
Exit Codex CLI |
One-shot mode (non-interactive):
You can also run Codex without entering interactive mode by passing your prompt directly:
# Run a single task and exit
codex "Explain what this project does based on the README"
# Specify a different model
codex --model gpt-5.4 "Add error handling to main.py"
# Run a single task and exit
codex "Explain what this project does based on the README"
# Specify a different model
codex --model gpt-5.4 "Add error handling to main.py"
Quiet mode for scripting:
# Suppress interactive UI, output result to stdout
codex --quiet "What is the main entry point of this project?"
Useful keyboard shortcuts during a session:
- Up/Down arrows — Navigate through prompt history
- Ctrl+C — Cancel current generation or exit
- Ctrl+L — Clear the screen (keeps session active)
Questions & Answers
Key Takeaways
- Terminal-native AI: Codex CLI brings AI assistance directly into your terminal workflow with full local file access
- Approval flow: Every destructive action requires your explicit approval — you stay in control
- Interactive or one-shot: Use interactive mode for complex tasks, one-shot mode for quick questions
- Project-aware: Codex sees your entire working directory and maintains context across a session
- Read first, write later: Start with read-only questions to understand the interface before approving changes
- Git safety net: Always work in a git repo so you can revert any unwanted changes
Next Steps: In Lesson 2 — Sandboxed Execution, you'll learn how Codex CLI's sandboxing keeps your system safe and explore the different approval policies in depth.