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
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)
- 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
Install steps (VS Code)
- Open VS Code. Press Ctrl+Shift+X (Mac: Cmd+Shift+X).
- Search Codex / OpenAI and install Codex – OpenAI’s coding agent (publisher OpenAI, ID
openai.chatgpt). - Or from Quick Open (Ctrl+P):
ext install openai.chatgpt. - Open a project folder.
- Click the Codex icon in the Activity Bar / side panel. If missing: Command Palette → Codex: Open Codex Sidebar.
- Sign in with your ChatGPT account and finish the browser flow.
- Many people drag the Codex panel to the right side so chat sits next to the editor.
Optional: Codex CLI
- 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). - cd into your project and run
codex. - Sign in with ChatGPT when prompted.
- 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
- Model / effort: pick from the Codex UI or CLI model controls. Exact labels change; choose a coding-capable model for hard tasks.
- Permissions / sandbox: keep approvals on for shell and file writes until you trust the task.
- Config file: CLI/extension share user config under
~/.codex/config.toml(Windows:%USERPROFILE%\.codex\config.toml). - Old approval_policy: if Codex fails to start mentioning
approval_policy = "untrusted", remove that setting (OpenAI removed it in newer builds). - Project rules: add a short
AGENTS.md(Codex/initcan create one) so standing rules are not retyped.
# 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)
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.
- Open one source file and (optionally) select a function.
- Paste the prompt in the Codex sidebar.
- Read the summary and the diff. Keep only what you understand.
- If it offers cloud delegation, use it only when your plan includes Codex Cloud and the task is large.
- Commit to Git first so you can undo.
| Client | Best for |
|---|---|
| Codex VS Code extension | Day-to-day chat, edits, diffs beside code |
| Codex CLI | Terminal workflows, scripts, CI-style codex exec |
| ChatGPT macOS app + VS Code | Quick questions/edits from the desktop app (Mac) |
- 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.
नमस्कार मित्रांनो. वरच्या chapter मध्ये आपण Codex extension install करून ChatGPT ने sign in कसं करायचं ते पाहिलं. आता Codex खरंच तुमच्या editor मध्ये चालतो का ते तपासूया. Peacock Print Shop नावाच्या काल्पनिक दुकानाचा एक छोटा practice folder उघडा, एक Git checkpoint save करा, आणि Codex ला किमतीचा bug fix करायला सांगा. Codex तुमच्या folder मधल्या files स्वतः बदलू शकतो, म्हणून Git checkpoint तुमची सुरक्षा आहे, आणि git diff प्रत्येक बदल दाखवतो. Starter file मध्ये 4 tests fail आणि 3 pass होतात, आणि बरोबर fix केल्यावर सगळे 7 pass होतात.
नमस्ते दोस्तों. ऊपर के chapter में हमने Codex extension install करके ChatGPT से sign in करना देखा. अब देखते हैं कि Codex सच में आपके editor में चलता है या नहीं. Peacock Print Shop नाम की काल्पनिक दुकान का एक छोटा practice folder खोलो, एक Git checkpoint save करो, और Codex से कीमत का bug ठीक करवाओ. Codex आपके folder की files खुद बदल सकता है, इसलिए Git checkpoint आपकी सुरक्षा है, और git diff हर बदलाव दिखाता है. Starter file में 4 tests fail और 3 pass होते हैं, और सही fix के बाद सभी 7 pass होते हैं।
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.
Ravindra Bagale's Tip – मराठी
OpenAI चे Codex docs प्रत्येक काम करण्याआधी आणि नंतर Git checkpoint घ्यायला सांगतात. Checkpoint असला की Codex ने केलेला कोणताही बदल git diff ने सहज दिसतो आणि git restore ने सहज परत घेता येतो.
Ravindra Bagale's Tip – हिंदी
OpenAI के Codex docs हर काम से पहले और बाद में Git checkpoint लेने की सलाह देते हैं. Checkpoint हो तो Codex का कोई भी बदलाव git diff से आसानी से दिखता है और git restore से आसानी से वापस हो जाता है।
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.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)
- Create the practice folder with the name shown below, and save the two files from this section inside it.
- Create a virtual environment: on macOS or Linux run
python3 -m venv .venv. On Windows runpy -3 -m venv .venv. - 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. - Install pytest inside the virtual environment:
python -m pip install pytest.
Save a Git checkpoint before Codex starts
- 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.
- Create a small ignore file: the folder needs a file named
.gitignorewith 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. - 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.
- Check it: run
git log --oneline. You should see one line that ends with Checkpoint before Codex.
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):
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:
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.txtRead 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
- Open the folder: in VS Code choose File and then Open Folder, pick
peacock-print, and openprint_cost.py. - Open Codex: click the Codex icon. If it is not visible, open the Command Palette with
Ctrl+Shift+PorCmd+Shift+Pand run Codex: Open Codex Sidebar. Sign in with your ChatGPT account if Codex asks. - 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.
- 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.
- See every change: in the terminal run
git status --shortand thengit diff. Onlyprint_cost.pyshould be listed. Iftest_print_cost.pyalso changed, rungit restore test_print_cost.pyto put the tests back. - Confirm yourself: with your virtual environment active, run
python -m pytest -q. Expect 7 passed. - 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.
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
- 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.
- Problem:
git commitsays Author identity unknown. Fix: run the twogit config user.nameandgit config user.emaillines from the checkpoint step inside the folder, and then run the commit again. - 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 initin this folder, and then allow Codex to work in the folder when it asks. - 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 pytestin your virtual environment, and ask Codex to run the tests again. - 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.tomlon Windows, and restart VS Code. - Problem: you do not like what Codex changed. Fix: run
git restore print_cost.pyto go back to your checkpoint, and then try a clearer prompt. Nothing is lost, because the checkpoint is saved in Git. - 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-printfolder. 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.
Git checkpoint before Codex works
Check Codex changes with git diff
Codex काम करण्याआधी Git checkpoint
Codex चे बदल git diff ने तपासा
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
Reference the open file/selection instead of pasting megabytes. One task per chat. Use cloud only for long jobs your plan includes.