Ravindra BagaleCourses & study guides Track your progress
AI CODING ASSISTANTS · CHAPTER 2 · SETUP

How to Set Up ChatGPT Codex in VS Code (Step by Step)

Codex is OpenAI’s coding agent. In VS Code you use the official extension (Marketplace ID openai.chatgpt). You can also run the Codex CLI in a terminal. Sign in with your ChatGPT account.

In short: install Codex – OpenAI’s coding agent, open the Codex sidebar, sign in with ChatGPT, then chat beside your code or hand bigger jobs to cloud tasks when your plan allows. Optional: install the Codex CLI for the same account in a terminal.

Why Codex in VS Code

WHY

If you already pay for ChatGPT, Codex is the coding agent that sits in your editor: open files and selections become context, you review diffs in place, and you can keep longer work in the same account.

What the product is called (Oct 2026)

WHAT
  • VS Code extension: Marketplace title: Codex – OpenAI’s coding agent. Extension ID: openai.chatgpt.
  • Codex CLI: Terminal agent. Official installers include a curl script from chatgpt.com/codex and package options shown in OpenAI docs.
  • ChatGPT sign-in: Codex is included across ChatGPT plans (including Free/Go on current Help Center wording); usage limits vary. Re-check chatgpt.com/pricing.
  • Codex Cloud: Longer cloud tasks — Help Center says availability depends on plan (often Plus/Pro/Business/Edu/Enterprise). Not the same as Free/Go IDE chat.
  • macOS ChatGPT app: On Mac, the extension can also connect “Work with VS Code” from the ChatGPT desktop app for simple Q&A/edits.

How setup flows

1 · Install extension openai.chatgpt 2 · Open Codex sidebar icon or Command Palette 3 · Sign in ChatGPT account 4 · First local task review diff 5 · Optional CLI codex in terminal

Install steps (VS Code)

HOW
  1. Open VS Code. Press Ctrl+Shift+X (Mac: Cmd+Shift+X).
  2. Search Codex / OpenAI and install Codex – OpenAI’s coding agent (publisher OpenAI, ID openai.chatgpt).
  3. Or from Quick Open (Ctrl+P): ext install openai.chatgpt.
  4. Open a project folder.
  5. Click the Codex icon in the Activity Bar / side panel. If missing: Command Palette → Codex: Open Codex Sidebar.
  6. Sign in with your ChatGPT account and finish the browser flow.
  7. Many people drag the Codex panel to the right side so chat sits next to the editor.

Optional: Codex CLI

HOW
  1. Follow the current install command on OpenAI’s Codex CLI docs (macOS/Linux often: curl -fsSL https://chatgpt.com/codex/install.sh | sh — re-check the docs if the URL changes).
  2. cd into your project and run codex.
  3. Sign in with ChatGPT when prompted.
  4. Useful slash-style commands (names can change): status, model, permissions, review, init for an agents file — run ? or help inside the CLI.

Settings and configuration

  1. Model / effort: pick from the Codex UI or CLI model controls. Exact labels change; choose a coding-capable model for hard tasks.
  2. Permissions / sandbox: keep approvals on for shell and file writes until you trust the task.
  3. Config file: CLI/extension share user config under ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml).
  4. Old approval_policy: if Codex fails to start mentioning approval_policy = "untrusted", remove that setting (OpenAI removed it in newer builds).
  5. Project rules: add a short AGENTS.md (Codex /init can create one) so standing rules are not retyped.
AGENTS.md (example)
# Project rules for Codex
- Language: TypeScript (strict) or Python 3.12 as marked in the folder
- Tests must pass before you finish a task
- Prefer small diffs; do not rewrite unrelated files
- Never read .env or commit secrets

First task (5 minutes)

COPY THIS PROMPT

