背景
OpenAI の Codex CLI は、当初 macOS / Linux のみ公式サポートでした。
Windows 環境では WSL (Windows Subsystem for Linux) を使うことが推奨されていて、ドキュメントにも「Windows は experimental(実験的)」と書かれていました。
ところが最近になって、海外のブログやコミュニティで
「WSL なしでも Windows ネイティブで Codex CLI が動いた」という記事やツイートを目にするようになりました。
そこで自分も Windows ネイティブで試してみたのですが、実際には npm install -g @openai/codex
で下記のようなエラーに遭遇しました。
npm error command failed
npm error path C:\Users\<user>\AppData\Roaming\npm\node_modules\@openai\codex\node_modules\@vscode\ripgrep
npm error [Error: EPERM: operation not permitted, rmdir ...]
npm error [Error: ENOENT: no such file or directory, mkdir ...\ripgrep\tmp\vscode-ripgrep-cache-...]
これは @vscode/ripgrep
の postinstall スクリプトが Windows の Roaming\npm
配下で失敗しているのが原因です。
(VS Code や OneDrive、ウイルス対策ソフトがフォルダをロックしていることも多い)
この記事では、Windows ネイティブで Codex CLI を入れるために行った対処法を残しておきます。
対処法
1. 作業前準備
VS Code / Node / Git Bash などを全部終了してから開始。
taskkill /f /im Code.exe /im node.exe /im git-bash.exe 2>$null
2. npm のグローバル先を変更
Roaming 配下はトラブルの温床なので、専用ディレクトリを用意する。
mkdir C:\npm-global -ea 0
mkdir C:\npm-cache -ea 0
mkdir C:\npm-tmp -ea 0
npm config set prefix "C:\npm-global"
npm config set cache "C:\npm-cache"
※
npm config set tmp
は v9 以降廃止。代わりに OS 環境変数を設定する。
3. TEMP/TMP をユーザー環境変数で上書き
[Environment]::SetEnvironmentVariable('TEMP','C:\npm-tmp','User')
[Environment]::SetEnvironmentVariable('TMP','C:\npm-tmp','User')
$env:TEMP='C:\npm-tmp'
$env:TMP ='C:\npm-tmp'
確認:
$env:TEMP
$env:TMP
4. 残骸を掃除
Remove-Item -LiteralPath "$env:APPDATA\npm\node_modules\@openai\codex" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath "$env:APPDATA\npm\node_modules\@vscode" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath "$env:APPDATA\npm-cache" -Recurse -Force -ErrorAction SilentlyContinue
npm cache clean --force
5. ripgrep を事前にインストール(推奨)
winget install BurntSushi.ripgrep
rg --version
6. Codex CLI をインストール
npm install -g @openai/codex --unsafe-perm --foreground-scripts
codex --version
🔧 それでもダメなとき
-
--ignore-scripts
を付けて ripgrep の postinstall をスキップし、PATH 上のrg
を利用:npm install -g @openai/codex --ignore-scripts
-
直近のエラーログは
C:\npm-cache\_logs\...-debug-0.log
にあるので、末尾を確認。
🎯 まとめ
-
Codex CLI は本来 macOS / Linux 向けに設計され、Windows では WSL が推奨されてきました。
-
最近は「Windows ネイティブで動く」という記事も見かけますが、実際に試すと npm / ripgrep 周りでエラーに遭遇しがちです。
-
今回紹介したように npm のグローバル先を Roaming から避ける + TEMP/TMP を専用フォルダに切り替える + ripgrep を事前導入する ことで、Windows 単体でもインストールが可能でした。
-
「WSL を入れるのはちょっと大げさだけど、Windows 上で Codex CLI を触ってみたい」という人の参考になれば幸いです。