How-To Guides

How to Set Up OpenAI Codex CLI on Windows with PowerShell: Step-by-Step Guide

A step-by-step guide to setting up OpenAI's Codex CLI natively on Windows with PowerShell, VS Code, Git, and GitHub CLI. Go from a Windows machine to running AI-assisted code in under an hour, with no WSL required.

  • Codex runs natively in PowerShell with its own Windows sandbox, no WSL needed
  • The standalone PowerShell installer is the primary install path, with npm as a fallback
  • ️ Know which Windows sandbox you are on, and when a one-time admin approval is needed
  • AGENTS.md gives Codex the same project-rule context that CLAUDE.md gives Claude Code
By Rejith Krishnan11 min read
How to Set Up OpenAI Codex CLI on Windows with PowerShell: Step-by-Step Guide

Why Native Windows Is a Good Foundation for Codex

OpenAI's Windows documentation says to use the native Windows sandbox by default. You install Codex in PowerShell, run it against projects on your normal Windows drive, and keep using the Windows tools you already have. There is no Linux distribution to install and no second filesystem to manage.

Codex enforces its sandbox on Windows itself. The sandbox applies the active filesystem and network permissions to every command Codex runs and to the child processes those commands start. Approval policy is a separate control: it decides when Codex stops to ask before using more access.

Choose WSL instead when you need Linux-native tooling, when your repositories and workflow already live in WSL2, or when the native sandbox options do not fit your machine. We cover that route in our Codex CLI on Windows with WSL guide.

By the end of this guide you will have:

  • VS Code on Windows, configured to open into PowerShell by default
  • Git and GitHub CLI installed with winget and authenticated to your GitHub account
  • Codex CLI installed, verified, signed in, and used to build a Hello World web app
  • An understanding of which Windows sandbox Codex is using on your machine
  • An npm fallback path for teams that standardize on Node.js

Total time: under an hour on a modern machine with a decent connection.

This is the PowerShell companion to our WSL guide, so Steps 1 to 5 follow the same order and the two read as a set.


Prerequisites

  • Windows 11 (recommended) or a recent, fully updated Windows 10 (best effort; Windows 10 version 1809 or later)
  • winget available. If winget --version fails in PowerShell, update Windows or install the Windows Package Manager first
  • Permission to approve one administrator prompt, in case Codex needs to set up its sandbox
  • A ChatGPT plan that includes Codex, or an OpenAI API key
  • A GitHub account (skip Step 4 if you already have one, or create one there in a few minutes)

Check winget now:

winget --version

Step 1: Install VS Code

Already have VS Code? Skip to Step 2.

You can install it from https://code.visualstudio.com, or from PowerShell:

winget install --id Microsoft.VisualStudioCode -e

If you use the website installer, run it with the defaults and, on Select Additional Tasks, check Add to PATH so code . works from any terminal. Launch VS Code once so it finishes first-run setup, then close and reopen PowerShell so the PATH change takes effect.

Tip: Pin VS Code to your taskbar. You will open it constantly.


Step 2: Check Your Windows Terminal and Winget Setup

Unlike the WSL route, there is no Linux layer to install here. This step makes sure your shell and package manager are ready.

2a. Open PowerShell

Search for Windows Terminal or PowerShell in the Start menu and open it. A normal (non-admin) window is what you want for everything in this guide, including running Codex. Administrator rights are only needed if Codex asks to set up its sandbox in Step 6.

2b. Confirm winget works

winget --version

You should see a version number. If the command is not found, update Windows or install the Windows Package Manager, then reopen PowerShell.

2c. Confirm package IDs before install

winget search --id Microsoft.VisualStudioCode -e
winget search --id Git.Git -e
winget search --id GitHub.cli -e
winget search --id OpenJS.NodeJS.LTS -e

Each command should return one exact match.

2d. Check your Windows version

[System.Environment]::OSVersion.Version

Build 26100 or later means Windows 11 24H2 or newer, which supports Codex's recommended sandbox (more on that in Step 6). Older builds still work using a fallback sandbox.


Step 3: Set PowerShell as the Default Terminal in VS Code

  1. Open VS Code and press Ctrl + Shift + P.
  2. Run Terminal: Select Default Profile.
  3. Select PowerShell.

New terminals (Ctrl + backtick) now open in PowerShell with a prompt like:

PS C:\Users\yourname>

If you see a different shell, such as Command Prompt or Git Bash, repeat the steps.

Tip: Type code . in any folder from PowerShell and VS Code opens that folder.