Explain this open file in simple words, then suggest one small improvement with a unit test. Do not edit unrelated files. Wait for my approval before running shell commands.

  1. Open one source file and (optionally) select a function.
  2. Paste the prompt in the Codex sidebar.
  3. Read the summary and the diff. Keep only what you understand.
  4. If it offers cloud delegation, use it only when your plan includes Codex Cloud and the task is large.
  5. Commit to Git first so you can undo.
ClientBest for
Codex VS Code extensionDay-to-day chat, edits, diffs beside code
Codex CLITerminal workflows, scripts, CI-style codex exec
ChatGPT macOS app + VS CodeQuick questions/edits from the desktop app (Mac)
Rule: extension and menu names change. If you cannot find “Codex”, search the Command Palette for Codex / OpenAI and re-check the Visual Studio Marketplace page.
  • Never paste API keys or .env into Codex chat.
  • Company ChatGPT workspace admins may disable Codex — ask IT first.

Verify your Codex setup: fix a small print shop bug with a Git checkpoint

Hello friends. The chapter above showed how to install the Codex extension and sign in with ChatGPT. Now we prove that Codex really works in your editor. You will open a tiny practice folder for a fictional shop called Peacock Print Shop, save a Git checkpoint, and ask Codex to fix a price bug. Codex can edit files inside your folder by itself, so the Git checkpoint is your safety net, and git diff shows you every change. The starter file fails 4 tests and passes 3, and a correct fix passes all 7.

Ravindra Bagale's Tip

OpenAI's Codex docs suggest a Git checkpoint before and after each task. With a checkpoint, any change Codex makes is easy to see with git diff and easy to undo with git restore.

Practice label: Peacock Print Shop and its page prices are fictional teaching data. It is not a real business, and no real customer data is used. The Git name and the example.com email address below are placeholders for practice only. Passing these tests proves only the listed cases.
Environment (tested): on 16 November 2026 the starter and fixed files below were run on this course's Linux build machine with Python 3.13.5 and pytest 9.1.1. Starter: 4 failed, 3 passed. Fixed file: 7 passed. The AI tool itself runs on your own computer, so its words will differ from any example here. The Git commands below were also run with git 2.47.3.
Checked against official docs: every menu name, command and setting in this practice was checked on 16 November 2026 against the Codex IDE extension page and the agent approvals and security page on developers.openai.com/codex. These tools update often. If a menu name looks different on your screen, search for the same words in the official docs or the Command Palette, and do not guess.

Your task: open the practice folder in VS Code, save a Git checkpoint, open the Codex sidebar, and ask Codex to make print_cost charge 2 rupees per black-and-white page and 8 rupees per colour page, and reject fewer than 1 page with a message that contains pages.

Setup (practice folder peacock-print)

HOW
  1. Create the practice folder with the name shown below, and save the two files from this section inside it.
  2. Create a virtual environment: on macOS or Linux run python3 -m venv .venv. On Windows run py -3 -m venv .venv.
  3. Activate it: on macOS or Linux run source .venv/bin/activate. In Windows Command Prompt run .venv\Scripts\activate.bat, and in Windows PowerShell run .venv\Scripts\Activate.ps1.
  4. Install pytest inside the virtual environment: python -m pip install pytest.

Save a Git checkpoint before Codex starts

HOW
  1. Install pytest first, as shown in the steps above. Codex's default sandbox turns network access off, so it would have to ask you before it could download anything.
  2. Create a small ignore file: the folder needs a file named .gitignore with three lines, .venv/, __pycache__/ and .pytest_cache/, so the virtual environment and cache folders stay out of Git. On macOS or Linux the first command below creates it. On Windows, create the file in VS Code and type the three lines yourself.
  3. Create the checkpoint: run the other Git commands below inside the folder. The name and email are practice placeholders that apply to this folder only.
  4. Check it: run git log --oneline. You should see one line that ends with Checkpoint before Codex.
git-checkpoint.sh
printf '.venv/\n__pycache__/\n.pytest_cache/\n' > .gitignore
git init
git config user.name "Practice Student"
git config user.email "student@example.com"
git add .
git commit -m "Checkpoint before Codex"

