@leeguoo/wrangler-accounts 1.6.0 → 1.6.2

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.
@@ -682,8 +682,9 @@ function main() {
682
682
  e.status === "expired" ? "EXPIRED"
683
683
  : e.status === "refreshable" ? "valid*"
684
684
  : e.status === "valid" ? "valid"
685
+ : e.status === "token" ? "token"
685
686
  : "unknown",
686
- expires: formatExpiry(e.expirationTime),
687
+ expires: e.type === "token" ? "—" : formatExpiry(e.expirationTime),
687
688
  verified:
688
689
  e.verified === true ? "✓ ok"
689
690
  : e.verified === false ? `✗ ${e.verifyError || "failed"}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leeguoo/wrangler-accounts",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Cloudflare Wrangler multi-account manager — save, switch, and run wrangler against multiple Cloudflare Workers accounts with AWS-style --profile and per-invocation shadow HOME isolation.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -1,514 +0,0 @@
1
- ---
2
- name: wrangler-accounts
3
- description: AWS-style multi-account convenience for Cloudflare Wrangler. Use when you need to run wrangler commands against a specific Cloudflare account, manage saved OAuth profiles, set or switch the persistent default profile, or open an isolated subshell for a profile. Prefer --json for machine-readable output.
4
- ---
5
-
6
- # Wrangler Accounts
7
-
8
- ## Overview
9
-
10
- `wrangler-accounts` runs `wrangler` under per-invocation **shadow HOME** isolation, so multiple shells can use different Cloudflare accounts in parallel without any global switching. Profile resolution order: `--profile` / `-p` > positional shorthand > `$WRANGLER_PROFILE` > `profilesDir/default` > hard error.
11
-
12
- ## Installation
13
-
14
- For Claude Code users, prefer the plugin marketplace install path because it ships this skill and the raw-`wrangler` guard hook together:
15
-
16
- ```text
17
- /plugin marketplace add leeguooooo/wrangler-accounts
18
- /plugin install wrangler-accounts@leeguoo-tools
19
- ```
20
-
21
- The plugin does **not** replace the CLI binary. The actual `wrangler-accounts` executable still must be installed on `PATH`:
22
-
23
- ```bash
24
- npm i -g @leeguoo/wrangler-accounts
25
- ```
26
-
27
- Non-Claude-Code users can keep using the `skills.sh` distribution path for this same `SKILL.md` mirror:
28
-
29
- ```bash
30
- npx skills add leeguooooo/wrangler-accounts -g -y
31
- ```
32
-
33
- If a Claude Code user previously installed via `skills.sh`, removing the standalone copy avoids a duplicate `/wrangler-accounts` entry in the command picker:
34
-
35
- ```bash
36
- npx skills remove wrangler-accounts
37
- # or: rm -rf ~/.agents/skills/wrangler-accounts
38
- ```
39
-
40
- ## Prerequisites (check before running any recipe below)
41
-
42
- This skill is only documentation — the actual `wrangler-accounts` binary must also be installed on the user's `PATH`. Before running any command below, verify:
43
-
44
- ```bash
45
- command -v wrangler-accounts && wrangler-accounts --version
46
- ```
47
-
48
- If the command is missing, tell the user to install the CLI first:
49
-
50
- ```bash
51
- npm i -g @leeguoo/wrangler-accounts
52
- ```
53
-
54
- `wrangler` itself (the Cloudflare CLI) must also be on `PATH`. If missing:
55
-
56
- ```bash
57
- npm i -g wrangler
58
- ```
59
-
60
- ### Minimum versions you should ask the user to upgrade past
61
-
62
- If `wrangler-accounts --version` is below any of these, **upgrade first** before debugging anything else — older versions have real bugs that will misdirect you:
63
-
64
- | Version | What it fixed | Symptom on older versions |
65
- |---|---|---|
66
- | **≥ 1.2.2** | per-profile `WRANGLER_CACHE_DIR`, fixes account-id leak across profiles | `d1`/`r2 object` commands return `7403 not authorized` even though OAuth is valid; deploys silently land in the wrong account |
67
- | **≥ 1.3.0** | STATUS column distinguishes `valid` / `valid*` / `EXPIRED` (refresh-token-aware) | `list` shows `EXPIRED` for healthy profiles, scaring you into running `login` for no reason |
68
- | **≥ 1.4.0** | `login` refuses non-TTY contexts and accidental overwrites | `login <name>` hangs forever in non-interactive contexts; reflexive `login` overwrites a healthy profile |
69
- | **≥ 1.6.0** | API token profiles (`token-add`) + anonymous env-var pass-through | only OAuth profiles existed; `CLOUDFLARE_API_TOKEN` in env still required a named profile to be selected |
70
-
71
- ```bash
72
- npm i -g @leeguoo/wrangler-accounts@latest # always-safe upgrade
73
- ```
74
-
75
- ## Triage flow — when something looks wrong
76
-
77
- **Run these in order before reaching for `login` or any destructive command.** The agent who skipped this step in a recent incident ended up overwriting a perfectly healthy profile in a sub-shell where the browser couldn't even open.
78
-
79
- ```bash
80
- # 1. Verify your binary is recent enough (see version table above)
81
- wrangler-accounts --version
82
-
83
- # 2. Authoritative state of every profile (hits Cloudflare API per profile)
84
- wrangler-accounts list --deep
85
- ```
86
-
87
- How to read `list --deep` output:
88
-
89
- | You see | Meaning | What to do |
90
- |---|---|---|
91
- | `STATUS valid` + `VERIFIED ✓ ok` | profile is fine | nothing — proceed with whatever the user actually asked |
92
- | `STATUS valid*` + `VERIFIED ✓ ok` | profile is fine; access token will auto-refresh on next use | nothing — **`valid*` is healthy, do NOT re-login** |
93
- | `STATUS EXPIRED` + `VERIFIED ✓ ok` | rare; only on `< 1.3.0` binaries — STATUS is lying | upgrade the CLI; profile is fine |
94
- | `STATUS EXPIRED` + `VERIFIED ✗ Not logged in` | profile is genuinely broken | `wrangler-accounts login <name>` (interactive only) |
95
- | `STATUS valid` + `VERIFIED ✗` of any kind | refresh token revoked server-side | `wrangler-accounts login <name>` (interactive only) |
96
- | `STATUS unknown` | profile file lacks `expiration_time` | run `--deep` (already did) — trust VERIFIED |
97
-
98
- **Rule**: only suggest `wrangler-accounts login <name>` when at least one of:
99
- 1. `list --deep` showed `VERIFIED ✗` for that profile, OR
100
- 2. The profile doesn't exist at all yet, OR
101
- 3. The user explicitly says "re-authenticate" / "log me in again"
102
-
103
- **If `list --deep` shows everything ✓ but a wrangler command still fails**, the root cause is somewhere other than wrangler-accounts — most likely:
104
- - Project-local `./.wrangler/state/` is sharing data across profiles (see "What is and isn't isolated")
105
- - The project's `wrangler.toml` has the wrong `account_id` hardcoded
106
- - The user is on a CLI version below 1.2.2 (account-id cache leak)
107
- - The wrangler subcommand actually needs `--remote` or `--local` and you forgot
108
-
109
- ## Quick Start
110
-
111
- - `wrangler-accounts login <name>` — interactive OAuth login into a new profile (never touches real `~/.wrangler`)
112
- - `wrangler-accounts token-add <name> <api-token> <account-id>` — save an API token profile (no browser login needed)
113
- - `wrangler-accounts default <name>` — set the persistent default profile
114
- - `wrangler-accounts deploy` — run `wrangler deploy` under the default profile
115
- - `wrangler-accounts --profile personal deploy` — one-shot override
116
- - `wrangler-accounts exec work -- npm run release` — run a command in an isolated subshell for the `work` profile
117
-
118
- > 💡 **Reading the STATUS column**: `valid` = healthy, `valid*` = healthy (will auto-refresh on next use, **don't re-login**), `EXPIRED` = truly broken (need login), `unknown` = run `--deep` to find out. Full table below in "List and inspect profiles".
119
-
120
- ## Tasks
121
-
122
- ### Run wrangler against a profile
123
-
124
- Per-invocation (preferred for scripts):
125
-
126
- `wrangler-accounts --profile <name> <wrangler-args...>`
127
-
128
- Or with env var:
129
-
130
- `WRANGLER_PROFILE=<name> wrangler-accounts <wrangler-args...>`
131
-
132
- Or positional shorthand (only when `<name>` is a saved profile name, not a management subcommand):
133
-
134
- `wrangler-accounts <name> <wrangler-args...>`
135
-
136
- ### Open a subshell for a profile
137
-
138
- `wrangler-accounts exec <name>` — launches `$SHELL -i` with isolated `HOME` and `WRANGLER_PROFILE` set. Everything inside the subshell sees the profile, including nested `npm run` scripts, Makefiles, and `npx wrangler`.
139
-
140
- Run a single command instead:
141
-
142
- `wrangler-accounts exec <name> -- <cmd> [args]`
143
-
144
- ### Manage the persistent default profile
145
-
146
- - `wrangler-accounts default` — print current default (exit 1 if none set)
147
- - `wrangler-accounts default <name>` — set the default
148
- - `wrangler-accounts default --unset` — clear the default
149
- - `wrangler-accounts default --json` — JSON output
150
-
151
- ### Show the resolved identity for a profile
152
-
153
- `wrangler-accounts whoami [--profile <name>]` — reports the profile name, source tier (cli / positional / env / default), and identity from `meta.json`. Does not spawn wrangler.
154
-
155
- Use `--json` for structured output.
156
-
157
- ### List and inspect profiles
158
-
159
- - `wrangler-accounts list` — text table with NAME / STATUS / EXPIRES / IDENTITY columns
160
- - `wrangler-accounts list --json` — structured: array of `{name, isDefault, isActive, status, expirationTime, hasRefreshToken, identity, verified, verifyError}`
161
- - `wrangler-accounts list --plain` — one profile name per line (scriptable)
162
- - `wrangler-accounts list --deep` — **authoritative** check: spawns `wrangler whoami` in a shadow HOME for every profile and reports whether Cloudflare actually accepts the credentials. Slower (makes network calls), but the only way to catch revoked refresh tokens or broken profile files.
163
- - `wrangler-accounts status` / `status --json`
164
- - Pass `--include-backups` to show hidden backup profiles.
165
-
166
- **STATUS values (1.3.0+):**
167
-
168
- | value | meaning | user action |
169
- |---|---|---|
170
- | `valid` | access_token is currently valid | none |
171
- | `valid*` / `refreshable` | access_token past expiry **BUT** refresh_token present; wrangler will auto-refresh on next use | **none** — this is fine, don't scare the user |
172
- | `EXPIRED` / `expired` | access_token expired **AND** no refresh_token saved; profile is genuinely broken | `wrangler-accounts login <name>` |
173
- | `unknown` | profile file has no `expiration_time` field | run `list --deep` to verify live |
174
- | `token` | API token profile (1.6.0+) — no expiration concept, always ready | none |
175
-
176
- **Cloudflare OAuth lifecycle reference:** access tokens are short-lived (~1 hour) by design. Every profile with `offline_access` in its scopes also has a long-lived refresh_token (~30 days, silently extended on use). Wrangler refreshes access tokens automatically whenever it runs a command and the current one is past expiry. **Do not tell the user to re-login just because `list` shows an expired access token** — check `hasRefreshToken` first. If the profile's STATUS is `valid*` / `refreshable`, nothing is wrong.
177
-
178
- The only time a user actually needs `wrangler-accounts login <name>` again is:
179
- 1. STATUS is `EXPIRED` (no refresh_token at all — profile was saved without `offline_access` scope)
180
- 2. OR `list --deep` returns `✗` with "Not logged in" / "refresh token may be revoked" (refresh token itself got invalidated)
181
-
182
- ### Save an API token profile (no browser required)
183
-
184
- `wrangler-accounts token-add <name> <api-token> <account-id> [--force]`
185
-
186
- Saves a Cloudflare API token + account ID as a named profile. No OAuth browser flow needed. The credentials are stored in `token.json` (mode 0600) inside the profile directory.
187
-
188
- ```bash
189
- # Get your API token from: Cloudflare dashboard → My Profile → API Tokens
190
- wrangler-accounts token-add work CF_TOKEN_HERE ACCOUNT_ID_HERE
191
-
192
- # Use identically to OAuth profiles
193
- wrangler-accounts --profile work deploy
194
- wrangler-accounts work r2 list
195
- ```
196
-
197
- Token profiles appear in `list` with a `[token]` type indicator and `STATUS: token` — there is no expiration concept, so they are always ready to use. `remove` works the same as for OAuth profiles.
198
-
199
- **Env-var pass-through (1.6.0+):** when `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` are already set in the environment and no profile is specified, `wrangler-accounts` runs in anonymous-token mode (no named profile needed). Useful for CI jobs that inject credentials via secrets:
200
-
201
- ```bash
202
- CLOUDFLARE_API_TOKEN=xxx CLOUDFLARE_ACCOUNT_ID=yyy wrangler-accounts deploy
203
- ```
204
-
205
- ### Save, sync, login, remove
206
-
207
- - `wrangler-accounts save <name>` — snapshot current Wrangler config as a profile
208
- - `wrangler-accounts sync <name>` — refresh a specific profile from the current login
209
- - `wrangler-accounts sync-default` — refresh the default profile
210
- - `wrangler-accounts login <name>` — fresh isolated OAuth login
211
- - `wrangler-accounts remove <name>` — delete a profile (works for both OAuth and token profiles)
212
-
213
- ### Clean up stale shadow HOMEs
214
-
215
- `wrangler-accounts gc [--older-than 1h]` — removes `wa-*` directories under `$TMPDIR` older than the threshold (default 1h). Safe to run at any time.
216
-
217
- ## Common Recipes
218
-
219
- These are the patterns the user is most likely asking about when they mention "Cloudflare accounts", "wrangler", or "multi-account deploys". Pick the one that matches intent.
220
-
221
- ### User wants: deploy a worker to a specific account
222
-
223
- ```bash
224
- wrangler-accounts --profile work deploy
225
- ```
226
-
227
- Or, when the user will be on this account for a while:
228
-
229
- ```bash
230
- wrangler-accounts default work # set once
231
- wrangler-accounts deploy # uses work from now on
232
- wrangler-accounts deploy --env staging # wrangler flags pass through unchanged
233
- ```
234
-
235
- ### User wants: tail production logs on one account while developing on another
236
-
237
- ```bash
238
- # shell 1
239
- wrangler-accounts --profile work tail my-worker --format pretty
240
-
241
- # shell 2 (simultaneously, zero interference)
242
- wrangler-accounts --profile personal dev
243
- ```
244
-
245
- The two shells each get their own shadow `HOME`, so there's no global state for the other to clobber.
246
-
247
- ### User wants: run a deploy script / npm script / Makefile against a specific account
248
-
249
- ```bash
250
- wrangler-accounts exec work -- npm run deploy
251
- wrangler-accounts exec work -- make release
252
- wrangler-accounts exec work -- bash scripts/deploy.sh
253
- ```
254
-
255
- Anything inside the subshell that calls `wrangler` (directly, via `npx`, via `pnpm`, via a package.json script) automatically uses the `work` profile.
256
-
257
- ### User wants: set up a new Cloudflare account from scratch
258
-
259
- ```bash
260
- wrangler-accounts login new-account # opens the browser OAuth flow
261
- wrangler-accounts whoami --profile new-account # verify identity
262
- wrangler-accounts list # confirm the profile is saved
263
- ```
264
-
265
- The login flow runs inside an isolated shadow `HOME`, so the user's real `~/.wrangler/config/default.toml` is never touched.
266
-
267
- > ⚠️ **`login` is destructive.** It opens a browser, requires the user to click "Authorize" interactively, and **OVERWRITES** the named profile. As of 1.4.0, `wrangler-accounts login <name>` refuses to run if (a) stdin is not a TTY, or (b) the profile already exists and looks healthy — both unless you pass `--force`. **Never run `login` to "verify" or "refresh" a profile** — see the antipattern below.
268
-
269
- ### ❌ Antipattern: running `login` to verify a profile works
270
-
271
- This is wrong:
272
- ```bash
273
- wrangler-accounts login Xdreamstar2025 # ❌ DON'T do this just to check
274
- ```
275
-
276
- Reasons:
277
- 1. `login` is **destructive** — it overwrites the saved profile with a brand new OAuth flow.
278
- 2. `login` requires a **browser and an interactive terminal** — it cannot complete in a Bash sub-shell, CI runner, or sub-agent context. The command will hang waiting for the user.
279
- 3. The Cloudflare access token in a healthy profile auto-refreshes via `refresh_token` — there is **nothing to "log in to"** when the profile already works.
280
-
281
- Use one of these instead:
282
-
283
- ```bash
284
- wrangler-accounts whoami --profile Xdreamstar2025 # fast, reads meta.json, no network
285
- wrangler-accounts list --deep # authoritative, runs wrangler whoami per profile
286
- wrangler-accounts list # quick STATUS overview (valid / valid* / EXPIRED / unknown)
287
- ```
288
-
289
- Only fall back to `wrangler-accounts login <name>` when:
290
- - The profile **does not exist yet** (creating a new account profile from scratch)
291
- - The profile shows `EXPIRED` (truly expired, no refresh_token left) — see STATUS table above
292
- - `list --deep` returns `✗` with "Not logged in" / "refresh token may be revoked" (server-side revocation)
293
- - The user **explicitly says** "re-authenticate this profile" / "log me in again"
294
-
295
- ### User wants: check which account a profile is tied to, without running wrangler
296
-
297
- ```bash
298
- wrangler-accounts whoami --profile <name> # text
299
- wrangler-accounts whoami --profile <name> --json # structured
300
- ```
301
-
302
- Returns the email + account ID from the saved `meta.json`. No network call.
303
-
304
- ### User wants: swap between many accounts quickly in one shell
305
-
306
- Use `default` as a "current" setting:
307
-
308
- ```bash
309
- wrangler-accounts default work
310
- wrangler-accounts deploy # work
311
- wrangler-accounts default personal
312
- wrangler-accounts dev # personal
313
- ```
314
-
315
- Or use positional shorthand inline:
316
-
317
- ```bash
318
- wrangler-accounts work deploy # one-shot, no persistent default
319
- wrangler-accounts personal dev
320
- ```
321
-
322
- ### User wants: run wrangler in CI with multiple accounts
323
-
324
- **Don't use `wrangler-accounts` in CI.** Use native env vars:
325
-
326
- ```bash
327
- # In CI secrets:
328
- CLOUDFLARE_API_TOKEN=<token-with-workers-deploy-scope>
329
- CLOUDFLARE_ACCOUNT_ID=<account-id>
330
-
331
- # In the pipeline:
332
- wrangler deploy
333
- ```
334
-
335
- `wrangler-accounts` is for **local developer** OAuth sessions. CI should use long-lived API tokens directly with plain `wrangler`. Recommend this even if the user asks to use `wrangler-accounts` in CI.
336
-
337
- ## Troubleshooting
338
-
339
- ### "Profile 'X' has expired Wrangler OAuth credentials and no refresh_token to renew them"
340
-
341
- The saved OAuth access_token is past its `expiration_time` AND there is no `refresh_token` in the profile config (no `offline_access` scope at login time, or the token was revoked). The profile is genuinely broken; only re-authenticating fixes it:
342
-
343
- ```bash
344
- wrangler-accounts login <name>
345
- ```
346
-
347
- This overwrites the existing profile with a fresh OAuth session. Any saved metadata (identity, etc.) is re-verified.
348
-
349
- **Note:** If you see this error in 1.5.0 or earlier, you may be hitting a known regression: any profile whose access_token had passed expiration was blocked even when a refresh_token was present. Upgrade to 1.5.1+ — `wrangler` itself silently refreshes those tokens on the next call, so wrangler-accounts no longer pre-flights against `expiration_time` alone.
350
-
351
- ### "No profile specified. Options: ..."
352
-
353
- The user ran `wrangler-accounts <wrangler-args>` without a resolvable profile. Fix one of:
354
-
355
- ```bash
356
- wrangler-accounts --profile <name> <args> # one-shot
357
- WRANGLER_PROFILE=<name> wrangler-accounts <args> # env var
358
- wrangler-accounts default <name> # persistent default
359
- ```
360
-
361
- **1.6.0+**: if `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` are both present in the environment, this error no longer fires — the tool runs in anonymous-token mode automatically.
362
-
363
- ### "Profile not found: X"
364
-
365
- The profile name doesn't exist in `profilesDir`. Check what's saved:
366
-
367
- ```bash
368
- wrangler-accounts list
369
- ```
370
-
371
- Create it with `wrangler-accounts login <name>` or copy an existing Wrangler login with `wrangler-accounts save <name>`.
372
-
373
- ### Inside `wrangler-accounts exec`, `cd ~` lands in a weird tmpdir
374
-
375
- Expected. Inside an `exec` session, `$HOME` is the shadow HOME. The real home is still accessible:
376
-
377
- ```bash
378
- cd "$WRANGLER_ACCOUNT_REAL_HOME"
379
- ```
380
-
381
- Or users can add a shell alias: `alias realhome='cd "$WRANGLER_ACCOUNT_REAL_HOME"'`.
382
-
383
- ### Deprecated `use` command warning
384
-
385
- `wrangler-accounts use <name>` still works but prints a deprecation warning. Suggest the replacement based on intent:
386
-
387
- - "I want this account to stick for a while" → `wrangler-accounts default <name>`
388
- - "Just this one command" → `wrangler-accounts --profile <name> <wrangler-args>`
389
-
390
- ### `[ERROR] A request to the Cloudflare API ... Authentication error [code: 10000]` with `code: 7403` ("not authorized to access this service")
391
-
392
- The OAuth token is fine but **the URL contains the wrong account ID**. wrangler caches the user's selected account in `wrangler-account.json`. If that cache file is shared across profiles, profile A's OAuth token gets paired with profile B's cached account ID, sending API calls to the wrong account. Symptoms:
393
-
394
- - `deploy` and `secret put` succeed (they don't put account ID in the URL path)
395
- - `d1 execute --remote`, `r2 object get/put`, anything else with `/accounts/<id>/...` in the URL fails with 7403
396
-
397
- **Fix path** (in order):
398
-
399
- 1. **Are you on wrangler-accounts ≥ 1.2.2?** Run `wrangler-accounts --version`. If `< 1.2.2`, upgrade — earlier versions pointed `WRANGLER_CACHE_DIR` at a shared global path. 1.2.2 isolates the cache per profile.
400
- 2. **Clear the polluted shared cache** (one-time, even after upgrading):
401
- ```bash
402
- rm -f ~/.wrangler/cache/wrangler-account.json
403
- rm -f ~/Library/Preferences/.wrangler/cache/wrangler-account.json # macOS env-paths fallback
404
- ```
405
- 3. **Verify with `wrangler-accounts list --deep`** — the VERIFIED column for each profile should be `✓ ok`. If `✗`, the underlying OAuth session itself is broken; run `wrangler-accounts login <name>`.
406
- 4. **Defense in depth**: set `CLOUDFLARE_ACCOUNT_ID=<correct-id>` in the calling environment. wrangler reads this env var directly and bypasses the cache entirely. Useful for scripts or one-off recovery commands:
407
- ```bash
408
- CLOUDFLARE_ACCOUNT_ID=<id> wrangler-accounts <profile> r2 object put ...
409
- ```
410
-
411
- **What to tell the user**: "wrangler returned 7403 because it cached the wrong account ID alongside your OAuth token. This was a real bug in wrangler-accounts ≤ 1.2.1 (shared cache directory across profiles). Upgrade to 1.2.2 and clear the polluted cache."
412
-
413
- ### "The OAuth config seems right, but the wrong account is being used"
414
-
415
- Same root cause as the 7403 above. Default to the same fix path.
416
-
417
- ### `wrangler dev` (or any `--local` command) shows stale data after switching profiles
418
-
419
- Project-local state at `<project>/.wrangler/state/` is **NOT** isolated per profile — wrangler's `getLocalPersistencePath` (cli.js:149025) hardcodes the path next to `wrangler.toml` and the only override is the `--persist-to` CLI flag (no env var hook). So if profile A's `wrangler dev` populated a local D1 emulation, then you switch to profile B and run `wrangler dev` in the same directory, B sees A's emulated rows.
420
-
421
- This only affects `--local` simulations. **`--remote` commands hit Cloudflare directly and are unaffected** — that's the common case for d1/r2 work in a multi-account setup.
422
-
423
- Two clean fixes:
424
-
425
- 1. **Use git worktrees** (recommended for any serious multi-profile dev workflow):
426
- ```bash
427
- git worktree add ../my-project-work main
428
- git worktree add ../my-project-personal main
429
- cd ../my-project-work && wrangler-accounts exec work # isolated .wrangler/state/
430
- cd ../my-project-personal && wrangler-accounts exec personal
431
- ```
432
- 2. **Clear state manually before switching**:
433
- ```bash
434
- rm -rf .wrangler/state
435
- wrangler-accounts --profile <new> dev
436
- ```
437
-
438
- `wrangler-accounts` does not auto-isolate `.wrangler/state/` because the only mechanism would be argv injection of `--persist-to`, which has too many failure modes (different subcommands accept persistTo at different positions, can't override user-supplied flags, path selection is ambiguous between per-profile and per-profile-per-project). The honest tradeoff is documented in the "What is and isn't isolated" table above — partial isolation with hidden gotchas would be worse than honest sharing.
439
-
440
- ### Shell history / `.zsh_history` seems to grow when running `exec`
441
-
442
- Intentional. By design the shadow HOME symlinks all top-level entries of real HOME except `.wrangler`, so shell history writes pass through to the real file. This is a **convenience** bias, not a clean-room sandbox — the goal is that `exec` subshells feel like a normal terminal with a different Cloudflare account, not a jail.
443
-
444
- ## Invariants the AI should rely on
445
-
446
- - **Real `~/.wrangler/config/default.toml` is never written to by `wrangler-accounts`.** If a user reports that it changed, something else touched it (e.g. a direct `wrangler login` outside `wrangler-accounts`).
447
- - **Two `wrangler-accounts --profile A` and `wrangler-accounts --profile B` running in parallel never clobber each other on credentials OR account-id cache.** Each gets its own `mkdtemp` shadow HOME, and each gets its own per-profile `WRANGLER_CACHE_DIR` (next to the profile's `config.toml`) so that wrangler's `wrangler-account.json` (which stores the selected Cloudflare account ID) is naturally isolated.
448
- - **OAuth token refresh inside a profile is automatic.** The shadow HOME contains a symlink from `.wrangler/config/default.toml` to the saved profile file, so Wrangler's in-place `fs.writeFileSync` during `refreshToken()` flows straight back to the profile.
449
- - **`wrangler-accounts <args>` without a management subcommand forwards everything to wrangler verbatim**, including `--env`, `--dry-run`, `--json`, and any wrangler-native flags. The only flags consumed by `wrangler-accounts` itself are the ones listed in "Paths and environment" below.
450
-
451
- ## What is and isn't isolated
452
-
453
- | State | Location | Isolated? |
454
- |---|---|---|
455
- | OAuth credentials (`config.toml`) | shadow `$HOME/.wrangler/config/default.toml` → symlink to per-profile file | ✅ per profile |
456
- | Account-id cache (`wrangler-account.json`) | per-profile `WRANGLER_CACHE_DIR` (= `<profilesDir>/<name>/cache/`) | ✅ per profile |
457
- | Pages config cache (`pages-config-cache.json`) | same as above | ✅ per profile |
458
- | Miniflare dev registry | `WRANGLER_REGISTRY_PATH` = `$realHome/.wrangler/registry` | ❌ shared on purpose (cross-profile worker discovery during local dev) |
459
- | Wrangler debug logs | `WRANGLER_LOG_PATH` = `$realHome/.wrangler/logs` | ❌ shared (append-only, harmless) |
460
- | Project-local state (`./.wrangler/state/`, `./node_modules/.cache/wrangler`) | inside the project directory | ❌ shared at project level (per-project, but not per-profile) |
461
- | `cloudflared` binary | `CLOUDFLARED_PATH` or `~/.wrangler/cloudflared/` | ❌ shared (binary, not account-scoped) |
462
- | Shell history, npm cache, git config, ssh keys | symlinked through to real `$HOME` | ❌ shared by design (so `exec` subshells feel like a normal terminal) |
463
-
464
- If a user is hitting a "wrong account" symptom and the credentials look right, the most likely culprit is **project-local state** in `./.wrangler/state/` — clear that and re-run.
465
-
466
- ## CI guidance
467
-
468
- For CI and deploy pipelines you have two options:
469
-
470
- **Option 1 — plain `wrangler` with env vars (simplest for CI):**
471
-
472
- ```bash
473
- CLOUDFLARE_API_TOKEN=<token>
474
- CLOUDFLARE_ACCOUNT_ID=<account-id>
475
- wrangler deploy
476
- ```
477
-
478
- **Option 2 — `wrangler-accounts` with a token profile (useful when you want the same CLI both locally and in CI):**
479
-
480
- ```bash
481
- # Save once (locally or during CI bootstrap):
482
- wrangler-accounts token-add work "$CF_TOKEN" "$CF_ACCOUNT_ID"
483
- # Use the same commands locally and in CI:
484
- wrangler-accounts --profile work deploy
485
- ```
486
-
487
- Or use the anonymous pass-through (no profile needed if env vars are present):
488
-
489
- ```bash
490
- CLOUDFLARE_API_TOKEN="$CF_TOKEN" CLOUDFLARE_ACCOUNT_ID="$CF_ACCOUNT_ID" wrangler-accounts deploy
491
- ```
492
-
493
- `wrangler-accounts` is primarily a local developer convenience for juggling OAuth sessions on your workstation, but since 1.6.0 it also supports API token profiles for teams that want a consistent CLI interface across local and CI environments.
494
-
495
- ## Paths and environment
496
-
497
- - `--profile <name>` / `-p <name>` — profile for this invocation (v1.0: `-p` means `--profile`)
498
- - `--profiles <path>` — profiles directory (long form only since v1.0)
499
- - `-c, --config <path>` — Wrangler config path
500
- - `WRANGLER_PROFILE` — profile to use when no `--profile` flag is given
501
- - `WRANGLER_CONFIG_PATH`, `WRANGLER_ACCOUNTS_DIR`, `XDG_CONFIG_HOME` — path overrides
502
-
503
- ## Output conventions
504
-
505
- Use `--json` when another tool needs to parse results. All v1.0 commands that produce structured data support `--json`.
506
-
507
- ## Naming rules
508
-
509
- Profile names: letters, numbers, dot, underscore, dash only. Names matching management subcommand names (`exec`, `default`, `whoami`, `gc`, `login`, `token-add`, `list`, `status`, `save`, `sync`, `sync-default`, `remove`, `use`, `sync-active`) cannot be reached via positional shorthand — use `--profile <name>` for those.
510
-
511
- ## Deprecated
512
-
513
- - `wrangler-accounts use <name>` — deprecated, prints warning. Use `default <name>` for persistence or `--profile <name>` for one-shot.
514
- - `wrangler-accounts sync-active` — deprecated alias for `sync-default`.