Step 4: Set Up Your GitHub Account

Already have a GitHub account? Skip to Step 5. Use the same account you use for work or personal projects. There is no need to create a new one.

If you do not have one yet:

  1. Go to https://github.com and create a free account.
  2. Add a profile photo and your name.
  3. Students can apply for the GitHub Student Developer Pack at https://education.github.com/students.

Step 5: Install Git and GitHub CLI

winget install --id Git.Git -e
winget install --id GitHub.cli -e

Close and reopen PowerShell so both commands are on your PATH, then configure your identity and sign in:

git config --global user.name "Your Name"
git config --global user.email "your-github-email@example.com"
gh auth login

Use the email address already registered to your GitHub account for user.email. If git config --global user.name already returns your correct name, you can skip both git config lines.

At the prompts choose GitHub.com, HTTPS, and Login with a web browser. Copy the one-time code, open the URL, paste it, and authorize. Then verify:

git --version
gh --version
gh auth status

All three should return versions or a confirmed login with no errors.


Step 6: Install Codex CLI and Build Your First App

Codex is OpenAI's coding agent for the terminal. You describe a task in plain language and it reads, edits, and runs code in your project, asking for approval at the boundaries you set.

6a. Install Codex with the standalone installer (recommended)

Download the PowerShell installer, then run it. The -ExecutionPolicy Bypass flag applies to this one script run only and does not change your system policy:

Invoke-WebRequest -UseBasicParsing -Uri 'https://chatgpt.com/codex/install.ps1' -OutFile '.\codex-install.ps1'
powershell -ExecutionPolicy Bypass -File .\codex-install.ps1

OpenAI's Windows deployment docs confirm this installer defaults to latest when you do not pass -Release. Use -Release only when you need to pin a specific version for managed rollout.

Close and reopen PowerShell, then verify as your normal user, not as administrator:

Get-Command codex
codex --version

Get-Command codex should print a path, and codex --version should print a version number. If you see "not recognized", reopen PowerShell once more and confirm you ran the installer in PowerShell, not in a WSL shell.

You can delete codex-install.ps1 afterward.

6b. Optional fallback: install with npm

Use this path if your team standardizes CLI installs through npm. It needs Node.js and npm on the machine first:

winget install --id OpenJS.NodeJS.LTS -e

Reopen PowerShell, then check and install:

node --version
npm --version
npm install -g @openai/codex
codex --version

On Windows, npm installs global packages into your own profile folder by default, so there is no sudo step and no need to change the npm prefix. This is simpler than the Linux route.

6c. Sign in before you start your first session

Choose how to authenticate:

codex login
  • ChatGPT sign-in uses the access included with your plan. Complete the browser flow. If the browser cannot reach the CLI, run codex login --device-auth and enter the one-time code.
  • API key bills your OpenAI Platform account at API rates. Read the key without echoing it, then pipe it in:
$secureKey = Read-Host 'OpenAI API key' -AsSecureString
$plainKey = [System.Net.NetworkCredential]::new('', $secureKey).Password
$plainKey | codex login --with-api-key
Remove-Variable plainKey, secureKey

Never put a key in a repository, an AGENTS.md, a script, or a prompt. Confirm either method worked with codex login status.

6d. Understand the Windows sandbox

The first time Codex runs commands on Windows, it uses one of three sandbox implementations:

  • mxc is the recommended sandbox on compatible machines (Windows 11 24H2 or 25H2). It uses native process isolation and needs no administrator-approved setup, extra Windows accounts, or firewall rules.
  • elevated is the preferred fallback when mxc is unavailable. It needs a one-time administrator approval. Commands inside the sandbox still run without administrator privileges.
  • unelevated is a weaker fallback for when elevated setup is not possible. It has weaker network isolation.

If Codex shows a Set up Agent sandbox to continue prompt, approve the administrator (UAC) prompt that follows. This setup prompt appears when Codex must provision the legacy elevated sandbox.

To prefer mxc on a compatible machine, or to pin a fallback, add this to $HOME\.codex\config.toml:

[features]
prefer_mxc = true

[windows]
sandbox = "elevated"

Use only the settings you need. sandbox accepts "elevated" or "unelevated". Inside a Codex session, /status and /debug-config show which settings are active.

6e. Build your first app

New-Item -ItemType Directory -Force -Path "$HOME\git\helloworld" | Out-Null
Set-Location "$HOME\git\helloworld"
git init
codex

Codex starts in its default approval mode, so it will ask before doing anything outside the workspace. Type:

