iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⚒️

How to Set Up Codex CLI on Windows

に公開
2025/08/30

Introduction

This article introduces the steps to set up Codex CLI on a Windows environment. The procedure is as follows:
*If you have already completed some steps, please skip them as needed.

  1. Try installing Codex CLI without using a WSL environment (updated 2025/08/29)
  2. If installation without a WSL environment is not possible, install WSL on Windows 11
  3. Install nvm/node.js in the WSL environment
  4. Install Codex CLI

※ Due to recent updates, it seems to work stably even without a WSL environment,
Please try installation without a WSL environment first. (Updated 2025/08/29)

Codex CLI does not officially support Windows (as of 2025/08/29)

According to the page below, Windows is only in experimental support, and using it with Windows + WSL environment is recommended.


https://help.openai.com/en/articles/11096431-openai-codex-cli-getting-started?utm_source=chatgpt.com

Platform Support Status
macOS / Linux Officially supported
Windows (Native) Experimental support only
Windows + WSL (Recommended) Execution via WSL is the recommended method

0. Try installing Codex CLI without using a WSL environment (Updated 2025/08/29)

According to recent updates, it works stably even without a WSL environment.
Open PowerShell and install Codex using the following command:

$ npm install -g @openai/codex@latest
added 1 package in 2s
npm notice
npm notice New major version of npm available! 10.9.3 -> 11.5.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.5.2
npm notice To update run: npm install -g npm@11.5.2
npm notice

If the version is displayed after running the following command, it is OK.
For subsequent steps, refer to the later section.

$ codex --version
codex-cli 0.20.0

1. Installing WSL on Windows 11

※ These steps are for when Codex CLI could not be installed without a WSL environment.

This section introduces the procedure for installing WSL on Windows 11.
If you have already installed it, proceed to "2. Install nvm/node.js in the WSL environment".

■ Preparation 1: Add the compatibility layer for running Linux kernel to Windows

Launch PowerShell as "Run as administrator".
Execute the following command:

$ dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  • Feature name: Microsoft-Windows-Subsystem-Linux
  • Role: Installs and enables the WSL functionality itself on Windows.
    • /all: Option to also enable dependent features together.
    • /norestart: Specifies not to automatically reboot after enabling

Without this, the wsl command itself cannot be used.

■ Preparation 2: Enable the virtualization platform

Execute the following command.
After the command executes, restart your computer.

$ dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  • Feature name: VirtualMachinePlatform
  • Role: Enables the virtualization platform (like a lightweight version of Hyper-V).
  • If not executed, the following error appeared:
$ wsl --install
Error code: Wsl/InstallDistro/Service/RegisterDistro/CreateVm/HCS/HCS_E_SERVICE_NOT_AVAILABLE

■ Installing WSL

Install WSL with the following command.
After installation, you will be prompted to register a password.

$ wsl --install
Downloading: Ubuntu
Installing: Ubuntu
Distribution installed successfully. Can be started using 'wsl.exe -d Ubuntu'
Starting Ubuntu...
Provisioning the new WSL instance Ubuntu
This might take a while...
Create a default Unix user account: is0383kk
New password:
Retype new password:
passwd: password updated successfully
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

[Notes] If you want to choose a different distribution

By default, WSL2 and Ubuntu are installed.
If you want to use a different distribution, you can specify it with an option like this:

wsl --install -d Debian

■ Start Ubuntu using WSL

You can start it with the following command:

wsl.exe -d Ubuntu

2. Install nvm/node.js in the WSL environment

This section introduces the procedure for installing nvm/node.js in the WSL environment.
If you have already installed them, proceed to "3. Install Codex CLI".

■ Installing nvm

To install node.js, first install nvm.
Please run this on the WSL terminal

Install curl with the following command:

$ sudo apt-get install curl

