How to Use Codex in VS Code: A Beginner’s Guide

To use Codex in VS Code, install the official Codex extension from OpenAI, open its sidebar, and sign in with ChatGPT. Open your project folder, then ask Codex to explain your code or make a change.

You can inspect the resulting edits without leaving the editor.

This tutorial takes you from installation to fixing a small JavaScript bug. You’ll give Codex a specific task, review its changes, and run the code to check the result.

What you need

Before starting, have these ready:

  • Visual Studio Code installed on your computer.
  • A ChatGPT account with Codex access, or an OpenAI API key with available API usage.
  • A project folder to open in VS Code. An empty folder is fine for this tutorial.
  • Node.js if you want to run the JavaScript example below.

Codex supports ChatGPT sign-in and API key authentication for local work. With ChatGPT, you use your account’s available Codex allowance. API key usage is billed through your OpenAI Platform account instead. You don’t need an API key when signing in with ChatGPT.

If you’re working on an existing project, save your files and create a Git commit before asking for edits. That gives you a known starting point to compare against.

1. Install the Codex extension

Open the Extensions view using the square-block icon in VS Code’s sidebar. Search for Codex and select the extension published by OpenAI.

You can also open the official Codex Marketplace listing directly. Its extension identifier is openai.chatgpt.

Click Install and wait for installation to finish.

For this guide, use the Codex extension’s own panel. VS Code also offers other AI chat integrations, so checking the publisher and extension identifier helps you follow the same setup.

2. Open Codex and sign in

Click the Codex icon in the sidebar. If you can’t find it, open View → Command Palette, search for Codex: Open Codex Sidebar, and run that command.

Select Sign in with ChatGPT, complete the browser sign-in, and return to VS Code. Use the account and workspace where you have Codex access.

If you prefer API billing, select Use API Key on the signed-out screen instead.

3. Open your project folder

Choose File → Open Folder and open the project you want to work on.

For a small practice project, create a folder named codex-practice and open it in VS Code. Add a file named total.js with this code:

function calculateTotal(prices) {
  return prices.reduce((total, price) => total + price);
}

console.log(calculateTotal([10, 20, 30]));
console.log(calculateTotal([]));

Save the file. Open Terminal → New Terminal and run:

node total.js

The first call prints 60. The second throws a TypeError because reduce() has no initial value and the array is empty.

This gives you a clear task for Codex: make an empty array return 0 while preserving the result for a populated array.

4. Ask Codex to explain the problem

Keep total.js open and select the function. The extension can use open files and selected code as context, as described in the official extension listing.

Send this prompt in the Codex panel:

Explain calculateTotal in total.js. Why does it fail when prices is
an empty array? Explain the smallest fix before changing any files.

This prompt names the file, identifies the failing input, and asks for an explanation first. It gives you a chance to understand the proposed fix.

A useful explanation should identify the missing initial accumulator value. Without that value, reduce() uses the first array element as its starting point. An empty array has no first element.

For your own project, use the same pattern:

Explain the login handler in src/auth.js. Trace what happens when
the password is incorrect. Don't edit files yet.

Include the actual filename and behavior you want to understand. If there’s an error message, paste it into the prompt too.

5. Ask Codex to fix the bug

Once you understand the explanation, send a follow-up:

Update calculateTotal in total.js so an empty array returns 0.
Keep the result for [10, 20, 30] equal to 60.
Make the smallest change and run node total.js to check it.

If Codex requests permission to edit a file or run a command, read the request and approve the action needed for this exercise. The permissions available depend on your configuration.

For this bug, a minimal fix is:

function calculateTotal(prices) {
  return prices.reduce((total, price) => total + price, 0);
}

The added 0 is the initial accumulator value. It also becomes the result when there are no array elements to process.

Codex’s exact response may vary. Check the code it produces rather than expecting its wording to match this tutorial.

6. Review and test the change

Read Codex’s summary and open the changed file. The extension supports reviewing edits beside your code.

For this exercise, check that:

  • The function still adds the prices together.
  • The only necessary change is the initial value passed to reduce().
  • Both example calls remain in the file.

Run the command yourself in VS Code’s terminal:

node total.js

You should now see:

60
0

Try another input, such as [5, 15], which should return 20.

If Codex reports that it couldn’t run the command, its edit still needs checking. For example, node: command not found means Node.js isn’t available in that terminal; it doesn’t tell you whether the function is correct.

On a real project, run the relevant tests and try the feature yourself before committing the change. If the result is wrong, describe what happened and what you expected:

The empty array now returns 0, but this input still fails: [...].
Here is the error: [...]. Investigate that case and keep the
existing passing behavior.

Tips for your next Codex task

Once you’ve completed the example, try a small change in your own project.

Give Codex a goal with a way to check completion. For example:

In the contact form, show an error when the email field is empty.
Keep the existing layout. Add a test using this project's current
test setup, then run the relevant tests.

Start a separate conversation when moving to an unrelated task. Keep each request small enough that you can review the resulting files and explain why they changed.

If you aren’t sure where to begin, ask for an investigation:

Find where this project validates contact form submissions.
Tell me which files are involved and suggest a small implementation
plan before editing anything.

Troubleshooting common setup problems

The Codex sidebar isn’t visible

Check that the OpenAI extension is installed and enabled in the current VS Code window. Run Codex: Open Codex Sidebar from the Command Palette.

If the command is missing, reload VS Code and check the extension again.

Sign-in works, but Codex won’t start a task

Read the displayed error first. Confirm that you’re using the intended account and workspace, and check whether the message mentions access or a usage limit.

For a work or school account, workspace settings may affect access. Switching to API authentication changes the billing method; it isn’t a way to use your ChatGPT allowance.

Codex is looking at the wrong files

Check which folder is open in VS Code. Open the relevant file, select the code you mean, and name the file explicitly in your request.

For example, use “Explain src/cart/total.js” instead of “Explain the total function” when several files contain similar code.

Codex can’t run the project’s commands

Try the same command in Terminal → New Terminal. Check that you’re in the right directory and that the required runtime and dependencies are installed.

For the tutorial example, node --version should print a version number. If it doesn’t, install Node.js and reopen the terminal before trying again.

Frequently asked questions

Do I need an API key to use Codex in VS Code?

No. You can sign in with ChatGPT if your account has Codex access. An API key is an alternative for usage billed through OpenAI Platform.

Is Codex in VS Code free?

Installing the extension and paying for model usage are separate things. Your available allowance depends on your account and plan; API key usage is billed separately.

Do I need to connect GitHub?

You can follow this local-folder exercise without publishing the project to GitHub. Git is useful for tracking changes, but creating a local Git repository and connecting a GitHub account are different steps.

Can Codex edit files, or does it only suggest code?

Codex can edit project files through the extension. Inspect the changes and run your checks after each task.

Can I use Codex in Cursor too?

Yes. OpenAI lists Cursor and Windsurf alongside VS Code as compatible editors for the extension.

More ChatGPT tutorials

See all