Build me a simple Hello World web app with HTML, CSS, and JavaScript. Give it a clean modern look with a centered card, a heading that says 'Hello World', a subtitle with today's date, and a button that shows an alert when clicked. Save everything in this folder.

Approve the file writes as they come up. When it finishes, run /quit.

6f. Preview your app

From the same folder in PowerShell:

Start-Process .\index.html

Your default browser opens the page.

6g. Keep Codex updated

Run this command in a normal PowerShell window:

codex update

Step 7: Open Your Project in VS Code

Set-Location "$HOME\git"
code .

VS Code opens with your git folder, and Explorer shows helloworld with the files Codex created. The integrated terminal opens in PowerShell, so you can edit, test, and commit without leaving the editor.


Best Practices for AI-Assisted Development

Keep projects in a normal folder in your user profile. A path such as C:\Users\yourname\git\my-app works well. Do not move a repository after Codex has set up its sandbox for it, because sandboxing can stop working after a move. If that happens, restart Codex or re-run the sandbox setup.

Watch for the "writable by Everyone" warning. Codex warns when a folder is writable by the Everyone group. Remove that access where appropriate, then restart Codex or re-run the sandbox setup.

Match the approval mode to the risk. Sandbox mode sets what Codex is allowed to touch. Approval policy sets when it must ask. Two settings cover most work:

# Normal development: edit inside the workspace, ask before crossing it
codex --sandbox workspace-write --ask-for-approval on-request

# Investigation and review: no edits
codex --sandbox read-only --ask-for-approval on-request

You can also switch mid-session with /permissions.

Know when full access is fine and when it is not. Full access (--yolo, or --dangerously-bypass-approvals-and-sandbox) means Codex is not limited to your project directory and might perform unintentional destructive actions. It is reasonable in a disposable environment you can throw away, such as a scratch VM or a throwaway learning project. It is the wrong choice on a shared repository, a codebase with credentials nearby, or anything you cannot rebuild. For those, stay on workspace-write with on-request approval so you keep oversight.

--full-auto is not a current Codex flag in codex --help (verified with Codex CLI 0.139.0 on November 1, 2026), so do not rely on it in scripts.

Use /plan before non-trivial changes. Type /plan followed by your request. Codex investigates and proposes an approach without implementing it. Reviewing the plan takes a minute and prevents unwanted changes. Entering Plan mode does not grant write access, and permissions are a separate setting.

Use AGENTS.md as the counterpart to CLAUDE.md. Run /init inside Codex to create a starter AGENTS.md, then edit it. Record build and test commands, conventions, and what Codex must not change. Commit it so the whole team shares the rules. Keep it short, because those tokens load on every task. If your team also uses Claude Code, the same facts belong in both files.

Keep sessions short. Every file read, test log, and message consumes context. Run /status to see usage, /compact to summarize earlier conversation, and /new when the next job is unrelated. Small, focused sessions beat marathon ones. Restate any critical constraint after a compact.

Review before you commit. Run /diff, then /review for a second pass, then run your own tests and check git status.

Check your plan or billing. ChatGPT sign-in follows your plan's limits. API-key sign-in bills per token at platform.openai.com.


Verification Notes

This guide was updated against official docs and CLI help on November 1, 2026:

  • OpenAI Windows deployment docs confirm install.ps1 defaults to latest when -Release is omitted.
  • OpenAI Windows sandbox docs confirm native-Windows default guidance, prefer_mxc, and [windows].sandbox keys.
  • codex --help and codex login --help confirm --sandbox, --ask-for-approval on-request, --yolo, codex login --device-auth, codex login --with-api-key, codex login status, and codex update.

What's Next?

For teams looking to bring agentic AI into enterprise workflows with HITL controls, private-by-architecture deployment, and outcome-based contracts, talk to the lowtouch.ai team.

About the Author

Rejith Krishnan

Rejith Krishnan

Founder and CEO

Rejith Krishnan is the Founder and CEO of lowtouch.ai, a platform dedicated to empowering enterprises with private, no-code AI agents. With expertise in Site Reliability Engineering (SRE), Kubernetes, and AI systems architecture, he is passionate about simplifying the adoption of AI-driven automation to transform business operations.

Rejith specializes in deploying Large Language Models (LLMs) and building intelligent agents that automate workflows, enhance customer experiences, and optimize IT processes, all while ensuring data privacy and security. His mission is to help businesses unlock the full potential of enterprise AI with seamless, scalable, and secure solutions that fit their unique needs.

LinkedIn →