Install nvm with the following command:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16631  100 16631    0     0  71634      0 --:--:-- --:--:-- --:--:-- 71685
=> Downloading nvm from git to '/home/hoge/.nvm'
=> Cloning into '/home/hoge/.nvm'...
remote: Enumerating objects: 383, done.
remote: Counting objects: 100% (383/383), done.
remote: Compressing objects: 100% (326/326), done.
remote: Total 383 (delta 43), reused 178 (delta 29), pack-reused 0 (from 0)
Receiving objects: 100% (383/383), 392.12 KiB | 8.17 MiB/s, done.
Resolving deltas: 100% (43/43), done.
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/hoge/.bashrc
=> Appending bash_completion source string to /home/hoge/.bashrc
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:

C:\Users\hoge\AppData\Roaming\nvm\v22.16.0
+-- @openai/codex@0.20.0
+-- corepack@0.32.0
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` node installs), you can remove them from the system Node as follows:

     $ nvm use system
     $ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

■ Reflect environment variables

After installation, reflect the nvm environment variables with the following command:

source ~/.bashrc

■ Verify nvm operation

Check if the nvm command can be executed:

$ nvm --version

0.40.3

*If the following is displayed, the environment variables may not be reflected:

$ nvm --version
Command 'nvm' not found, did you mean:
  command 'lvm' from deb lvm2 (2.03.16-3ubuntu3.2)
  command 'nvme' from deb nvme-cli (2.8-1ubuntu0.1)
  command 'kvm' from deb qemu-system-x86 (1:8.2.2+ds-0ubuntu1.6)
  command 'nm' from deb binutils (2.42-4ubuntu2.4)
Try: sudo apt install <deb name>

■ Install node.js

Install the LTS release of node.js with the following command:

$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v22.18.0...
Downloading https://nodejs.org/dist/v22.18.0/node-v22.18.0-linux-x64.tar.xz...
################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v22.18.0 (npm v10.9.3)
Creating default alias: default -> lts/* (-> v22.18.0)

After installation, check the installed node.js version:

$ node --version
v22.18.0

3. Install Codex CLI

This section explains the procedure for installing Codex CLI in the WSL environment.

■ Install Codex

Install Codex with the following command:

$ npm install -g @openai/codex
added 1 package in 2s
npm notice
npm notice New major version of npm available! 10.9.3 -> 11.5.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.5.2
npm notice To update run: npm install -g npm@11.5.2
npm notice

If the version is displayed after running the following command, it is OK:

$ codex --version
codex-cli 0.20.0

■ Codex CLI Model Access Settings

Configure model access to use Codex CLI.
You need to set one of the following:

  • Use an OpenAI API key
  • Log in with a ChatGPT plan

If you have an API key

Setup procedure if you own an OpenAI API key.

Open .bashrc with the following command:

$ vi ~/.bashrc

Set the API key with the following environment variable:

export OPENAI_API_KEY="Your API key"

After setting, reflect the environment variable with:

source ~/.bashrc

If logging in with a ChatGPT plan

Setup procedure if you have a Plus/Pro subscription for ChatGPT.

Running the following command will display a URL link:

$ codex login
Starting local login server on http://localhost:1455
. If your browser did not open, navigate to this URL to authenticate:

https://auth.openai.com/oauth/authorize?hogehoge
gio: https://auth.openai.com/oauth/authorize?hogehoge: Operation not supported

Copy the URL displayed on the terminal and paste it into a browser. The ChatGPT authentication screen will open.
Enter your username and password, then click "Continue" on the following screen:

After that, if the following screen appears, it is OK:

After successful authentication, the message "Successfully logged in" will appear on the WSL terminal.

■ Verify Codex CLI Operation

Let's verify that Codex CLI works.

Navigate to any directory and start Codex CLI with the following command:

$ codex

If the following choices appear, Codex CLI installation is complete:

  1. Allow Codex to work in this folder without asking for approval
    • Allows Codex to edit and execute commands in the target folder without user approval
  2. Require approval of edits and commands
    • You will be asked for approval each time an edit or command is executed
$ codex
> You are running Codex in /home/is0383kk/React-shadcn-pane-layouts

  Since this folder is version controlled, you may wish to allow Codex
  to work in this folder without asking for approval.

> 1. Yes, allow Codex to work in this folder without asking for approval
  2. No, ask me to approve edits and commands

Supplementary Information

Codex CLI Rate Limits

Summarized on the following page:
https://zenn.dev/is0383kk/articles/ac9e6895727fb0

Discussion