Skip to content

Detect Codex installs managed by pnpm#31503

Open
charliemarsh-oai wants to merge 9 commits into
mainfrom
charlie/fix-pnpm-install-detection
Open

Detect Codex installs managed by pnpm#31503
charliemarsh-oai wants to merge 9 commits into
mainfrom
charlie/fix-pnpm-install-detection

Conversation

@charliemarsh-oai

@charliemarsh-oai charliemarsh-oai commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Why

The Codex JavaScript shim currently distinguishes npm and Bun installs, but a global pnpm install falls back to npm. That causes the native CLI, codex doctor, and update flows to report or run npm commands even though pnpm owns the installation. pnpm also allows its global package and bin directories to differ, so PNPM_HOME does not reliably identify the package owner.

What changed

  • detect pnpm-managed installs by finding pnpm's node_modules/.modules.yaml metadata from the launched JavaScript entrypoint
  • pass a mutually exclusive CODEX_MANAGED_BY_PNPM marker into the native CLI
  • represent pnpm in install context, doctor output, version checks, and TUI update actions without changing the existing public InstallContext::from_exe signature
  • recommend pnpm add -g @openai/codex for pnpm-managed installs and snapshot the rendered TUI update notice

Validated with the 9-test install-context suite, the focused pnpm TUI snapshot test, and Node's syntax check for the launcher.

@charliemarsh-oai charliemarsh-oai marked this pull request as ready for review July 8, 2026 02:05
Comment thread codex-cli/bin/codex.js Outdated
{
"bun": "CODEX_MANAGED_BY_BUN",
"pnpm": "CODEX_MANAGED_BY_PNPM",
}[detectPackageManager()] ?? "CODEX_MANAGED_BY_NPM";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex is there a better way to do this that's less ugly?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha. We can do a nested ternary?

Comment thread codex-cli/bin/codex.js Outdated
Comment on lines +123 to +124
// pnpm records installation metadata in node_modules/.modules.yaml. Search
// the canonical package root and lexical entrypoint because either can be

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex i'm a bit worried about this while(true) and traversal through a potentially deepish directory, is there no better way to distinguish pnpm from npm?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Replaced the unbounded while (true) parent-directory walk in pnpm detection with a bounded scan of node_modules roots derived from the resolved Codex package paths. codex-cli/bin/codex.jsL123-L140
  • Kept the pnpm ownership guard intact by requiring .modules.yaml and verifying that node_modules/@openai/codex resolves to the current Codex package root before returning pnpm. codex-cli/bin/codex.jsL142-L156
  • Committed the follow-up change as 68aa389a314224d0697958b8150ec689b456ea83 and created the follow-up PR titled “Bound pnpm owner detection in CLI shim.”

Testing

  • node --check codex-cli/bin/codex.js && prettier --check codex-cli/bin/codex.js && git diff --check
  • ⚠️ cd codex-rs && just fmt (failed due environment/tooling limits: missing dotslash, plus Python formatter dependencies could not be downloaded through the proxy)

View task →

Other,
}

enum ManagedPackageManager {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why do we have to introduce a new type here since we already have the InstallContext? Maybe would be better to impl some is_managed method on InstallMethod if that data is needed?

Comment thread codex-cli/bin/codex.js
CODEX_MANAGED_PACKAGE_ROOT: realpathSync(path.join(__dirname, "..")),
CODEX_MANAGED_PACKAGE_ROOT: codexPackageRoot,
};
delete env.CODEX_MANAGED_BY_NPM;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to delete the env variables newly?

)
}

fn from_exe_with_package_manager_and_codex_home(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we dont introduce ManagedPackageManager type we might not need the new function/scaffolding here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants