From f754b19e80508bfd29f4fb643375a3a969315c8d Mon Sep 17 00:00:00 2001
From: miraclebakelaser <65143272+miraclebakelaser@users.noreply.github.com>
Date: Tue, 16 Dec 2025 08:30:06 +0900
Subject: [PATCH] Fix: Detect Bun global install via path check (#8004)
## Summary
Restores ability to detect when Codex is installed globally via **Bun**,
which was broken by c3e4f920b4e965085164d6ee0249a873ef96da77. Fixes
#8003.
Instead of relying on `npm_config_user_agent` (which is only set when
running via `bunx` or `bun run`), this adds a path-based check to see if
the CLI wrapper is located in Bun's global installation directory.
## Regression Context
Commit `c3e4f920b4e965085164d6ee0249a873ef96da77` removed the
`BUN_INSTALL` environment variable checks to prevent false positives.
However, this caused false negatives for genuine Bun global installs
because `detectPackageManager()` defaults to NPM when no signal is
found.
## Changes
- Updated `codex-cli/bin/codex.js` to check if `__dirname` contains
`.bun/install/global` (handles both POSIX and Windows paths).
## Verification
Verified by performing a global install of the patched CLI (v0.69.0 to
trigger the update prompt):
1. Packed the CLI using `npm pack` in `codex-cli/` to create a release
tarball.
2. Installed globally via Bun: `bun install -g
$(pwd)/openai-codex-0.0.0-dev.tgz`.
3. Ran `codex`, confirmed it detected Bun (banner showed `bun install -g
@openai/codex`), selected "Update now", and verified it correctly
spawned `bun install -g` instead of `npm`.
4. Confirmed the upgrade completed successfully using Bun.
5. Verified installations via npm are unaffected.
---
codex-cli/bin/codex.js | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/codex-cli/bin/codex.js b/codex-cli/bin/codex.js
index 138796e5d..6ec8069bd 100644
--- a/codex-cli/bin/codex.js
+++ b/codex-cli/bin/codex.js
@@ -95,6 +95,14 @@ function detectPackageManager() {
return "bun";
}
+
+ if (
+ __dirname.includes(".bun/install/global") ||
+ __dirname.includes(".bun\\install\\global")
+ ) {
+ return "bun";
+ }
+
return userAgent ? "npm" : null;
}