Starter print_cost.py (it ignores colour, so every page costs 2 rupees, and 0 or negative pages are accepted):

print_cost.py
def print_cost(pages, colour=False):
    """Fictional Peacock Print Shop: 2 rupees per black-and-white page, 8 rupees per colour page."""
    return pages * 2

Simple tests test_print_cost.py:

test_print_cost.py
import pytest

from print_cost import print_cost


def test_one_black_and_white_page():
    assert print_cost(1) == 2


def test_ten_black_and_white_pages():
    assert print_cost(10) == 20


def test_fifty_black_and_white_pages():
    assert print_cost(50) == 100


def test_ten_colour_pages():
    assert print_cost(10, colour=True) == 80


def test_three_colour_pages():
    assert print_cost(3, colour=True) == 24


def test_zero_pages_is_rejected():
    with pytest.raises(ValueError, match="pages"):
        print_cost(0)


def test_negative_pages_is_rejected():
    with pytest.raises(ValueError, match="pages"):
        print_cost(-2)

Before you ask the AI, run python -m pytest -q in the folder. You should see 4 failed, 3 passed. That proves Python and pytest work before the AI tool is involved.

The exact prompt to try (copy it as it is):

codex-prompt.txt
Read print_cost.py and test_print_cost.py. Fix print_cost for the fictional Peacock Print Shop: 2 rupees per black-and-white page and 8 rupees per colour page, so 10 colour pages cost 80. Raise ValueError with a message that contains pages when pages is less than 1. Do not change test_print_cost.py. Then run python -m pytest -q and show me the result.

HOW to verify your Codex extension setup

HOW
  1. Open the folder: in VS Code choose File and then Open Folder, pick peacock-print, and open print_cost.py.
  2. Open Codex: click the Codex icon. If it is not visible, open the Command Palette with Ctrl+Shift+P or Cmd+Shift+P and run Codex: Open Codex Sidebar. Sign in with your ChatGPT account if Codex asks.
  3. Know what Codex may do: when a folder is under Git, the Codex docs say that Codex recommends the Auto preset. In Auto, Codex can read files, edit files and run commands inside this folder without asking, and it asks first before it uses the network or touches files outside the folder.
  4. Send the prompt: paste the prompt above into the Codex chat and press Enter. Wait until Codex shows a short summary of what it changed and the test result.
  5. See every change: in the terminal run git status --short and then git diff. Only print_cost.py should be listed. If test_print_cost.py also changed, run git restore test_print_cost.py to put the tests back.
  6. Confirm yourself: with your virtual environment active, run python -m pytest -q. Expect 7 passed.
  7. Save the result: if all 7 tests pass and the diff looks right, run git commit -am "Codex fixed print_cost". This is your checkpoint after the task.

What a correct result looks like: Codex explains that the starter ignores colour and does not reject 0 or negative pages. Its edit picks a rate of 8 for colour and 2 otherwise, and adds a check that raises ValueError with pages in the message. git status --short shows M print_cost.py only, and the exact words and code style change from run to run, which is fine. The result is correct only when pytest shows 7 passed.

Real pytest output after the fixed file:

pytest-after.txt
.......                                                                  [100%]
7 passed in 0.01s
Optional completed print_cost.py (try it yourself first)

Codex may write the rate with an if statement instead of a one-line choice. Any version is fine if all 7 tests pass and git diff shows no change to the test file.

print_cost.py
def print_cost(pages, colour=False):
    """Fictional Peacock Print Shop: 2 rupees per black-and-white page, 8 rupees per colour page."""
    if pages < 1:
        raise ValueError("pages must be at least 1")
    rate = 8 if colour else 2
    return pages * rate

Troubleshooting: common Codex extension problems

