Skip to content

codex module: install fails with npm ENOTEMPTY on workspace restart (persistent npm prefix) #905

@turbotankist

Description

@turbotankist

Module

coder-labs/codex

Summary

On the first workspace build the Codex module installs fine. After a
workspace restart/rebuild (where the home directory / npm prefix is on a
persistent volume), the install script fails with npm error code ENOTEMPTY
and Codex is not (re)installed.

What happens

The install step runs npm install -g @openai/codex@latest. npm installs the
new version into a temp dir and then atomically renames it over the existing
@openai/codex directory. When a previous install already exists in the
persistent npm prefix (/home/coder/.npm-global), that rename fails because the
target directory is not empty.

Logs

Success
--------------------------------
codex_version: latest
workdir: /home/coder/project
enable_ai_gateway: false
install_codex: true
model_reasoning_effort: 
--------------------------------
\033[0;1m Installing Codex CLI
npm error code ENOTEMPTY
npm error syscall rename
npm error path /home/coder/.npm-global/lib/node_modules/@openai/codex
npm error dest /home/coder/.npm-global/lib/node_modules/@openai/.codex-zW1CjBX3
npm error errno -39
npm error ENOTEMPTY: directory not empty, rename '/home/coder/.npm-global/lib/node_modules/@openai/codex' -> '/home/coder/.npm-global/lib/node_modules/@openai/.codex-zW1CjBX3'
npm error A complete log of this run can be found in: /home/coder/.npm/_logs/2026-05-29T06_52_58_698Z-debug-0.log
Success

Workaround

Manually deleting the existing package directory makes the next install
succeed:
rm -rf /home/coder/.npm-global/lib/node_modules/@openai/codex

Expected behavior

The install script should be idempotent across restarts — installing or
upgrading Codex even when a prior install already exists in a persistent
npm prefix (e.g. remove the existing package dir before installing, skip the
install when the requested version is already present, or otherwise handle the
existing directory rather than failing).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions