@ralphkrauss/codex-account-switcher 0.1.6 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.7 - 2026-06-06
4
+
5
+ ### Added
6
+
7
+ - Add `docs/AGENT_SETUP.md`, a copy-pasteable agent setup guide for installing Codex, `cx`, and 1Password-backed profiles on personal devices without exposing auth secrets.
8
+ - Expand the README with quick-start setup steps, agent-safe verification commands, bootstrap/push guidance, and troubleshooting links.
9
+
3
10
  ## 0.1.6 - 2026-06-06
4
11
 
5
12
  ### Added
package/README.md CHANGED
@@ -18,6 +18,28 @@ npx -y @ralphkrauss/codex-account-switcher --help
18
18
 
19
19
  Requires Node.js 22+ and the native Codex CLI on `PATH`.
20
20
 
21
+ ## New personal device quick start
22
+
23
+ If your Codex profiles already exist in 1Password, a new machine should only need:
24
+
25
+ ```bash
26
+ npm install -g @openai/codex @ralphkrauss/codex-account-switcher
27
+ op signin
28
+ cx 1password setup --vault <VAULT_NAME> --pull --use <PROFILE_NAME>
29
+ cx doctor
30
+ cx 1password status
31
+ ```
32
+
33
+ Example:
34
+
35
+ ```bash
36
+ cx 1password setup --vault Codex --pull --use gi
37
+ ```
38
+
39
+ For a copy-pasteable prompt you can give another agent, plus macOS/Windows/Linux, bootstrap, headless EC2, and troubleshooting steps, see [`docs/AGENT_SETUP.md`](docs/AGENT_SETUP.md).
40
+
41
+ Agent safety rule: do not paste or print `auth.json`, `accounts/*.json`, OAuth tokens, refresh tokens, or 1Password concealed-field contents. Use `cx doctor`, `cx 1password status`, `cx sync status`, and `cx ls` for verification instead.
42
+
21
43
  ## Data layout
22
44
 
23
45
  `cx` uses `CODEX_HOME` when set, otherwise `~/.codex`:
@@ -105,6 +127,8 @@ cx hermes sync work # copy refreshed Hermes tokens back to the c
105
127
 
106
128
  `cx` can use 1Password as a native profile backend through the 1Password CLI (`op`). This is intended for moving Codex auth between machines without committing secrets to git or publishing them to npm.
107
129
 
130
+ Full setup documentation for personal devices and delegated agent setup is in [`docs/AGENT_SETUP.md`](docs/AGENT_SETUP.md). It includes a prompt you can give your agent, OS-specific installation notes, first-machine bootstrapping, headless/service-account setup, and troubleshooting.
131
+
108
132
  Prerequisites:
109
133
 
110
134
  - Install 1Password CLI v2 (`op`) on each machine.
