@bjesuiter/codex-switcher 1.2.0 → 1.4.0

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.
Files changed (3) hide show
  1. package/README.md +136 -44
  2. package/cdx.mjs +857 -283
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -1,6 +1,36 @@
1
1
  # cdx
2
2
 
3
- CLI tool to switch between multiple OpenAI accounts for [OpenCode](https://opencode.ai).
3
+ Switch the coding-agents [pi](https://pi.dev/), [codex](https://developers.openai.com/codex/cli/) and [opencode](https://opencode.ai/) auth between multiple openAI Plus and Pro accounts.
4
+
5
+ ---
6
+
7
+ ## Latest Changes
8
+
9
+ ### 1.4.0
10
+
11
+ #### Features
12
+
13
+ - Add **beta Windows/Linux support** with platform-specific defaults for config/auth paths.
14
+ - Add secure-store adapters via `cross-keychain` for Windows Credential Manager and Linux Secret Service/keyring.
15
+ - Add `cdx doctor` to display auth file state with explicit paths plus runtime capability diagnostics.
16
+ - Improve `cdx status` output flow: account/token details first, usage fetch with spinner after.
17
+ - Require explicit one-time consent before using secure-store fallback backends (`CDX_ALLOW_SECURE_STORE_FALLBACK=1` override).
18
+
19
+ #### Fixes
20
+
21
+ - Use platform-neutral secure-store wording in output where macOS-specific keychain wording was misleading.
22
+
23
+ #### Internal
24
+
25
+ - Add shared platform abstraction layer (`lib/platform/*`) for paths, browser launcher, and runtime capability detection.
26
+ - Expand platform/path/browser/secret-store test coverage.
27
+ - Update dependencies and lockfile for `cross-keychain`.
28
+
29
+ see full changelog here: https://github.com/bjesuiter/codex-switcher/blob/main/CHANGELOG.md
30
+
31
+
32
+
33
+ ---
4
34
 
5
35
  ## Why codex-switcher?
6
36
 
@@ -9,13 +39,22 @@ So: switching between two $20 plans is the poor man's $100 plan for OpenAI. ^^
9
39
 
10
40
  ## Supported Configurations
11
41
 
12
- - **OpenAI Plus & Pro subscription accounts**: Log in to multiple OpenAI accounts via OAuth and switch the active auth credentials used by OpenCode.
42
+ - **OpenAI Plus & Pro subscription accounts**: Log in to multiple OpenAI OAuth accounts and switch the active credentials.
43
+ - **OpenCode auth target**: Writes active credentials to `~/.local/share/opencode/auth.json`.
44
+ - **Pi Agent auth target**: Writes active credentials to `~/.pi/agent/auth.json` (or `$PI_CODING_AGENT_DIR/auth.json`).
45
+ - **Codex CLI auth target**: Writes active credentials to `~/.codex/auth.json` when `id_token` is available.
13
46
 
14
47
  ## Requirements
15
48
 
16
- - macOS (uses Keychain via the `security` command)
49
+ - macOS (uses Keychain), Windows (uses Windows Credential Manager), **or** Linux (uses Secret Service/keyring)
17
50
  - [Bun](https://bun.sh) runtime
18
51
 
52
+ ## Platform Support Status
53
+
54
+ - **macOS:** stable
55
+ - **Windows:** beta
56
+ - **Linux:** beta
57
+
19
58
  ## Install
20
59
 
21
60
  ```bash
@@ -26,88 +65,141 @@ This exposes the `cdx` binary globally.
26
65
 
27
66
  ## Usage
28
67
 
29
- ### Add your first account
68
+ ### macOS (stable)
69
+
70
+ 1. Install [Bun](https://bun.sh)
71
+ 2. Install `cdx`
72
+ 3. Run and verify:
73
+ - `cdx login`
74
+ - `cdx status`
75
+ - `cdx switch`
76
+ - `cdx relogin <account-id-or-label>`
77
+ 4. Confirm auth files are written correctly after switching:
78
+ - `~/.local/share/opencode/auth.json` (or `$XDG_DATA_HOME/opencode/auth.json`)
79
+ - `~/.codex/auth.json`
80
+ - `~/.pi/agent/auth.json` (or `$PI_CODING_AGENT_DIR/auth.json`)
81
+ 5. Credentials are stored in macOS Keychain.
82
+
83
+ ### Windows (beta)
84
+
85
+ Windows support is **test-ready** and suitable for friend/beta testing, but is not yet production-proven by broad real-world testing.
86
+
87
+ 1. Install [Bun](https://bun.sh)
88
+ 2. Install `cdx`
89
+ 3. Run and verify:
90
+ - `cdx login`
91
+ - `cdx status`
92
+ - `cdx switch`
93
+ - `cdx relogin <account-id-or-label>`
94
+ 4. Confirm auth files are written correctly after switching:
95
+ - `%LOCALAPPDATA%\\opencode\\auth.json`
96
+ - `%USERPROFILE%\\.codex\\auth.json`
97
+ - `%USERPROFILE%\\.pi\\agent\\auth.json` (or `%PI_CODING_AGENT_DIR%\\auth.json`)
98
+ 5. If prompted about secure-store fallback, explicitly choose whether to allow it for testing.
99
+ - Non-interactive override (if you accept the risk): `CDX_ALLOW_SECURE_STORE_FALLBACK=1`
100
+
101
+ ### Linux (beta)
102
+
103
+ Linux support is **test-ready** and suitable for friend/beta testing, but is not yet production-proven by broad real-world testing.
104
+
105
+ 1. Install [Bun](https://bun.sh)
106
+ 2. Ensure a Secret Service backend is available (for example GNOME Keyring with `secret-tool`)
107
+ 3. Install `cdx`
108
+ 4. Run and verify:
109
+ - `cdx login`
110
+ - `cdx status`
111
+ - `cdx switch`
112
+ - `cdx relogin <account-id-or-label>`
113
+ 5. Confirm auth files are written correctly after switching:
114
+ - `~/.local/share/opencode/auth.json` (or `$XDG_DATA_HOME/opencode/auth.json`)
115
+ - `~/.codex/auth.json`
116
+ - `~/.pi/agent/auth.json` (or `$PI_CODING_AGENT_DIR/auth.json`)
117
+ 6. If prompted about secure-store fallback, explicitly choose whether to allow it for testing.
118
+ - Non-interactive override (if you accept the risk): `CDX_ALLOW_SECURE_STORE_FALLBACK=1`
119
+
120
+ Please report the full command output and platform info (`cdx status`) for any failures.
121
+
122
+ ### Common command examples (all platforms)
123
+
124
+ Add your first account:
30
125
 
31
126
  ```bash
32
127
  cdx login
33
128
  ```
34
129
 
35
- Opens your browser to authenticate with OpenAI. After successful login, your credentials are stored securely in macOS Keychain.
36
-
37
- ### Switch between accounts
130
+ Switch between accounts:
38
131
 
39
132
  ```bash
40
133
  cdx switch
41
- ```
42
-
43
- Interactive picker to select an account. Writes credentials to:
44
- - `~/.local/share/opencode/auth.json` (OpenCode)
45
- - `~/.pi/agent/auth.json` (Pi agent, or `$PI_CODING_AGENT_DIR/auth.json` when `PI_CODING_AGENT_DIR` is set)
46
- - `~/.codex/auth.json` (Codex CLI; requires `id_token`)
47
-
48
- ```bash
49
134
  cdx switch --next
50
- ```
51
-
52
- Cycles to the next configured account without prompting.
53
-
54
- ```bash
55
135
  cdx switch <account-id-or-label>
56
136
  ```
57
137
 
58
- Switch directly to a specific account by ID or label.
59
-
60
- ### Label accounts
138
+ Label accounts:
61
139
 
62
140
  ```bash
63
141
  cdx label
64
- ```
65
-
66
- Interactive prompt to assign a friendly name to an account.
67
-
68
- ```bash
69
142
  cdx label <account> <new-label>
70
143
  ```
71
144
 
72
- Assign a label directly.
73
-
74
- ### Interactive mode
145
+ Interactive mode:
75
146
 
76
147
  ```bash
77
148
  cdx
78
149
  ```
79
150
 
80
- Running `cdx` without arguments opens an interactive menu to:
81
- - List all configured accounts
82
- - Switch to a different account
83
- - Add a new account (OAuth login)
84
- - Remove an account
85
-
86
151
  ## Commands
87
152
 
88
153
  | Command | Description |
89
154
  |---------|-------------|
90
155
  | `cdx` | Interactive mode |
91
156
  | `cdx login` | Add a new OpenAI account via OAuth |
157
+ | `cdx relogin` | Re-authenticate an existing account via OAuth |
158
+ | `cdx relogin <account>` | Re-authenticate a specific account by ID or label |
92
159
  | `cdx switch` | Switch account (interactive picker) |
93
160
  | `cdx switch --next` | Cycle to next account |
94
161
  | `cdx switch <id>` | Switch to specific account |
95
162
  | `cdx label` | Label an account (interactive) |
96
163
  | `cdx label <account> <label>` | Assign label directly |
97
164
  | `cdx status` | Show account status, token expiry, and usage |
165
+ | `cdx doctor` | Show auth file paths/state and runtime capabilities |
98
166
  | `cdx usage` | Show usage overview for all accounts |
99
167
  | `cdx usage <account>` | Show detailed usage for a specific account |
168
+ | `cdx help [command]` | Show help for all commands or one command |
169
+ | `cdx version` | Show CLI version |
100
170
  | `cdx --help` | Show help |
101
171
  | `cdx --version` | Show version |
102
172
 
103
173
  ## How It Works
104
174
 
105
- - OAuth credentials are stored securely in macOS Keychain
106
- - Account list is stored in `~/.config/cdx/accounts.json`
107
- - Active account credentials are written to:
108
- - `~/.local/share/opencode/auth.json`
109
- - `~/.pi/agent/auth.json` (or `$PI_CODING_AGENT_DIR/auth.json`)
110
- - `~/.codex/auth.json` (when `id_token` exists)
175
+ ### Secure credential storage
176
+
177
+ - **macOS:** macOS Keychain
178
+ - **Windows:** Windows Credential Manager
179
+ - **Linux:** Secret Service/keyring
180
+ - If only a fallback secure-store backend is available on your platform, `cdx` asks for one-time explicit consent before the first credential write and explains the security trade-off.
181
+ - Non-interactive override (if you accept the risk): set `CDX_ALLOW_SECURE_STORE_FALLBACK=1`
182
+
183
+ ### Account list path
184
+
185
+ - **macOS/Linux:** `~/.config/cdx/accounts.json` (or `$XDG_CONFIG_HOME/cdx/accounts.json`)
186
+ - **Windows:** `%APPDATA%\\cdx\\accounts.json`
187
+
188
+ ### Auth file paths
189
+
190
+ #### macOS / Linux
191
+
192
+ - **OpenCode:** `~/.local/share/opencode/auth.json` (or `$XDG_DATA_HOME/opencode/auth.json`)
193
+ - **Codex CLI:** `~/.codex/auth.json`
194
+ - **Pi Agent:** `~/.pi/agent/auth.json` (or `$PI_CODING_AGENT_DIR/auth.json`)
195
+
196
+ #### Windows
197
+
198
+ - **OpenCode:** `%LOCALAPPDATA%\\opencode\\auth.json`
199
+ - **Codex CLI:** `%USERPROFILE%\\.codex\\auth.json`
200
+ - **Pi Agent:** `%USERPROFILE%\\.pi\\agent\\auth.json` (or `%PI_CODING_AGENT_DIR%\\auth.json`)
201
+
202
+ `cdx` writes Codex CLI auth only when `id_token` exists.
111
203
 
112
204
  ## For Developers
113
205
 
@@ -130,7 +222,7 @@ bun link
130
222
 
131
223
  ### Manual Configuration (Advanced)
132
224
 
133
- You can also manually add accounts to Keychain:
225
+ You can also manually add accounts to Keychain (macOS only):
134
226
 
135
227
  ```bash
136
228
  security add-generic-password -a "ACCOUNT_ID" -s "cdx-openai-ACCOUNT_ID" -w '{"refresh":"REFRESH","access":"ACCESS","expires":1234567890,"accountId":"ACCOUNT_ID"}' -U