How to Run OpenAI Codex on Windows and Get It Working the First Time
If you want OpenAI Codex working on a Windows laptop with the least friction, the shortest path is usually this: use WSL2 for the CLI version, or stay native Windows if you’re only calling the API from Python or Node. The exact setup depends on which “Codex” you mean, so start there. For most first-time Windows setups, WSL2 is the safest choice because many terminal tools behave more like they do on Linux and you avoid a lot of Windows shell quirks.
What you need before you start
- An OpenAI account with API access and an API key.
- A terminal you can use comfortably: PowerShell, Windows Terminal, or a WSL2 shell like Ubuntu.
- If you’re using a CLI tool, follow that tool’s install method exactly, because the command name and install path depend on which Codex package you mean.
- If you’re using an API-based workflow, install the runtime your script needs, usually Python or Node.js.
- Permission to install software on the machine, or at least permission to use Windows Subsystem for Linux if you choose WSL2.
- A project folder you can safely test in, not your most important repo first.
If you only want Codex to generate code through your own script, you can stay on native Windows. If you want the least trouble with terminal tools, WSL2 is usually the better starting point.
The easiest way to run Codex on Windows
Start with WSL2 if you want the best odds of a clean first run. Native Windows can work, but CLI tools often expect Unix-like paths, shells, and package behavior. WSL2 gives you a Linux environment inside Windows, which tends to match those expectations better.
Use native Windows when your workflow is just an API call from Python, Node, or another app you control. That route is simpler if you do not need a terminal app to manage files and prompts for you.
For a first setup, the practical order is:
- Use native Windows only if you are calling the API from your own script.
- Use WSL2 if you want a terminal-based Codex CLI or helper to behave predictably.
- Avoid mixing half the setup in PowerShell and half in WSL unless you have a reason. That is where most first-run problems start.
If the tool you are trying to use ships as a Node package or shell command, WSL2 is the cleaner path. If the tool is just a Python script using the API, either environment can work.
Set up your OpenAI key and command line
- Create or copy your OpenAI API key.
Store it somewhere safe. Do not paste it into code that you plan to share.
- Install the runtime your Codex workflow needs.
If the workflow is Node-based, install Node.js. If it is Python-based, install Python. If the tool has its own installer, use that instead of guessing.
- Put the tool on your PATH the way its installer expects.
If the command is meant to be run from a terminal, the install location has to be visible to that shell. On Windows, that usually means installing through the package manager the tool recommends, or opening a new terminal after installation so PATH updates take effect.
- Set your API key as an environment variable.
In PowerShell, a common per-session approach looks like this:
$env:OPENAI_API_KEY="your_api_key_here"If you want it to persist, set it through Windows environment variables or your shell profile instead of retyping it every time.
- Open a fresh terminal in the environment you plan to use.
If you chose WSL2, set the key in WSL as well. A key set in Windows does not always appear automatically inside Linux shells.
Run a first test command
Use the smallest possible command that proves two things: the tool starts, and your key works.
If you are using a CLI named codex, a first test often looks like this:
codex "Write a one-line PowerShell command that prints hello"If your workflow is a script instead of a CLI, run a minimal API call from that script and ask for a tiny response, such as a one-sentence answer or a short function.
You are looking for a clean response, not a perfect code sample. If the tool returns text and does not complain about authentication, your setup is close. If it fails, the error message usually tells you whether the problem is the key, the command name, or the shell environment.
If Windows says the command isn’t recognized
This usually means Windows cannot find the executable, or your current shell has not loaded the updated PATH yet.
Check these in order:
- Make sure the tool actually installed.
- Close the terminal and open a new one after installation.
- Confirm you are in the same shell where the tool was installed.
- If you installed in WSL, do not expect PowerShell to find the same Linux command automatically.
- If you installed in PowerShell for your user account, make sure the install directory is on PATH.
If you know where the executable is, you can test the full path once to confirm the install worked. If the full path works but the bare command does not, the problem is PATH, not the tool itself.
If PowerShell blocks the script
Changing execution policy affects how PowerShell runs scripts on your machine. Use the least permissive change that solves your trusted local setup.
PowerShell may block a script if it thinks the file is not allowed to run. That is common with local tooling and bootstrap scripts.
The safer first fix is usually to allow locally created scripts for your user account, not the whole machine. A common command is:
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedIf that is still too broad for your situation, use the tool from a shell that does not depend on a blocked .ps1 wrapper, or run the vendor-recommended install command exactly as written.
If you downloaded a script from the internet, check whether Windows marked it as blocked before you run it. A tool installed through a package manager is usually easier here than a loose script file.
Using WSL2 when native Windows gets in the way
Use WSL2 when you keep hitting shell differences, PATH problems, or package installs that behave better on Linux. It is often the cleaner choice for Codex-style CLI tools because the command line, file paths, and permissions are more predictable.
Keep these habits:
- Work inside the WSL filesystem for the project if possible, not a deeply nested Windows path.
- Use one terminal for the install and the test run.
- Set your API key inside WSL too.
- Be consistent about which side owns the repo. If you clone in WSL, edit and run there as well.
If you mix Windows paths, Windows Git, WSL Python, and a Windows terminal all at once, you can make a simple setup harder than it needs to be.
How to tell it’s working correctly
A working setup usually shows the same signs every time:
- The command starts without a “not recognized” error.
- The tool does not stop at authentication.
- You get a normal text response or a task result back.
- The response matches the model or mode you asked for, not some fallback behavior.
If the tool can describe a short code task, return a result, and keep running without credential errors, your setup is healthy. At that point, the remaining issues are usually about your prompt or project path, not Windows itself.
Common mistakes people make on Windows
The most common mistake is mixing environments. You install in WSL, then try to run the command in PowerShell. Or you set the API key in Windows, then open Ubuntu and wonder why it is missing.
Other frequent misses:
- Installing Node or Python in one shell and running the command from another.
- Forgetting to restart the terminal after changing PATH.
- Putting the API key in the wrong profile file.
- Running the tool from a folder with awkward permissions or spaces when the tool does not like that setup.
- Using an old shell session that still has the old environment variables.
If something worked once and then stopped, it is often because the shell session changed, not because the tool broke.
What to do next once it runs
Once Codex responds correctly, move from the test prompt to a small real task. Point it at a tiny repo, a single script, or one isolated bug rather than your whole codebase. That gives you a safer read on how it behaves in your environment.
A good next step is to ask it for one narrow change, then review the output before you trust it with anything larger. If you are using the API directly, wrap the call in a tiny script and keep that script as your known-good test case for future Windows setups.
Conclusion
If you only want the shortest reliable setup on Windows, use WSL2 for the CLI version of Codex and native Windows for a simple API script. Get the API key working first, confirm the command is visible in the terminal you plan to use, then run one small test prompt. Once that works, keep the same shell, the same environment, and the same project folder so you do not have to relearn the setup every time you open a new terminal.
Frequently Asked Questions
Should I use PowerShell, Command Prompt, or WSL2 for Codex on Windows?
Use WSL2 if you want the least friction for a terminal-based Codex tool. Use PowerShell if you are only calling the API from a Windows-native script. Command Prompt is usually the least convenient of the three for modern setup steps.
Do I need Node.js or Python?
Only if the Codex workflow you picked depends on them. A CLI tool may need Node, while a custom API script may need Python or Node. If you are not sure, check the install method for the specific tool you are using.
Why does my API key work in Windows but not in WSL2?
Because Windows and WSL2 keep separate environment settings. Set the key inside the environment where you are running the command.
Can I use Codex completely natively on Windows?
Often yes for API-based workflows, and sometimes yes for CLI tools if the package supports Windows well. If you want the fewest shell issues, WSL2 is usually the easier first try for command-line use.