[bug] Can not uninstall completely Codex Multi Auth out of VS code
Summary
Describe the bug in one paragraph.
Reproduction
Expected Behavior
Describe the expected result.
Actual Behavior
Describe the observed result.
Environment
codex --version:codex auth statusoutput summary:codex auth rotation statusoutput summary, if runtime rotation is involved:npm ls -g codex-multi-auth:- OS:
- Node.js:
Diagnostic Outputs
Include relevant outputs from:
codex auth checkcodex auth report --jsoncodex auth doctor --json
Logs (Optional)
If needed, include sanitized logs from ~/.codex/multi-auth/logs/codex-plugin/.
Only enable logging temporarily: ENABLE_PLUGIN_REQUEST_LOGGING=1.
Compliance Confirmation
- [ ] I am using this project for personal development workflows.
- [ ] This report does not request policy bypasses or prohibited usage.
- [ ] I removed any secrets/tokens from this report.
Coding Plan
Summary
- create
scripts/preuninstall.jsas npm lifecycle hook calling existingunbindCodexAppRuntimeRotation()(lib/runtime/app-bind.ts:718) andinstallCodexAppLauncher({ remove: true })(scripts/codex-app-launcher.js:526) plus newremovePluginFromListutility for codex.json cleanup - add
codex-multi-auth uninstallcli command for manual cleanup of existing installs, followinglib/codex-manager/repair-commands.tspatterns - warn to stderr on partial failures but always exit 0 to avoid blocking npm uninstall
- missing regression coverage for windows shortcut restoration and concurrent uninstall scenarios needs explicit attention
Design Choices
Design Choice 1: should `preuninstall` be silent on errors like `postinstall` is?
Options Considered:
- silent exit 0 on all errors (matches postinstall behavior)
- warn to stderr but still exit 0 (user sees issues but npm uninstall succeeds)
- exit non-zero on critical failures (can block uninstall)
Chosen Option: 2
Rationale: option 2 — warn to stderr but exit 0. users deserve visibility into partial failures, but blocking npm uninstall entirely would be worse than leaving residual files.
Design Choice 2: should the cli `uninstall` command require `--confirm` flag?
Options Considered:
- require
--confirmor interactive prompt - support
--dry-runonly, execute by default - both
--dry-runand--confirmflags
Chosen Option: 2
Rationale: option 2 — match existing repair commands pattern. --dry-run shows what would happen; actual execution is default. keeps cli ergonomics consistent.
💡 User Tips
Regenerate the plan with different choices with @coderabbitai <feedback>.
Implementation Steps
Phase 1: Core Uninstall Infrastructure
create the preuninstall npm lifecycle script and the missing removePluginFromConfig utility. this phase wires together existing removal functions and adds the codex.json cleanup that doesn't exist today.
Task 1: Add `removePluginFromConfig` utility to `scripts/install-codex-auth-utils.js`
implement the inverse of normalizePluginList — a function that strips codex-multi-auth (and versioned variants) from the plugin array.
- add
removePluginFromList(list)function inscripts/install-codex-auth-utils.jsthat filters outcodex-multi-authandcodex-multi-auth@*entries from the array - export alongside existing
normalizePluginListso both install and uninstall paths share the same file matching logic - return empty array gracefully when plugin not found (idempotent)
Task 2: Create `scripts/preuninstall.js` npm lifecycle script
main uninstall orchestrator that reverses postinstall.js operations.
- create
scripts/preuninstall.jsfollowingpostinstall.jsstructure with exported testable pure functions - implement
runPreuninstallCleanup({ unbindCodexApp, removeLauncher, removePluginConfig, clearCache, log, env })as main orchestrator - call
unbindCodexAppRuntimeRotation()fromlib/runtime/app-bind.tsto restore config.toml and kill router - call
installCodexAppLauncher({ remove: true })fromscripts/codex-app-launcher.jsto remove os launchers - load and rewrite
Codex.jsonusingremovePluginFromListto strip plugin entry - call existing
clearCache()fromscripts/install-codex-auth.jsto remove~/.cache/Codex/node_modules/codex-multi-authandbun.lock - wrap each operation in try/catch, log warnings to stderr on failure, always exit 0
- respect
--dry-runflag for testing - skip operations when running in ci (check
isCiEnvironment()from postinstall)
Task 3: Wire `preuninstall` into `package.json`
register the npm lifecycle hook.
- add
"preuninstall": "node scripts/preuninstall.js"topackage.jsonscripts section alongside existingpostinstall
🤖 Prompt for AI agents
implement the core uninstall infrastructure by adding a `removePluginFromList`
utility and a `preuninstall.js` lifecycle script that reverses all
`postinstall.js` operations. the goal is to ensure `npm uninstall -g` leaves no
residual artifacts.
**task 1: add `removePluginFromList` to `scripts/install-codex-auth-utils.js`**
- add a `removePluginFromList(list)` function that filters out
`codex-multi-auth` and `codex-multi-auth@*` (versioned variants) from the input
array
- export it alongside the existing `normalizePluginList` export so both install
and uninstall paths share the same file
- make it idempotent — return empty array gracefully when the plugin is not
present
**task 2: create `scripts/preuninstall.js`**
- mirror the structure of `postinstall.js` — export testable pure functions,
with a `runPreuninstallCleanup({ unbindCodexApp, removeLauncher,
removePluginConfig, clearCache, log, env })` as the main orchestrator
- inside the orchestrator, call these in sequence:
- `unbindCodexAppRuntimeRotation()` from `lib/runtime/app-bind.ts:718` to
restore config.toml and kill the router
- `installCodexAppLauncher({ remove: true })` from
`scripts/codex-app-launcher.js:526` to remove os launchers
- load and rewrite `Codex.json` using `removePluginFromList` to strip the plugin
entry
- `clearCache()` from `scripts/install-codex-auth.js` to remove
`~/.cache/Codex/node_modules/codex-multi-auth` and `bun.lock`
- wrap each operation in its own try/catch — log warnings to stderr on failure,
always exit 0 (never block uninstall)
- support a `--dry-run` flag that logs what would happen without executing
destructive operations
- skip all destructive operations in ci environments by checking
`isCiEnvironment()` (same helper used in postinstall)
**task 3: wire into `package.json`**
- add `"preuninstall": "node scripts/preuninstall.js"` to the `scripts` section
of `package.json`, alongside the existing `postinstall` entry
Phase 2: CLI uninstall Command
add manual cleanup command for users who already have residual artifacts from prior installs (before preuninstall hook existed).
Task 1: Create `lib/codex-manager/commands/uninstall.ts`
implement the cli command following repair-commands.ts patterns.
- define
UninstallCommandDepsinterface with deps for storage clearing, file operations, and console output - implement
parseUninstallArgs(args)supporting--dry-run,--json,--helpflags - implement
runUninstallCommand(args, deps)that:- calls
unbindCodexAppRuntimeRotation()to reverse app bind - calls launcher removal logic
- removes plugin from
Codex.json - clears plugin cache
- optionally clears account storage via
clearAccounts()dep (with--clear-accountsflag, off by default)
- calls
- output human-readable summary of removed artifacts (or json with
--json) - return 0 on success, 1 on partial failure with warnings
Task 2: Wire `uninstall` command into CLI dispatcher
register the command in the main cli.
- add
"uninstall"toACCOUNT_MANAGER_COMMANDSset inlib/codex-manager.ts:195 - add
if (command === "uninstall")branch inrunCodexMultiAuthCli()around line 3500 (near other repair commands) - import
runUninstallCommandfrom./codex-manager/commands/uninstall.js - add entry to
lib/codex-manager/help.tsunder theRepair:section
🤖 Prompt for AI agents
implement the `codex-multi-auth uninstall` cli command for manual cleanup of
residual artifacts from prior installs, following the `RepairCommandDeps`
pattern in `lib/codex-manager/repair-commands.ts`.
**task 1: create `lib/codex-manager/commands/uninstall.ts`**
- define a `UninstallCommandDeps` interface with deps for storage clearing, file
operations, and console output — mirror the shape of existing deps interfaces in
`lib/codex-manager/repair-commands.ts`
- implement `parseUninstallArgs(args)` supporting `--dry-run`, `--json`, and
`--help` flags
- implement `runUninstallCommand(args, deps)` that:
- calls `unbindCodexAppRuntimeRotation()` (`lib/runtime/app-bind.ts:718`) to
reverse app bind
- calls launcher removal logic (`scripts/codex-app-launcher.js:526`)
- removes plugin from `Codex.json` using `removePluginFromList`
- clears plugin cache
- optionally clears account storage via a `clearAccounts()` dep, gated behind
`--clear-accounts` flag (off by default)
- output a human-readable summary of removed artifacts; switch to structured
json output when `--json` is passed
- return exit code 0 on success, 1 on partial failure with warnings printed
**task 2: wire into the cli dispatcher in `lib/codex-manager.ts`**
- add `"uninstall"` to the `ACCOUNT_MANAGER_COMMANDS` set at
`lib/codex-manager.ts:195`
- add an `if (command === "uninstall")` branch in `runCodexMultiAuthCli()`
around line 3500, near the other repair command branches
- import `runUninstallCommand` from `./codex-manager/commands/uninstall.js`
- add a help entry in `lib/codex-manager/help.ts` under the `Repair:` section
Phase 3: Tests
add regression tests covering the new uninstall paths. flag: missing tests for windows shortcut restoration and concurrent uninstall.
Task 1: Add unit tests for `removePluginFromList`
test the new utility function.
- add tests in
test/install-codex-auth.test.tsalongside existingnormalizePluginListtests - verify removal of
codex-multi-auth,[email protected], mixed lists, already-absent entries - verify other plugins are preserved
Task 2: Add tests for `preuninstall.js`
test the npm lifecycle script using same patterns as test/install-codex-auth.test.ts.
- add tests in new
test/preuninstall.test.tsfollowing patterns fromtest/install-codex-auth.test.ts:565 - test with injected mocks for
unbindCodexApp,removeLauncher,logdeps - test
--dry-runmode does not delete files (use temp directories) - test partial failure (one op throws) still continues and exits 0
- test ci environment skips destructive operations
- flag: need windows-specific tests for shortcut restoration path in
scripts/codex-app-launcher.js— currently untested
Task 3: Add tests for `uninstall` CLI command
test the manual cli command.
- add tests in
test/codex-manager-uninstall.test.ts - test
--dry-runreports artifacts without removing - test
--jsonoutput format - test
--clear-accountsflag clears storage - test idempotent behavior (running twice does not error)
- flag: need concurrency test — two simultaneous
uninstallcommands should not corrupt state. usePromise.allpattern fromtest/install-codex-auth.test.ts:100
🤖 Prompt for AI agents
add regression tests for all new uninstall paths. explicitly call out missing
coverage for windows shortcut restoration and concurrent uninstall scenarios.
**task 1: unit tests for `removePluginFromList` in
`test/install-codex-auth.test.ts`**
- add tests alongside existing `normalizePluginList` tests
- cover: removal of bare `codex-multi-auth`, versioned `[email protected]`,
mixed plugin lists, already-absent entries (idempotent), and preservation of
unrelated plugins
**task 2: tests for `scripts/preuninstall.js` in `test/preuninstall.test.ts`**
- follow patterns from `test/install-codex-auth.test.ts:565`
- inject mocks for `unbindCodexApp`, `removeLauncher`, `log` deps
- test `--dry-run` mode: use temp directories to assert no files are deleted
- test partial failure: one operation throws, rest continue, final exit code is
0
- test ci environment: assert destructive operations are skipped when
`isCiEnvironment()` returns true
- **flag:** windows-specific tests for shortcut restoration in
`scripts/codex-app-launcher.js` are missing and need to be added
**task 3: tests for the cli uninstall command in
`test/codex-manager-uninstall.test.ts`**
- test `--dry-run` reports artifacts without removing them
- test `--json` output is valid structured json
- test `--clear-accounts` flag triggers `clearAccounts()` dep
- test idempotent behavior: running `uninstall` twice does not error
- **flag:** add a concurrency test using `Promise.all` (see
`test/install-codex-auth.test.ts:100`) — two simultaneous `uninstall` commands
must not corrupt state
Research
the project uses scripts/postinstall.js to auto-bind the codex desktop app and install os-level launchers on global npm install. removal logic already exists:
unbindCodexAppRuntimeRotation()inlib/runtime/app-bind.ts:718reverses config.toml changes and kills the routerinstallCodexAppLauncher({ remove: true })inscripts/codex-app-launcher.js:526removes launcher files and restores windows shortcuts
however, neither is wired into any npm lifecycle hook, and there's no utility to strip the codex-multi-auth entry from Codex.json. cli commands follow the RepairCommandDeps pattern in lib/codex-manager/repair-commands.ts and are dispatched via ACCOUNT_MANAGER_COMMANDS set in lib/codex-manager.ts:195.
🚀 Next Steps
🤖 All AI agent prompts combined
Task: 1
implement the core uninstall infrastructure by adding a `removePluginFromList`
utility and a `preuninstall.js` lifecycle script that reverses all
`postinstall.js` operations. the goal is to ensure `npm uninstall -g` leaves no
residual artifacts.
**task 1: add `removePluginFromList` to `scripts/install-codex-auth-utils.js`**
- add a `removePluginFromList(list)` function that filters out
`codex-multi-auth` and `codex-multi-auth@*` (versioned variants) from the input
array
- export it alongside the existing `normalizePluginList` export so both install
and uninstall paths share the same file
- make it idempotent — return empty array gracefully when the plugin is not
present
**task 2: create `scripts/preuninstall.js`**
- mirror the structure of `postinstall.js` — export testable pure functions,
with a `runPreuninstallCleanup({ unbindCodexApp, removeLauncher,
removePluginConfig, clearCache, log, env })` as the main orchestrator
- inside the orchestrator, call these in sequence:
- `unbindCodexAppRuntimeRotation()` from `lib/runtime/app-bind.ts:718` to
restore config.toml and kill the router
- `installCodexAppLauncher({ remove: true })` from
`scripts/codex-app-launcher.js:526` to remove os launchers
- load and rewrite `Codex.json` using `removePluginFromList` to strip the plugin
entry
- `clearCache()` from `scripts/install-codex-auth.js` to remove
`~/.cache/Codex/node_modules/codex-multi-auth` and `bun.lock`
- wrap each operation in its own try/catch — log warnings to stderr on failure,
always exit 0 (never block uninstall)
- support a `--dry-run` flag that logs what would happen without executing
destructive operations
- skip all destructive operations in ci environments by checking
`isCiEnvironment()` (same helper used in postinstall)
**task 3: wire into `package.json`**
- add `"preuninstall": "node scripts/preuninstall.js"` to the `scripts` section
of `package.json`, alongside the existing `postinstall` entry
===============================================================================
Task: 2
implement the `codex-multi-auth uninstall` cli command for manual cleanup of
residual artifacts from prior installs, following the `RepairCommandDeps`
pattern in `lib/codex-manager/repair-commands.ts`.
**task 1: create `lib/codex-manager/commands/uninstall.ts`**
- define a `UninstallCommandDeps` interface with deps for storage clearing, file
operations, and console output — mirror the shape of existing deps interfaces in
`lib/codex-manager/repair-commands.ts`
- implement `parseUninstallArgs(args)` supporting `--dry-run`, `--json`, and
`--help` flags
- implement `runUninstallCommand(args, deps)` that:
- calls `unbindCodexAppRuntimeRotation()` (`lib/runtime/app-bind.ts:718`) to
reverse app bind
- calls launcher removal logic (`scripts/codex-app-launcher.js:526`)
- removes plugin from `Codex.json` using `removePluginFromList`
- clears plugin cache
- optionally clears account storage via a `clearAccounts()` dep, gated behind
`--clear-accounts` flag (off by default)
- output a human-readable summary of removed artifacts; switch to structured
json output when `--json` is passed
- return exit code 0 on success, 1 on partial failure with warnings printed
**task 2: wire into the cli dispatcher in `lib/codex-manager.ts`**
- add `"uninstall"` to the `ACCOUNT_MANAGER_COMMANDS` set at
`lib/codex-manager.ts:195`
- add an `if (command === "uninstall")` branch in `runCodexMultiAuthCli()`
around line 3500, near the other repair command branches
- import `runUninstallCommand` from `./codex-manager/commands/uninstall.js`
- add a help entry in `lib/codex-manager/help.ts` under the `Repair:` section
===============================================================================
Task: 3
add regression tests for all new uninstall paths. explicitly call out missing
coverage for windows shortcut restoration and concurrent uninstall scenarios.
**task 1: unit tests for `removePluginFromList` in
`test/install-codex-auth.test.ts`**
- add tests alongside existing `normalizePluginList` tests
- cover: removal of bare `codex-multi-auth`, versioned `[email protected]`,
mixed plugin lists, already-absent entries (idempotent), and preservation of
unrelated plugins
**task 2: tests for `scripts/preuninstall.js` in `test/preuninstall.test.ts`**
- follow patterns from `test/install-codex-auth.test.ts:565`
- inject mocks for `unbindCodexApp`, `removeLauncher`, `log` deps
- test `--dry-run` mode: use temp directories to assert no files are deleted
- test partial failure: one operation throws, rest continue, final exit code is
0
- test ci environment: assert destructive operations are skipped when
`isCiEnvironment()` returns true
- **flag:** windows-specific tests for shortcut restoration in
`scripts/codex-app-launcher.js` are missing and need to be added
**task 3: tests for the cli uninstall command in
`test/codex-manager-uninstall.test.ts`**
- test `--dry-run` reports artifacts without removing them
- test `--json` output is valid structured json
- test `--clear-accounts` flag triggers `clearAccounts()` dep
- test idempotent behavior: running `uninstall` twice does not error
- **flag:** add a concurrency test using `Promise.all` (see
`test/install-codex-auth.test.ts:100`) — two simultaneous `uninstall` commands
must not corrupt state
💡 Iterate on the plan with:
@coderabbitai <feedback>
Example Feedback
- @coderabbitai You can skip phase 3. Add a simple unit test case for phase 2.
- @coderabbitai For design choice 1 go ahead with option 3 and replan.
💬 Have feedback or questions? Drop into our discord!
I've updated the plan above based on your feedback. Ready to proceed when you are!
I've updated the plan above based on your feedback. Ready to proceed when you are!