HOW
  1. Problem: the Codex icon is not visible. Fix: open the Command Palette and run Codex: Open Codex Sidebar. If that command is missing, check in the Extensions view that Codex – OpenAI's coding agent by OpenAI is installed and enabled, and then reload the window.
  2. Problem: git commit says Author identity unknown. Fix: run the two git config user.name and git config user.email lines from the checkpoint step inside the folder, and then run the commit again.
  3. Problem: Codex only answers and does not edit the file. Fix: Codex may be in read-only mode, which it can use for a folder that is not under Git or that you have not trusted yet. Make sure you ran git init in this folder, and then allow Codex to work in the folder when it asks.
  4. Problem: Codex asks for approval to install pytest or to use the network. Fix: the default sandbox keeps network access off. You can decline, install pytest yourself with python -m pip install pytest in your virtual environment, and ask Codex to run the tests again.
  5. Problem: Codex fails to start and the error mentions approval_policy = "untrusted". Fix: OpenAI retired that setting. Remove that line from ~/.codex/config.toml, or %USERPROFILE%\.codex\config.toml on Windows, and restart VS Code.
  6. Problem: you do not like what Codex changed. Fix: run git restore print_cost.py to go back to your checkpoint, and then try a clearer prompt. Nothing is lost, because the checkpoint is saved in Git.
  7. Problem: Codex says the tests pass, but they fail for you. Fix: make sure your virtual environment is active and that you are inside the peacock-print folder. Trust the result in your own terminal, not the summary in the chat.

Practice cards: English and spoken Marathi

Each card below explains one idea on its own, so you can save or revise a single card without reading the whole chapter.

PRACTICE CARDAI Coding

Git checkpoint before Codex works

Run git init, git add . and git commit before you ask Codex to change anything.
If you dislike the change, git restore puts the file back exactly as it was.
Ravindra Bagale · ravindrabagale.com/ai-coding
PRACTICE CARDAI Coding

Check Codex changes with git diff

Run git status --short to list every file that Codex changed.
Run git diff to read each change, and then run the tests in your own terminal.
Ravindra Bagale · ravindrabagale.com/ai-coding
सराव कार्डमराठी

Codex काम करण्याआधी Git checkpoint

Codex ला काहीही बदलायला सांगण्याआधी git init, git add . आणि git commit चालवा.
बदल आवडला नाही तर git restore file पूर्वी होती तशीच परत आणतो.
Ravindra Bagale · ravindrabagale.com/ai-coding
सराव कार्डमराठी

Codex चे बदल git diff ने तपासा

Codex ने बदललेल्या सगळ्या files पाहण्यासाठी git status --short चालवा.
प्रत्येक बदल वाचण्यासाठी git diff चालवा, आणि मग tests तुमच्या स्वतःच्या terminal मध्ये चालवा.
Ravindra Bagale · ravindrabagale.com/ai-coding

Quick quiz

1. What is the VS Code extension ID?

openai.chatgpt (title: Codex – OpenAI’s coding agent).

2. How do you sign in?

With your ChatGPT account in the extension or CLI.

3. Where is shared config often stored?

~/.codex/config.toml.

4. Is Codex Cloud the same on every ChatGPT plan?

No — cloud tasks are plan-dependent; re-check OpenAI Help Center.

Save tokens and money

SMART AI USE

Reference the open file/selection instead of pasting megabytes. One task per chat. Use cloud only for long jobs your plan includes.

Save these cards

INTERVIEW CARDAI Coding

What is ChatGPT Codex?

OpenAI’s coding agent (IDE + CLI + optional cloud).
Sign in with ChatGPT; review diffs before keep.
Ravindra Bagale · ravindrabagale.com/ai-coding
COMPARISON CARDAI Coding

Codex vs Copilot in VS Code

Codex: OpenAI ChatGPT account / Codex agent.
Copilot: GitHub account; strong inline ghost text.
Ravindra Bagale · ravindrabagale.com/ai-coding
REVISION CARDAI Coding

Codex VS Code in 4

Install openai.chatgpt.
Open sidebar → ChatGPT sign-in.
AGENTS.md rules.
Review diff; optional CLI.
Ravindra Bagale · ravindrabagale.com/ai-coding