Installation, Setup, and Your First Task
Now that you understand what Codex is and how it fits the AI coding landscape, it is time to get it running on your machine. In this lesson, you will install Codex CLI, authenticate your account, and run your very first coding task.
What You Will Learn
- How to install Codex CLI with the install script, npm, or Homebrew
- How to sign in with your ChatGPT account or an API key
- How to launch Codex and navigate the interface
- How to run your first coding task from start to finish
- How to reach Codex cloud from the terminal, the desktop app, and the web
Installing Codex CLI
Codex CLI can be installed in several ways. Commands change from time to time, so check the official Codex CLI docs for the current recommended command for your system. At the time of writing, these are the options.
Option 1: Install script (macOS and Linux)
The official docs lead with a standalone installer:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Run the same command again later to update Codex.
Option 2: Windows
On Windows, run the PowerShell installer:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
Option 3: npm
If you already use Node.js:
npm install -g @openai/codex
Option 4: Homebrew (macOS)
If you prefer Homebrew:
brew install --cask codex
You can also download ready-made binaries from the GitHub Releases page at github.com/openai/codex.
Verifying the Installation
After installation, verify that Codex is available:
codex --version
You should see a version number printed to your terminal. If you get a "command not found" error, make sure the installation directory is in your system PATH.
Authentication
Codex supports two authentication methods:
Method 1: ChatGPT Sign-In (Recommended)
The simplest way to authenticate is to sign in with your ChatGPT account. When you first run codex from a project folder, choose Sign in with ChatGPT and finish the sign-in in your browser. You can also run codex login at any time.
Codex is included with several ChatGPT plans, and usage limits depend on your plan. Plans and limits change, so check OpenAI's pricing page for what yours includes.
Method 2: API Key
If you prefer to use an API key, pipe it into codex login so the key never appears on the command line:
printenv OPENAI_API_KEY | codex login --with-api-key
Run codex login status to check how you are signed in.
Note: API key usage is billed at standard API rates, not from your ChatGPT plan. Some features tied to ChatGPT, such as cloud tasks, may be limited or unavailable with an API key.
Launching Codex
To start Codex CLI, simply type:
codex
This launches the interactive Codex interface in your terminal. You will see a prompt where you can type natural language instructions.
You can also pass a task directly as an argument:
codex "explain what this project does"
This starts Codex and immediately begins working on the task you specified.
Your First Task: Understanding a Project
Let us walk through a complete first task. Navigate to any project directory and run:
cd your-project-directory
codex "explain the structure of this project and what each top-level directory does"
Here is what happens step by step:
- Codex reads your project โ It scans the directory structure, key configuration files (package.json, Cargo.toml, pyproject.toml, etc.), and source files
- It analyzes the structure โ The agent identifies frameworks, languages, and architectural patterns
- It presents its findings โ You get a clear, organized explanation of your project
This is a safe first task because it only reads files. Codex does not modify anything when you ask it to explain or analyze.
Your Second Task: Making a Change
Now try something that modifies code. Create a simple test project first:
mkdir codex-test && cd codex-test
echo "console.log('hello');" > index.js
codex "add a function called greet that takes a name parameter and returns a greeting string, then update the main code to use it"
Codex will:
- Read the existing
index.jsfile - Plan the changes needed
- Edit the file inside your project folder (in the recommended Ask for approval mode, edits inside the project do not need a prompt)
- Ask you first if it needs to go outside the project or use the internet
- Tell you what it changed
When it is done, check the result:
cat index.js
You should see a greet function and updated code that uses it.
Accessing Codex Cloud
Codex cloud runs tasks on OpenAI's servers instead of your laptop. There are three ways in.
From the terminal:
codex cloud
This lets you browse your cloud tasks, send new work to a configured environment, and apply the results to your local repository. The docs mark this command as experimental.
From the desktop app: On macOS and Windows, codex app opens the ChatGPT desktop app. Start a chat and choose Work in > Cloud.
From the web: Go to chatgpt.com/codex, or start a chat on ChatGPT and choose Work in > Cloud.
In Codex cloud you can:
- Pick an environment (your repositories and setup)
- Send tasks to run in cloud sandboxes
- Run several tasks at the same time
- Review results, ask for changes, and open a pull request
Common Setup Issues
"command not found" after installation:
If you installed with npm, make sure the npm global bin folder is in your PATH. Run npm prefix -g to find the install prefix, then add its bin folder to your shell profile.
Authentication fails: Ensure you have an active ChatGPT subscription or a valid API key. Check your internet connection and try signing in again.
Slow responses on first run: The first task may take longer as Codex indexes your project. Subsequent tasks will be faster as the agent builds context.
Key Takeaways
- Install Codex CLI with the official install script, npm (
npm install -g @openai/codex), or Homebrew (brew install --cask codex) - Sign in with ChatGPT (recommended) or an API key through
codex login - Launch with
codexfor interactive mode orcodex "your task"for direct execution - Start with read-only tasks like "explain this project" before making changes
- Reach Codex cloud with
codex cloud, the ChatGPT desktop app (codex app), or chatgpt.com/codex - Start in Ask for approval mode, which keeps Codex inside your project and asks before going further
Quiz
Up next ยท Lesson 3 of 11
Approval Modes: Suggest, Auto Edit, and Full Auto
6 min read
2 of 11 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