@@ -0,0 +1,317 @@
1
+ # Agent setup guide for Codex account profiles
2
+
3
+ This guide is written so Ralph can ask an agent on a new personal device to install and configure `cx` without handing the agent raw Codex tokens.
4
+
5
+ `cx` is the `@ralphkrauss/codex-account-switcher` CLI. It stores local Codex profile slots under Codex's normal data directory and can sync named profiles through 1Password using the 1Password CLI (`op`).
6
+
7
+ ## Copy-paste prompt for an agent
8
+
9
+ Use this prompt on a new device:
10
+
11
+ ```text
12
+ Set up Codex account switching on this machine using @ralphkrauss/codex-account-switcher.
13
+
14
+ Rules:
15
+ - Do not ask me to paste Codex auth JSON, OAuth tokens, refresh tokens, or 1Password secrets into chat.
16
+ - Do not print ~/.codex/auth.json, ~/.codex/accounts/*.json, or 1Password field contents.
17
+ - It is OK to ask me to complete browser/device-login prompts or run a local 1Password unlock/sign-in step.
18
+ - Prefer using 1Password-backed profiles with `cx 1password setup`.
19
+
20
+ Tasks:
21
+ 1. Check whether Node.js 22+, npm, Codex CLI, cx, and 1Password CLI (`op`) are installed.
22
+ 2. Install or upgrade what is missing:
23
+ - Codex CLI: `npm install -g @openai/codex`
24
+ - cx: `npm install -g @ralphkrauss/codex-account-switcher`
25
+ 3. Make sure `op` is signed in/unlocked. If not, tell me the exact local command to run, such as `op signin`.
26
+ 4. Configure 1Password-backed Codex profiles:
27
+ `cx 1password setup --vault <VAULT_NAME> --pull --use <PROFILE_NAME>`
28
+ 5. Verify setup with safe commands only:
29
+ - `cx doctor`
30
+ - `cx 1password status`
31
+ - `cx ls`
32
+ - `cx run <PROFILE_NAME> -- --version`
33
+ 6. If a requested profile exists in 1Password but is not local, rely on `cx use <PROFILE_NAME>` or `cx run <PROFILE_NAME> -- ...` to auto-pull it.
34
+ 7. If a profile's Codex session has ended, run `cx login <PROFILE_NAME> --device-auth`, ask me to complete the browser/device flow, then run `cx sync push <PROFILE_NAME>`.
35
+
36
+ Use `<VAULT_NAME>` for the 1Password vault that contains the `cx-*` items and `<PROFILE_NAME>` for the profile I want active, for example `gi` or `personal`.
37
+ ```
38
+
39
+ ## What the setup should produce
40
+
41
+ After setup, these files may exist:
42
+
43
+ ```text
44
+ ~/.codex/auth.json # Codex's active/live auth file
45
+ ~/.codex/accounts/<profile>.json # local named profile copies
46
+ ~/.codex/.current-account # active profile marker
47
+ ~/.codex/remote.json # 1Password sync config
48
+ ```
49
+
50
+ The package code itself is installed by npm. Credential data stays under `~/.codex` and, if enabled, in 1Password secure-note items.
51
+
52
+ ## New personal device: normal interactive flow
53
+
54
+ 1. Install prerequisites.
55
+
56
+ macOS with Homebrew:
57
+
58
+ ```bash
59
+ brew install node@22 1password-cli
60
+ npm install -g @openai/codex @ralphkrauss/codex-account-switcher
61
+ ```
62
+
63
+ Windows with PowerShell/winget:
64
+
65
+ ```powershell
66
+ winget install OpenJS.NodeJS.LTS
67
+ winget install AgileBits.1Password.CLI
68
+ npm install -g @openai/codex @ralphkrauss/codex-account-switcher
69
+ ```
70
+
71
+ Linux example:
72
+
73
+ ```bash
74
+ node --version # must be v22+
75
+ npm install -g @openai/codex @ralphkrauss/codex-account-switcher
76
+ ```
77
+
78
+ 2. Sign in to 1Password CLI locally.
79
+
80
+ ```bash
81
+ op signin
82
+ op vault list
83
+ ```
84
+
85
+ 3. Configure and pull the remote profiles.
86
+
87
+ ```bash
88
+ cx 1password setup --vault <VAULT_NAME> --pull --use <PROFILE_NAME>
89
+ ```
90
+
91
+ Example:
92
+
93
+ ```bash
94
+ cx 1password setup --vault Codex --pull --use gi
95
+ ```
96
+
97
+ 4. Verify without exposing secrets.
98
+
99
+ ```bash
100
+ cx doctor
101
+ cx 1password status
102
+ cx ls
103
+ cx run gi -- --version
104
+ ```
105
+
106
+ 5. Switch naturally after that.
107
+
108
+ ```bash
109
+ cx use gi
110
+ cx use personal
111
+ cx run gi -- exec "summarize this repo"
112
+ ```
113
+
114
+ ## First machine / bootstrapping profiles into 1Password
115
+
116
+ If 1Password does not have any `cx-*` items yet, bootstrap from a machine where Codex is already logged in.
117
+
118
+ 1. Save or create named local profiles.
119
+
120
+ If the current `~/.codex/auth.json` is the account you want to call `gi`:
121
+
122
+ ```bash
123
+ cx save gi
124
+ ```
125
+
126
+ If you need to log in a new account:
127
+
128
+ ```bash
129
+ cx login personal --device-auth
130
+ ```
131
+
132
+ 2. Configure the vault.
133
+
134
+ ```bash
135
+ cx 1password setup --vault <VAULT_NAME>
136
+ ```
137
+
138
+ 3. Push named profiles.
139
+
140
+ ```bash
141
+ cx sync push gi
142
+ cx sync push personal
143
+ # or push all local named profiles except reserved default:
144
+ cx sync push --all
145
+ ```
146
+
147
+ 4. Confirm presence only, not token contents.
148
+
149
+ ```bash
150
+ cx sync status
151
+ ```
152
+
153
+ ## Headless hosts and EC2
154
+
155
+ For a non-interactive Linux host, prefer a 1Password service account scoped only to the dedicated Codex vault.
156
+
157
+ 1. Create a 1Password service account with access only to the Codex profile vault.
158
+ 2. Store the token in a local env file with private permissions. Do this outside chat; do not paste the token to the agent.
159
+
160
+ ```bash
161
+ mkdir -p ~/.config/1password
162
+ install -m 600 /dev/null ~/.config/1password/op.env
163
+ $EDITOR ~/.config/1password/op.env
164
+ ```
165
+
166
+ File contents:
167
+
168
+ ```bash
169
+ export OP_SERVICE_ACCOUNT_TOKEN="..."
170
+ ```
171
+
172
+ 3. Source it before running `cx` commands.
173
+
174
+ ```bash
175
+ set -a
176
+ . ~/.config/1password/op.env
177
+ set +a
178
+ op vault list
179
+ cx 1password setup --vault <VAULT_NAME> --pull --use <PROFILE_NAME>
180
+ ```
181
+
182
+ If the shell is non-interactive, make sure the env file is sourced before any early `return` in shell startup files, or source it explicitly in the command that runs the agent.
183
+
184
+ ## Day-to-day commands
185
+
186
+ List local profiles:
187
+
188
+ ```bash
189
+ cx ls
190
+ ```
191
+
192
+ Switch active profile:
193
+
194
+ ```bash
195
+ cx use gi
196
+ ```
197
+
198
+ Run Codex under a profile:
199
+
200
+ ```bash
201
+ cx run gi -- exec "fix the failing tests"
202
+ ```
203
+
204
+ Login or refresh a profile, then push the refreshed token to 1Password:
205
+
206
+ ```bash
207
+ cx login personal --device-auth
208
+ cx sync push personal
209
+ ```
210
+
211
+ Pull a new remote profile:
212
+
213
+ ```bash
214
+ cx sync pull personal
215
+ ```
216
+
217
+ Pull every missing remote profile:
218
+
219
+ ```bash
220
+ cx sync pull --all
221
+ ```
222
+
223
+ Show local/remote presence without secrets:
224
+
225
+ ```bash
226
+ cx 1password status
227
+ cx sync status
228
+ ```
229
+
230
+ ## Important rules
231
+
232
+ - Sync named profiles such as `gi` and `personal`; do not sync `default`.
233
+ - `default` is reserved for Codex's live `auth.json` target on each machine.
234
+ - `cx use <profile>` chooses which named profile is active on that machine.
235
+ - Do not copy `auth.json` through chat, git, shared folders, or plain text notes.
236
+ - Do not run a fresh `cx login <profile>` on a secondary machine unless you intentionally want to rotate/replace that OAuth session. Pulling from 1Password is safer for shared profiles.
237
+ - If Codex says a session has ended, run `cx login <profile> --device-auth` and then `cx sync push <profile>`.
238
+
239
+ ## Troubleshooting
240
+
241
+ ### `cx: command not found`
242
+
243
+ Check npm's global bin directory:
244
+
245
+ ```bash
246
+ npm bin -g
247
+ npm prefix -g
248
+ ```
249
+
250
+ Make sure the global bin directory is on `PATH`, then reinstall:
251
+
252
+ ```bash
253
+ npm install -g @ralphkrauss/codex-account-switcher
254
+ ```
255
+
256
+ ### Node is too old
257
+
258
+ `cx` requires Node.js 22+:
259
+
260
+ ```bash
261
+ node --version
262
+ ```
263
+
264
+ Upgrade Node, then reinstall the global packages.
265
+
266
+ ### `op` cannot access the vault
267
+
268
+ Verify the CLI can see the vault:
269
+
270
+ ```bash
271
+ op vault list
272
+ op item list --vault <VAULT_NAME>
273
+ ```
274
+
275
+ If that fails, sign in/unlock 1Password locally or fix the service-account token/vault permissions.
276
+
277
+ ### Remote profile is shown but not local
278
+
279
+ Use either:
280
+
281
+ ```bash
282
+ cx sync pull <PROFILE_NAME>
283
+ ```
284
+
285
+ or just switch/run it; `cx` will auto-pull from the configured 1Password backend:
286
+
287
+ ```bash
288
+ cx use <PROFILE_NAME>
289
+ cx run <PROFILE_NAME> -- --version
290
+ ```
291
+
292
+ ### Local profile exists but should be replaced by 1Password
293
+
294
+ Use force deliberately:
295
+
296
+ ```bash
297
+ cx sync pull <PROFILE_NAME> --force
298
+ ```
299
+
300
+ ### Need to migrate from the old shell script
301
+
302
+ Keep credential data, remove only the sourced script/hook:
303
+
304
+ ```bash
305
+ npm install -g @ralphkrauss/codex-account-switcher
306
+ rm -f ~/.codex/codex-acct.sh
307
+ ```
308
+
309
+ Then remove the marked `.bashrc` block that sourced `~/.codex/codex-acct.sh`.
310
+
311
+ Do not delete:
312
+
313
+ ```text
314
+ ~/.codex/auth.json
315
+ ~/.codex/accounts/
316
+ ~/.codex/.current-account
317
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ralphkrauss/codex-account-switcher",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Safe multi-account auth.json switcher for the native Codex CLI.",
5
5
  "author": "Ralph Krauss <ralph@krauss.be>",
6
6
  "type": "module",
@@ -30,6 +30,7 @@
30
30
  "!dist/__tests__/",
31
31
  "!src/__tests__/",
32
32
  "README.md",
33
+ "docs/",
33
34
  "CHANGELOG.md",
34
35
  "CONTRIBUTING.md",
35
36
  "SECURITY.md",
@@ -65,5 +66,8 @@
65
66
  "@types/node": "^22.15.18",
66
67
  "typescript": "^5.9.3"
67
68
  },
68
- "packageManager": "pnpm@10.30.3"
69
+ "packageManager": "pnpm@10.30.3",
70
+ "directories": {
71
+ "doc": "docs"
72
+ }
69
73
  }