@wen2go/codex-auth-ext 0.3.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-PRESENT Loongphy<https://github.com/loongphy>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # Codex Auth Ext
2
+
3
+ ![command list](https://github.com/user-attachments/assets/6c13a2d6-f9da-47ea-8ec8-0394fc072d40)
4
+
5
+ `codex-auth` is a command-line tool for switching Codex accounts.
6
+
7
+ ## Fork Notice
8
+
9
+ This repository is a second-development fork of [Loongphy/codex-auth](https://github.com/Loongphy/codex-auth).
10
+
11
+ This fork adds:
12
+
13
+ - Alias-first account labels in `codex-auth list`, so accounts with an alias render as `alias(email)`.
14
+ - `codex-auth login --alias <alias>` for assigning an alias while adding a new account.
15
+ - `codex-auth set-alias <selector> <alias>` as a shortcut for updating an existing account alias.
16
+ - A local npm packaging helper, `npm run pack:local`, for building an installable package from the current platform binary.
17
+
18
+ > [!IMPORTANT]
19
+ > For **Codex CLI** and **Codex App** users, switch accounts, then restart the client for the new account to take effect.
20
+ >
21
+ > If you use the CLI and want seamless automatic account switching without restarting, use the forked [`codext`](https://github.com/Loongphy/codext), an enhanced Codex CLI. Install it with `npm i -g @loongphy/codext` and run `codext`.
22
+
23
+ ## Supported Platforms
24
+
25
+ `codex-auth` works with these Codex clients:
26
+
27
+ - Codex CLI
28
+ - VS Code extension
29
+ - Codex App
30
+
31
+ For the best experience, install the Codex CLI even if you mainly use the VS Code extension or the App, because it makes adding accounts easier:
32
+
33
+ ```shell
34
+ npm install -g @openai/codex
35
+ ```
36
+
37
+ After that, you can use `codex login`, `codex login --device-auth`, `codex-auth login`, or `codex-auth login --device-auth` to sign in and add accounts more easily.
38
+
39
+ ## Install
40
+
41
+ Install with npm:
42
+
43
+ ```shell
44
+ npm install -g @wen2go/codex-auth-ext
45
+ ```
46
+
47
+ You can also run it without a global install:
48
+
49
+ ```shell
50
+ npx @wen2go/codex-auth-ext list
51
+ ```
52
+
53
+ npm packages currently support Linux x64, Linux arm64, macOS x64, macOS arm64, Windows x64, and Windows arm64.
54
+
55
+ ### Uninstall
56
+
57
+ #### npm
58
+
59
+ Remove the npm package:
60
+
61
+ ```shell
62
+ npm uninstall -g @wen2go/codex-auth-ext
63
+ ```
64
+
65
+ ## Commands
66
+
67
+ Detailed command documentation lives in [docs/commands/README.md](./docs/commands/README.md).
68
+
69
+ ### Account Management
70
+
71
+ | Command | Description |
72
+ |---------|-------------|
73
+ | [`codex-auth list [--live] [--active] [--api\|--skip-api]`](./docs/commands/list.md) | List stored accounts and usage state |
74
+ | [`codex-auth login [--device-auth] [--alias <alias>]`](./docs/commands/login.md) | Run `codex login`, then add the current account |
75
+ | [`codex-auth switch [--live] [--api\|--skip-api]`](./docs/commands/switch.md) | Switch the active account interactively |
76
+ | [`codex-auth switch <query>`](./docs/commands/switch.md) | Switch directly by row number or account selector |
77
+ | [`codex-auth remove [--live] [--api\|--skip-api]`](./docs/commands/remove.md) | Remove accounts interactively |
78
+ | [`codex-auth remove <query> [<query>...]`](./docs/commands/remove.md) | Remove accounts by selector |
79
+ | [`codex-auth remove --all`](./docs/commands/remove.md) | Remove all stored accounts |
80
+ | [`codex-auth set-alias <query> <alias>`](./docs/commands/alias.md) | Set or update an account alias |
81
+
82
+ ### Import and Maintenance
83
+
84
+ | Command | Description |
85
+ |---------|-------------|
86
+ | [`codex-auth import <path> [--alias <alias>]`](./docs/commands/import.md) | Import a single auth file or batch import a folder |
87
+ | [`codex-auth import --cpa [<path>]`](./docs/commands/import.md) | Import CLIProxyAPI token JSON |
88
+ | [`codex-auth import --purge [<path>]`](./docs/commands/import.md) | Rebuild `registry.json` from auth files |
89
+ | [`codex-auth export [<dir>]`](./docs/commands/export.md) | Export stored account auth files |
90
+ | [`codex-auth export --cpa [<dir>]`](./docs/commands/export.md) | Export CLIProxyAPI token JSON |
91
+ | [`codex-auth clean`](./docs/commands/clean.md) | Delete managed backup and stale account files |
92
+
93
+ ### Configuration
94
+
95
+ | Command | Description |
96
+ |---------|-------------|
97
+ | [`codex-auth config live --interval <seconds>`](./docs/commands/config.md) | Configure live TUI refresh interval |
98
+
99
+ ## Quick Examples
100
+
101
+ ```shell
102
+ codex-auth list
103
+ codex-auth list --active
104
+ codex-auth switch
105
+ codex-auth switch 02
106
+ codex-auth remove work
107
+ codex-auth login --alias personal
108
+ codex-auth set-alias 02 work
109
+ codex-auth import /path/to/auth.json --alias personal
110
+ codex-auth list --skip-api
111
+ ```
112
+
113
+ ## Q&A
114
+
115
+ ### Why is my usage limit not refreshing?
116
+
117
+ API-backed refresh is the default. When you pass `--skip-api`, `codex-auth` reads the newest `~/.codex/sessions/**/rollout-*.jsonl` file instead. Recent Codex builds often write `token_count` events with `rate_limits: null`. The local files may still contain older usable usage limit data, but in practice they can lag by several hours, so local-only refresh may show a usage limit snapshot from hours ago instead of your latest state.
118
+
119
+ - Upstream Codex issue: [openai/codex#14880](https://github.com/openai/codex/issues/14880)
120
+
121
+ Run the API-backed default with:
122
+
123
+ ```shell
124
+ codex-auth list
125
+ ```
126
+
127
+ Run one local-only command with:
128
+
129
+ ```shell
130
+ codex-auth list --skip-api
131
+ ```
132
+
133
+ Verify with:
134
+
135
+ ```shell
136
+ codex exec "say hello"
137
+ ```
138
+
139
+ ## Disclaimer
140
+
141
+ This project is provided as-is and use is at your own risk.
142
+
143
+ **Usage Data Refresh Source:**
144
+ `codex-auth` supports two sources for refreshing account usage/usage limit information:
145
+
146
+ 1. **API (default):** The tool makes direct HTTPS requests to OpenAI's endpoints using your account's access token. This enables both usage refresh and team name refresh. npm installs already satisfy the runtime requirement.
147
+ 2. **Local-only:** With per-command `--skip-api`, the tool scans local `~/.codex/sessions/*/rollout-*.jsonl` files for usage data and skips team name refresh API calls. This mode is safer, but it can be less accurate because recent Codex rollout files often contain `rate_limits: null`, so the latest local usage limit data may lag by several hours.
148
+
149
+ **API Call Declaration:**
150
+ By using the default API-backed refresh, this tool will send your ChatGPT access token to OpenAI's servers, including `https://chatgpt.com/backend-api/wham/usage` for usage limit and `https://chatgpt.com/backend-api/accounts/check/v4-2023-04-27` for team name. This behavior may be detected by OpenAI and could violate their terms of service, potentially leading to account suspension or other risks. The decision to use this feature and any resulting consequences are entirely yours.
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import { createRequire } from "node:module";
6
+ import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ const require = createRequire(import.meta.url);
12
+ const rootPackageJsonPath = path.join(__dirname, "..", "package.json");
13
+ const requiredNodeMajor = 22;
14
+
15
+ function ensureSupportedNodeVersion() {
16
+ const major = Number(process.versions?.node?.split(".")[0] ?? 0);
17
+ if (Number.isInteger(major) && major >= requiredNodeMajor) {
18
+ return;
19
+ }
20
+
21
+ console.error(
22
+ `Node.js ${requiredNodeMajor}+ is required to run @wen2go/codex-auth-ext. Current version: ${process.version}.`
23
+ );
24
+ process.exit(1);
25
+ }
26
+
27
+ ensureSupportedNodeVersion();
28
+
29
+ const packageMap = {
30
+ "linux:x64": "@wen2go/codex-auth-ext-linux-x64",
31
+ "linux:arm64": "@wen2go/codex-auth-ext-linux-arm64",
32
+ "darwin:x64": "@wen2go/codex-auth-ext-darwin-x64",
33
+ "darwin:arm64": "@wen2go/codex-auth-ext-darwin-arm64",
34
+ "win32:x64": "@wen2go/codex-auth-ext-win32-x64",
35
+ "win32:arm64": "@wen2go/codex-auth-ext-win32-arm64"
36
+ };
37
+
38
+ function readRootPackage() {
39
+ try {
40
+ return JSON.parse(fs.readFileSync(rootPackageJsonPath, "utf8"));
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+
46
+ function maybePrintPreviewVersion(argv) {
47
+ if (argv.length !== 1) return false;
48
+ if (argv[0] !== "--version" && argv[0] !== "-V") return false;
49
+
50
+ const rootPackage = readRootPackage();
51
+ if (!rootPackage) return false;
52
+
53
+ const previewLabel = rootPackage.codexAuthPreviewLabel;
54
+ if (typeof previewLabel !== "string" || previewLabel.length === 0) return false;
55
+ if (typeof rootPackage.version !== "string" || rootPackage.version.length === 0) return false;
56
+
57
+ process.stdout.write(`codex-auth ${rootPackage.version} (preview ${previewLabel})\n`);
58
+ return true;
59
+ }
60
+
61
+ if (maybePrintPreviewVersion(process.argv.slice(2))) {
62
+ process.exit(0);
63
+ }
64
+
65
+ function resolveBinary() {
66
+ const key = `${process.platform}:${process.arch}`;
67
+ const packageName = packageMap[key];
68
+ if (!packageName) {
69
+ console.error(`Unsupported platform: ${process.platform}/${process.arch}`);
70
+ process.exit(1);
71
+ }
72
+
73
+ try {
74
+ const packageRoot = path.dirname(require.resolve(`${packageName}/package.json`));
75
+ const binaryName = process.platform === "win32" ? "codex-auth.exe" : "codex-auth";
76
+ const binaryPath = path.join(packageRoot, "bin", binaryName);
77
+ if (!fs.existsSync(binaryPath)) {
78
+ console.error(`Missing binary inside ${packageName}: ${binaryPath}`);
79
+ process.exit(1);
80
+ }
81
+ return binaryPath;
82
+ } catch (error) {
83
+ console.error(
84
+ `Missing platform package ${packageName}. Reinstall @wen2go/codex-auth-ext on ${process.platform}/${process.arch}.`
85
+ );
86
+ if (error && error.message) {
87
+ console.error(error.message);
88
+ }
89
+ process.exit(1);
90
+ }
91
+ }
92
+
93
+ const binaryPath = resolveBinary();
94
+ const child = spawnSync(binaryPath, process.argv.slice(2), {
95
+ stdio: "inherit",
96
+ env: {
97
+ ...process.env,
98
+ CODEX_AUTH_NODE_EXECUTABLE: process.execPath
99
+ }
100
+ });
101
+
102
+ if (child.error) {
103
+ console.error(child.error.message);
104
+ process.exit(1);
105
+ }
106
+
107
+ if (child.signal) {
108
+ process.kill(process.pid, child.signal);
109
+ } else {
110
+ process.exit(child.status ?? 1);
111
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@wen2go/codex-auth-ext",
3
+ "version": "0.3.0-alpha.7",
4
+ "type": "module",
5
+ "description": "CLI for switching Codex accounts",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/wen2go/codex-auth-ext.git"
10
+ },
11
+ "homepage": "https://github.com/wen2go/codex-auth-ext",
12
+ "bugs": {
13
+ "url": "https://github.com/wen2go/codex-auth-ext/issues"
14
+ },
15
+ "bin": {
16
+ "codex-auth": "bin/codex-auth.js"
17
+ },
18
+ "files": [
19
+ "bin/",
20
+ "LICENSE",
21
+ "README.md"
22
+ ],
23
+ "optionalDependencies": {
24
+ "@wen2go/codex-auth-ext-linux-x64": "0.3.0-alpha.7",
25
+ "@wen2go/codex-auth-ext-linux-arm64": "0.3.0-alpha.7",
26
+ "@wen2go/codex-auth-ext-darwin-x64": "0.3.0-alpha.7",
27
+ "@wen2go/codex-auth-ext-darwin-arm64": "0.3.0-alpha.7",
28
+ "@wen2go/codex-auth-ext-win32-x64": "0.3.0-alpha.7",
29
+ "@wen2go/codex-auth-ext-win32-arm64": "0.3.0-alpha.7"
30
+ },
31
+ "scripts": {
32
+ "check:versions": "node scripts/npm/check-versions.mjs",
33
+ "check:release-metadata": "node scripts/npm/check-release-metadata.mjs",
34
+ "pack:local": "node scripts/npm/stage-local-package.mjs",
35
+ "stage:npm": "node scripts/npm/stage-packages.mjs"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "engines": {
41
+ "node": ">=22"
42
+ }
43
+ }