@leeguoo/wrangler-accounts 1.4.0 → 1.5.1

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.
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "leeguoo-tools",
3
+ "owner": {
4
+ "name": "Lee Guo"
5
+ },
6
+ "metadata": {
7
+ "description": "Claude Code plugins for practical developer workflows from the wrangler-accounts author.",
8
+ "version": "1.5.1"
9
+ },
10
+ "plugins": [
11
+ {
12
+ "name": "wrangler-accounts",
13
+ "source": "./plugins/wrangler-accounts",
14
+ "description": "Cloudflare Wrangler multi-account skill plus a Bash hook that blocks raw wrangler calls when local profiles are configured.",
15
+ "version": "1.5.1",
16
+ "author": {
17
+ "name": "Lee Guo"
18
+ },
19
+ "homepage": "https://github.com/leeguooooo/wrangler-accounts#readme",
20
+ "repository": "https://github.com/leeguooooo/wrangler-accounts",
21
+ "license": "MIT",
22
+ "keywords": [
23
+ "cloudflare",
24
+ "wrangler",
25
+ "accounts",
26
+ "multi-account",
27
+ "claude-code",
28
+ "hook",
29
+ "skill"
30
+ ]
31
+ }
32
+ ]
33
+ }
package/README.md CHANGED
@@ -20,19 +20,59 @@ wrangler-accounts --profile work tail my-worker
20
20
  wrangler-accounts --profile personal dev
21
21
  ```
22
22
 
23
+ ## Claude Code users (recommended)
24
+
25
+ Install the marketplace and plugin first:
26
+
27
+ ```text
28
+ /plugin marketplace add leeguooooo/wrangler-accounts
29
+ /plugin install wrangler-accounts@leeguoo-tools
30
+ ```
31
+
32
+ The plugin bundles the `wrangler-accounts` skill plus a Bash `PreToolUse` hook, so Claude Code can learn the workflow and block raw `wrangler` calls before they bypass your local profile isolation. No manual `settings.json` editing is required.
33
+
34
+ The plugin does **not** install the CLI binary. Keep the npm package on your `PATH`:
35
+
36
+ ```bash
37
+ npm i -g @leeguoo/wrangler-accounts
38
+ ```
39
+
40
+ The guard only blocks direct `wrangler ...` Bash commands when all of these are true:
41
+
42
+ - `wrangler-accounts` is installed on `PATH`
43
+ - at least one local profile is configured
44
+ - the current directory looks like a Cloudflare project (`wrangler.toml`, `wrangler.json`, or `wrangler.jsonc`) or Cloudflare API env vars are set
45
+
46
+ If you explicitly want raw `wrangler`, bypass the hook for that command:
47
+
48
+ ```bash
49
+ NOWRANGLER_ACCOUNTS_GUARD=1 wrangler deploy
50
+ ```
51
+
52
+ ### Upgrading from the `skills.sh` install
53
+
54
+ If you previously installed this skill via `npx skills add leeguooooo/wrangler-accounts`, remove that standalone copy after installing the plugin — otherwise Claude Code's slash command picker shows two identical `/wrangler-accounts` entries (one from the skills.sh directory, one from the plugin):
55
+
56
+ ```bash
57
+ npx skills remove wrangler-accounts
58
+ # or, if the CLI is missing: rm -rf ~/.agents/skills/wrangler-accounts
59
+ ```
60
+
61
+ Then run `/reload-plugins` and confirm only one entry remains.
62
+
23
63
  ## What it does
24
64
 
25
65
  Every execution runs `wrangler` inside a per-invocation **shadow HOME** — a temporary directory that mirrors most of your real home, except `.wrangler/config/default.toml` is a symlink pointing at the saved profile's config. Token refreshes flow back to the profile automatically. Nothing touches your real `~/.wrangler`. Two parallel invocations get two independent shadow HOMEs.
26
66
 
27
67
  ## Install
28
68
 
29
- You need **two** things to get the full experience — the CLI binary (what actually runs) and the AI agent skill (what teaches your AI coding agent how to use it). Install both:
69
+ If you do **not** use Claude Code plugins, install the CLI binary and the mirrored `skills.sh` skill separately:
30
70
 
31
71
  ```bash
32
72
  # 1. The CLI (always required)
33
73
  npm i -g @leeguoo/wrangler-accounts
34
74
 
35
- # 2. The AI agent skill (recommended if you use Claude Code / Cursor / Codex / etc.)
75
+ # 2. The AI agent skill mirror (recommended if you use Cursor / Codex / Gemini CLI / etc.)
36
76
  npx skills add leeguooooo/wrangler-accounts -g -y
37
77
  ```
38
78
 
@@ -47,9 +87,9 @@ The CLI works standalone — you can skip step 2 if you don't use an AI coding a
47
87
 
48
88
  The AI will tell you to run commands like `wrangler-accounts --profile work deploy`; without step 1 those commands fail with "command not found".
49
89
 
50
- ### AI agent skill — more options
90
+ ### `skills.sh` mirror — more options
51
91
 
52
- The repo ships an Agent Skill (`skills/wrangler-accounts/SKILL.md`) with multi-account deploy recipes, troubleshooting, CI guidance, and invariants AI can rely on. [skills.sh](https://skills.sh)'s CLI auto-detects which agent you use (Claude Code, Cursor, Codex, Gemini CLI, OpenCode, and 40+ others) and installs to the right directory.
92
+ The repo keeps a mirrored Agent Skill at `skills/wrangler-accounts/SKILL.md` for [skills.sh](https://skills.sh). Claude Code users should prefer the plugin marketplace flow above; other agents can keep using `skills.sh` to install the same guidance markdown into their own skill directories.
53
93
 
54
94
  ```bash
55
95
  npx skills add leeguooooo/wrangler-accounts -g -y # user-global, non-interactive
@@ -293,9 +293,9 @@ function useProfile(name, configPath, profilesDir, backup) {
293
293
  }
294
294
 
295
295
  const session = readSessionState(profileConfig);
296
- if (session.expired) {
296
+ if (session.effective === 'expired') {
297
297
  die(
298
- `Profile '${name}' has expired Wrangler OAuth credentials (expiration_time: ${session.expirationTime}). Run 'wrangler-accounts login ${name}' to refresh it.`
298
+ `Profile '${name}' has expired Wrangler OAuth credentials and no refresh_token to renew them (expiration_time: ${session.expirationTime}). Run 'wrangler-accounts login ${name}' to re-authenticate.`
299
299
  );
300
300
  }
301
301
 
@@ -409,9 +409,9 @@ function main() {
409
409
 
410
410
  const profileCfg = path.join(profilesDir, resolved.name, "config.toml");
411
411
  const session = readSessionState(profileCfg);
412
- if (session.expired) {
412
+ if (session.effective === 'expired') {
413
413
  die(
414
- `Profile '${resolved.name}' has expired Wrangler OAuth credentials (expiration_time: ${session.expirationTime}). Run 'wrangler-accounts login ${resolved.name}' to refresh it.`,
414
+ `Profile '${resolved.name}' has expired Wrangler OAuth credentials and no refresh_token to renew them (expiration_time: ${session.expirationTime}). Run 'wrangler-accounts login ${resolved.name}' to re-authenticate.`,
415
415
  3
416
416
  );
417
417
  }
@@ -1075,9 +1075,9 @@ function main() {
1075
1075
 
1076
1076
  const profileCfg = path.join(profilesDir, resolved.name, "config.toml");
1077
1077
  const session = readSessionState(profileCfg);
1078
- if (session.expired) {
1078
+ if (session.effective === 'expired') {
1079
1079
  die(
1080
- `Profile '${resolved.name}' has expired Wrangler OAuth credentials. Run 'wrangler-accounts login ${resolved.name}' to refresh it.`,
1080
+ `Profile '${resolved.name}' has expired Wrangler OAuth credentials and no refresh_token to renew them. Run 'wrangler-accounts login ${resolved.name}' to re-authenticate.`,
1081
1081
  3
1082
1082
  );
1083
1083
  }
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@leeguoo/wrangler-accounts",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
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": {
7
7
  "wrangler-accounts": "bin/wrangler-accounts.js"
8
8
  },
9
9
  "files": [
10
+ ".claude-plugin",
10
11
  "bin",
11
12
  "lib",
12
13
  "completions",
14
+ "plugins",
13
15
  "skills"
14
16
  ],
15
17
  "keywords": [
@@ -55,7 +57,8 @@
55
57
  "scripts": {
56
58
  "test": "node --test test/*.test.js",
57
59
  "verify-package": "node scripts/verify-package.js",
58
- "prepublishOnly": "npm test && npm run verify-package"
60
+ "check-skill-sync": "node -e \"const fs=require('fs');const a='skills/wrangler-accounts/SKILL.md';const b='plugins/wrangler-accounts/skills/wrangler-accounts/SKILL.md';if(fs.readFileSync(a,'utf8')!==fs.readFileSync(b,'utf8')){console.error('SKILL.md sync check failed: keep skills/wrangler-accounts/SKILL.md and plugins/wrangler-accounts/skills/wrangler-accounts/SKILL.md identical.');process.exit(1)}\"",
61
+ "prepublishOnly": "npm test && npm run verify-package && npm run check-skill-sync"
59
62
  },
60
63
  "engines": {
61
64
  "node": ">=16"
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "wrangler-accounts",
3
+ "description": "Cloudflare Wrangler multi-account helper with a bundled skill and Bash guard hook for Claude Code.",
4
+ "version": "1.5.1",
5
+ "author": {
6
+ "name": "Lee Guo"
7
+ },
8
+ "homepage": "https://github.com/leeguooooo/wrangler-accounts#readme",
9
+ "repository": "https://github.com/leeguooooo/wrangler-accounts",
10
+ "license": "MIT"
11
+ }
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ INPUT_JSON="$(cat)"
5
+
6
+ parse_with_jq() {
7
+ TOOL_NAME="$(printf '%s' "$INPUT_JSON" | jq -r '.tool_name // empty' 2>/dev/null || true)"
8
+ TOOL_COMMAND="$(printf '%s' "$INPUT_JSON" | jq -r '.tool_input.command // empty' 2>/dev/null || true)"
9
+ }
10
+
11
+ parse_with_python() {
12
+ local parsed
13
+ parsed="$(
14
+ printf '%s' "$INPUT_JSON" | python3 -c '
15
+ import json
16
+ import sys
17
+
18
+ try:
19
+ payload = json.load(sys.stdin)
20
+ except Exception:
21
+ print("")
22
+ print("")
23
+ raise SystemExit(0)
24
+
25
+ print(payload.get("tool_name", ""))
26
+ print(payload.get("tool_input", {}).get("command", ""))
27
+ ' 2>/dev/null || true
28
+ )"
29
+ TOOL_NAME="$(printf '%s\n' "$parsed" | sed -n '1p')"
30
+ TOOL_COMMAND="$(printf '%s\n' "$parsed" | sed -n '2,$p')"
31
+ }
32
+
33
+ TOOL_NAME=""
34
+ TOOL_COMMAND=""
35
+
36
+ if command -v jq >/dev/null 2>&1; then
37
+ parse_with_jq
38
+ elif command -v python3 >/dev/null 2>&1; then
39
+ parse_with_python
40
+ else
41
+ exit 0
42
+ fi
43
+
44
+ [ "${TOOL_NAME:-}" = "Bash" ] || exit 0
45
+ [ -n "${TOOL_COMMAND:-}" ] || exit 0
46
+
47
+ if [ "${NOWRANGLER_ACCOUNTS_GUARD:-}" = "1" ]; then
48
+ exit 0
49
+ fi
50
+
51
+ case "$TOOL_COMMAND" in
52
+ *NOWRANGLER_ACCOUNTS_GUARD=1*)
53
+ exit 0
54
+ ;;
55
+ esac
56
+
57
+ if [ -n "${CLOUDFLARE_API_TOKEN:-}" ] || [ -n "${CLOUDFLARE_ACCOUNT_ID:-}" ]; then
58
+ :
59
+ elif [ -f "wrangler.toml" ] || [ -f "wrangler.jsonc" ] || [ -f "wrangler.json" ]; then
60
+ :
61
+ else
62
+ exit 0
63
+ fi
64
+
65
+ if printf '%s' "$TOOL_COMMAND" | grep -Eq '(^|[[:space:];(|&])(npx|pnpm|yarn|bunx)[[:space:]]+wrangler[[:space:]]'; then
66
+ exit 0
67
+ fi
68
+
69
+ if ! printf '%s' "$TOOL_COMMAND" | grep -Eq '(^|[[:space:];(|&])wrangler[[:space:]]'; then
70
+ exit 0
71
+ fi
72
+
73
+ if ! command -v wrangler-accounts >/dev/null 2>&1; then
74
+ exit 0
75
+ fi
76
+
77
+ PROFILES="$(wrangler-accounts list --plain 2>/dev/null || true)"
78
+ [ -n "$PROFILES" ] || exit 0
79
+
80
+ DEFAULT_PROFILE="$(wrangler-accounts default 2>/dev/null || true)"
81
+
82
+ {
83
+ echo "wrangler-accounts guard: blocked a direct \`wrangler\` command."
84
+ echo
85
+ echo "Direct \`wrangler\` calls bypass wrangler-accounts profile isolation when local profiles are configured."
86
+ echo "Retry with one of these forms instead:"
87
+ echo
88
+ echo " wrangler-accounts --profile <name> <wrangler-args...>"
89
+ echo " wrangler-accounts exec <name> -- <your-original-command>"
90
+ echo
91
+ echo "Configured profiles:"
92
+ printf '%s\n' "$PROFILES" | sed 's/^/ - /'
93
+ echo "Default profile: ${DEFAULT_PROFILE:-"(none)"}"
94
+ echo
95
+ echo "If the user explicitly wants raw wrangler, prepend NOWRANGLER_ACCOUNTS_GUARD=1."
96
+ } >&2
97
+
98
+ exit 2
@@ -0,0 +1,15 @@
1
+ {
2
+ "hooks": {
3
+ "PreToolUse": [
4
+ {
5
+ "matcher": "Bash",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "${CLAUDE_PLUGIN_ROOT}/hooks/guard-wrangler.sh"
10
+ }
11
+ ]
12
+ }
13
+ ]
14
+ }
15
+ }
@@ -0,0 +1,461 @@
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
+
70
+ ```bash
71
+ npm i -g @leeguoo/wrangler-accounts@latest # always-safe upgrade
72
+ ```
73
+
74
+ ## Triage flow — when something looks wrong
75
+
76
+ **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.
77
+
78
+ ```bash
79
+ # 1. Verify your binary is recent enough (see version table above)
80
+ wrangler-accounts --version
81
+
82
+ # 2. Authoritative state of every profile (hits Cloudflare API per profile)
83
+ wrangler-accounts list --deep
84
+ ```
85
+
86
+ How to read `list --deep` output:
87
+
88
+ | You see | Meaning | What to do |
89
+ |---|---|---|
90
+ | `STATUS valid` + `VERIFIED ✓ ok` | profile is fine | nothing — proceed with whatever the user actually asked |
91
+ | `STATUS valid*` + `VERIFIED ✓ ok` | profile is fine; access token will auto-refresh on next use | nothing — **`valid*` is healthy, do NOT re-login** |
92
+ | `STATUS EXPIRED` + `VERIFIED ✓ ok` | rare; only on `< 1.3.0` binaries — STATUS is lying | upgrade the CLI; profile is fine |
93
+ | `STATUS EXPIRED` + `VERIFIED ✗ Not logged in` | profile is genuinely broken | `wrangler-accounts login <name>` (interactive only) |
94
+ | `STATUS valid` + `VERIFIED ✗` of any kind | refresh token revoked server-side | `wrangler-accounts login <name>` (interactive only) |
95
+ | `STATUS unknown` | profile file lacks `expiration_time` | run `--deep` (already did) — trust VERIFIED |
96
+
97
+ **Rule**: only suggest `wrangler-accounts login <name>` when at least one of:
98
+ 1. `list --deep` showed `VERIFIED ✗` for that profile, OR
99
+ 2. The profile doesn't exist at all yet, OR
100
+ 3. The user explicitly says "re-authenticate" / "log me in again"
101
+
102
+ **If `list --deep` shows everything ✓ but a wrangler command still fails**, the root cause is somewhere other than wrangler-accounts — most likely:
103
+ - Project-local `./.wrangler/state/` is sharing data across profiles (see "What is and isn't isolated")
104
+ - The project's `wrangler.toml` has the wrong `account_id` hardcoded
105
+ - The user is on a CLI version below 1.2.2 (account-id cache leak)
106
+ - The wrangler subcommand actually needs `--remote` or `--local` and you forgot
107
+
108
+ ## Quick Start
109
+
110
+ - `wrangler-accounts login <name>` — interactive OAuth login into a new profile (never touches real `~/.wrangler`)
111
+ - `wrangler-accounts default <name>` — set the persistent default profile
112
+ - `wrangler-accounts deploy` — run `wrangler deploy` under the default profile
113
+ - `wrangler-accounts --profile personal deploy` — one-shot override
114
+ - `wrangler-accounts exec work -- npm run release` — run a command in an isolated subshell for the `work` profile
115
+
116
+ > 💡 **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".
117
+
118
+ ## Tasks
119
+
120
+ ### Run wrangler against a profile
121
+
122
+ Per-invocation (preferred for scripts):
123
+
124
+ `wrangler-accounts --profile <name> <wrangler-args...>`
125
+
126
+ Or with env var:
127
+
128
+ `WRANGLER_PROFILE=<name> wrangler-accounts <wrangler-args...>`
129
+
130
+ Or positional shorthand (only when `<name>` is a saved profile name, not a management subcommand):
131
+
132
+ `wrangler-accounts <name> <wrangler-args...>`
133
+
134
+ ### Open a subshell for a profile
135
+
136
+ `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`.
137
+
138
+ Run a single command instead:
139
+
140
+ `wrangler-accounts exec <name> -- <cmd> [args]`
141
+
142
+ ### Manage the persistent default profile
143
+
144
+ - `wrangler-accounts default` — print current default (exit 1 if none set)
145
+ - `wrangler-accounts default <name>` — set the default
146
+ - `wrangler-accounts default --unset` — clear the default
147
+ - `wrangler-accounts default --json` — JSON output
148
+
149
+ ### Show the resolved identity for a profile
150
+
151
+ `wrangler-accounts whoami [--profile <name>]` — reports the profile name, source tier (cli / positional / env / default), and identity from `meta.json`. Does not spawn wrangler.
152
+
153
+ Use `--json` for structured output.
154
+
155
+ ### List and inspect profiles
156
+
157
+ - `wrangler-accounts list` — text table with NAME / STATUS / EXPIRES / IDENTITY columns
158
+ - `wrangler-accounts list --json` — structured: array of `{name, isDefault, isActive, status, expirationTime, hasRefreshToken, identity, verified, verifyError}`
159
+ - `wrangler-accounts list --plain` — one profile name per line (scriptable)
160
+ - `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.
161
+ - `wrangler-accounts status` / `status --json`
162
+ - Pass `--include-backups` to show hidden backup profiles.
163
+
164
+ **STATUS values (1.3.0+):**
165
+
166
+ | value | meaning | user action |
167
+ |---|---|---|
168
+ | `valid` | access_token is currently valid | none |
169
+ | `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 |
170
+ | `EXPIRED` / `expired` | access_token expired **AND** no refresh_token saved; profile is genuinely broken | `wrangler-accounts login <name>` |
171
+ | `unknown` | profile file has no `expiration_time` field | run `list --deep` to verify live |
172
+
173
+ **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.
174
+
175
+ The only time a user actually needs `wrangler-accounts login <name>` again is:
176
+ 1. STATUS is `EXPIRED` (no refresh_token at all — profile was saved without `offline_access` scope)
177
+ 2. OR `list --deep` returns `✗` with "Not logged in" / "refresh token may be revoked" (refresh token itself got invalidated)
178
+
179
+ ### Save, sync, login, remove
180
+
181
+ - `wrangler-accounts save <name>` — snapshot current Wrangler config as a profile
182
+ - `wrangler-accounts sync <name>` — refresh a specific profile from the current login
183
+ - `wrangler-accounts sync-default` — refresh the default profile
184
+ - `wrangler-accounts login <name>` — fresh isolated OAuth login
185
+ - `wrangler-accounts remove <name>` — delete a profile
186
+
187
+ ### Clean up stale shadow HOMEs
188
+
189
+ `wrangler-accounts gc [--older-than 1h]` — removes `wa-*` directories under `$TMPDIR` older than the threshold (default 1h). Safe to run at any time.
190
+
191
+ ## Common Recipes
192
+
193
+ 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.
194
+
195
+ ### User wants: deploy a worker to a specific account
196
+
197
+ ```bash
198
+ wrangler-accounts --profile work deploy
199
+ ```
200
+
201
+ Or, when the user will be on this account for a while:
202
+
203
+ ```bash
204
+ wrangler-accounts default work # set once
205
+ wrangler-accounts deploy # uses work from now on
206
+ wrangler-accounts deploy --env staging # wrangler flags pass through unchanged
207
+ ```
208
+
209
+ ### User wants: tail production logs on one account while developing on another
210
+
211
+ ```bash
212
+ # shell 1
213
+ wrangler-accounts --profile work tail my-worker --format pretty
214
+
215
+ # shell 2 (simultaneously, zero interference)
216
+ wrangler-accounts --profile personal dev
217
+ ```
218
+
219
+ The two shells each get their own shadow `HOME`, so there's no global state for the other to clobber.
220
+
221
+ ### User wants: run a deploy script / npm script / Makefile against a specific account
222
+
223
+ ```bash
224
+ wrangler-accounts exec work -- npm run deploy
225
+ wrangler-accounts exec work -- make release
226
+ wrangler-accounts exec work -- bash scripts/deploy.sh
227
+ ```
228
+
229
+ Anything inside the subshell that calls `wrangler` (directly, via `npx`, via `pnpm`, via a package.json script) automatically uses the `work` profile.
230
+
231
+ ### User wants: set up a new Cloudflare account from scratch
232
+
233
+ ```bash
234
+ wrangler-accounts login new-account # opens the browser OAuth flow
235
+ wrangler-accounts whoami --profile new-account # verify identity
236
+ wrangler-accounts list # confirm the profile is saved
237
+ ```
238
+
239
+ The login flow runs inside an isolated shadow `HOME`, so the user's real `~/.wrangler/config/default.toml` is never touched.
240
+
241
+ > ⚠️ **`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.
242
+
243
+ ### ❌ Antipattern: running `login` to verify a profile works
244
+
245
+ This is wrong:
246
+ ```bash
247
+ wrangler-accounts login Xdreamstar2025 # ❌ DON'T do this just to check
248
+ ```
249
+
250
+ Reasons:
251
+ 1. `login` is **destructive** — it overwrites the saved profile with a brand new OAuth flow.
252
+ 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.
253
+ 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.
254
+
255
+ Use one of these instead:
256
+
257
+ ```bash
258
+ wrangler-accounts whoami --profile Xdreamstar2025 # fast, reads meta.json, no network
259
+ wrangler-accounts list --deep # authoritative, runs wrangler whoami per profile
260
+ wrangler-accounts list # quick STATUS overview (valid / valid* / EXPIRED / unknown)
261
+ ```
262
+
263
+ Only fall back to `wrangler-accounts login <name>` when:
264
+ - The profile **does not exist yet** (creating a new account profile from scratch)
265
+ - The profile shows `EXPIRED` (truly expired, no refresh_token left) — see STATUS table above
266
+ - `list --deep` returns `✗` with "Not logged in" / "refresh token may be revoked" (server-side revocation)
267
+ - The user **explicitly says** "re-authenticate this profile" / "log me in again"
268
+
269
+ ### User wants: check which account a profile is tied to, without running wrangler
270
+
271
+ ```bash
272
+ wrangler-accounts whoami --profile <name> # text
273
+ wrangler-accounts whoami --profile <name> --json # structured
274
+ ```
275
+
276
+ Returns the email + account ID from the saved `meta.json`. No network call.
277
+
278
+ ### User wants: swap between many accounts quickly in one shell
279
+
280
+ Use `default` as a "current" setting:
281
+
282
+ ```bash
283
+ wrangler-accounts default work
284
+ wrangler-accounts deploy # work
285
+ wrangler-accounts default personal
286
+ wrangler-accounts dev # personal
287
+ ```
288
+
289
+ Or use positional shorthand inline:
290
+
291
+ ```bash
292
+ wrangler-accounts work deploy # one-shot, no persistent default
293
+ wrangler-accounts personal dev
294
+ ```
295
+
296
+ ### User wants: run wrangler in CI with multiple accounts
297
+
298
+ **Don't use `wrangler-accounts` in CI.** Use native env vars:
299
+
300
+ ```bash
301
+ # In CI secrets:
302
+ CLOUDFLARE_API_TOKEN=<token-with-workers-deploy-scope>
303
+ CLOUDFLARE_ACCOUNT_ID=<account-id>
304
+
305
+ # In the pipeline:
306
+ wrangler deploy
307
+ ```
308
+
309
+ `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.
310
+
311
+ ## Troubleshooting
312
+
313
+ ### "Profile 'X' has expired Wrangler OAuth credentials and no refresh_token to renew them"
314
+
315
+ 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:
316
+
317
+ ```bash
318
+ wrangler-accounts login <name>
319
+ ```
320
+
321
+ This overwrites the existing profile with a fresh OAuth session. Any saved metadata (identity, etc.) is re-verified.
322
+
323
+ **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.
324
+
325
+ ### "No profile specified. Options: ..."
326
+
327
+ The user ran `wrangler-accounts <wrangler-args>` without a resolvable profile. Fix one of:
328
+
329
+ ```bash
330
+ wrangler-accounts --profile <name> <args> # one-shot
331
+ WRANGLER_PROFILE=<name> wrangler-accounts <args> # env var
332
+ wrangler-accounts default <name> # persistent default
333
+ ```
334
+
335
+ ### "Profile not found: X"
336
+
337
+ The profile name doesn't exist in `profilesDir`. Check what's saved:
338
+
339
+ ```bash
340
+ wrangler-accounts list
341
+ ```
342
+
343
+ Create it with `wrangler-accounts login <name>` or copy an existing Wrangler login with `wrangler-accounts save <name>`.
344
+
345
+ ### Inside `wrangler-accounts exec`, `cd ~` lands in a weird tmpdir
346
+
347
+ Expected. Inside an `exec` session, `$HOME` is the shadow HOME. The real home is still accessible:
348
+
349
+ ```bash
350
+ cd "$WRANGLER_ACCOUNT_REAL_HOME"
351
+ ```
352
+
353
+ Or users can add a shell alias: `alias realhome='cd "$WRANGLER_ACCOUNT_REAL_HOME"'`.
354
+
355
+ ### Deprecated `use` command warning
356
+
357
+ `wrangler-accounts use <name>` still works but prints a deprecation warning. Suggest the replacement based on intent:
358
+
359
+ - "I want this account to stick for a while" → `wrangler-accounts default <name>`
360
+ - "Just this one command" → `wrangler-accounts --profile <name> <wrangler-args>`
361
+
362
+ ### `[ERROR] A request to the Cloudflare API ... Authentication error [code: 10000]` with `code: 7403` ("not authorized to access this service")
363
+
364
+ 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:
365
+
366
+ - `deploy` and `secret put` succeed (they don't put account ID in the URL path)
367
+ - `d1 execute --remote`, `r2 object get/put`, anything else with `/accounts/<id>/...` in the URL fails with 7403
368
+
369
+ **Fix path** (in order):
370
+
371
+ 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.
372
+ 2. **Clear the polluted shared cache** (one-time, even after upgrading):
373
+ ```bash
374
+ rm -f ~/.wrangler/cache/wrangler-account.json
375
+ rm -f ~/Library/Preferences/.wrangler/cache/wrangler-account.json # macOS env-paths fallback
376
+ ```
377
+ 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>`.
378
+ 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:
379
+ ```bash
380
+ CLOUDFLARE_ACCOUNT_ID=<id> wrangler-accounts <profile> r2 object put ...
381
+ ```
382
+
383
+ **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."
384
+
385
+ ### "The OAuth config seems right, but the wrong account is being used"
386
+
387
+ Same root cause as the 7403 above. Default to the same fix path.
388
+
389
+ ### `wrangler dev` (or any `--local` command) shows stale data after switching profiles
390
+
391
+ 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.
392
+
393
+ 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.
394
+
395
+ Two clean fixes:
396
+
397
+ 1. **Use git worktrees** (recommended for any serious multi-profile dev workflow):
398
+ ```bash
399
+ git worktree add ../my-project-work main
400
+ git worktree add ../my-project-personal main
401
+ cd ../my-project-work && wrangler-accounts exec work # isolated .wrangler/state/
402
+ cd ../my-project-personal && wrangler-accounts exec personal
403
+ ```
404
+ 2. **Clear state manually before switching**:
405
+ ```bash
406
+ rm -rf .wrangler/state
407
+ wrangler-accounts --profile <new> dev
408
+ ```
409
+
410
+ `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.
411
+
412
+ ### Shell history / `.zsh_history` seems to grow when running `exec`
413
+
414
+ 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.
415
+
416
+ ## Invariants the AI should rely on
417
+
418
+ - **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`).
419
+ - **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.
420
+ - **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.
421
+ - **`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.
422
+
423
+ ## What is and isn't isolated
424
+
425
+ | State | Location | Isolated? |
426
+ |---|---|---|
427
+ | OAuth credentials (`config.toml`) | shadow `$HOME/.wrangler/config/default.toml` → symlink to per-profile file | ✅ per profile |
428
+ | Account-id cache (`wrangler-account.json`) | per-profile `WRANGLER_CACHE_DIR` (= `<profilesDir>/<name>/cache/`) | ✅ per profile |
429
+ | Pages config cache (`pages-config-cache.json`) | same as above | ✅ per profile |
430
+ | Miniflare dev registry | `WRANGLER_REGISTRY_PATH` = `$realHome/.wrangler/registry` | ❌ shared on purpose (cross-profile worker discovery during local dev) |
431
+ | Wrangler debug logs | `WRANGLER_LOG_PATH` = `$realHome/.wrangler/logs` | ❌ shared (append-only, harmless) |
432
+ | Project-local state (`./.wrangler/state/`, `./node_modules/.cache/wrangler`) | inside the project directory | ❌ shared at project level (per-project, but not per-profile) |
433
+ | `cloudflared` binary | `CLOUDFLARED_PATH` or `~/.wrangler/cloudflared/` | ❌ shared (binary, not account-scoped) |
434
+ | Shell history, npm cache, git config, ssh keys | symlinked through to real `$HOME` | ❌ shared by design (so `exec` subshells feel like a normal terminal) |
435
+
436
+ 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.
437
+
438
+ ## CI guidance
439
+
440
+ For CI and deploy pipelines, **use `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` with plain `wrangler`**, not saved OAuth profiles. `wrangler-accounts` is a local developer convenience for juggling OAuth sessions on your workstation, not a CI primitive.
441
+
442
+ ## Paths and environment
443
+
444
+ - `--profile <name>` / `-p <name>` — profile for this invocation (v1.0: `-p` means `--profile`)
445
+ - `--profiles <path>` — profiles directory (long form only since v1.0)
446
+ - `-c, --config <path>` — Wrangler config path
447
+ - `WRANGLER_PROFILE` — profile to use when no `--profile` flag is given
448
+ - `WRANGLER_CONFIG_PATH`, `WRANGLER_ACCOUNTS_DIR`, `XDG_CONFIG_HOME` — path overrides
449
+
450
+ ## Output conventions
451
+
452
+ Use `--json` when another tool needs to parse results. All v1.0 commands that produce structured data support `--json`.
453
+
454
+ ## Naming rules
455
+
456
+ Profile names: letters, numbers, dot, underscore, dash only. Names matching management subcommand names (`exec`, `default`, `whoami`, `gc`, `login`, `list`, `status`, `save`, `sync`, `sync-default`, `remove`, `use`, `sync-active`) cannot be reached via positional shorthand — use `--profile <name>` for those.
457
+
458
+ ## Deprecated
459
+
460
+ - `wrangler-accounts use <name>` — deprecated, prints warning. Use `default <name>` for persistence or `--profile <name>` for one-shot.
461
+ - `wrangler-accounts sync-active` — deprecated alias for `sync-default`.
@@ -9,12 +9,40 @@ description: AWS-style multi-account convenience for Cloudflare Wrangler. Use wh
9
9
 
10
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
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
+
12
40
  ## Prerequisites (check before running any recipe below)
13
41
 
14
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:
15
43
 
16
44
  ```bash
17
- command -v wrangler-accounts
45
+ command -v wrangler-accounts && wrangler-accounts --version
18
46
  ```
19
47
 
20
48
  If the command is missing, tell the user to install the CLI first:
@@ -29,6 +57,54 @@ npm i -g @leeguoo/wrangler-accounts
29
57
  npm i -g wrangler
30
58
  ```
31
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
+
70
+ ```bash
71
+ npm i -g @leeguoo/wrangler-accounts@latest # always-safe upgrade
72
+ ```
73
+
74
+ ## Triage flow — when something looks wrong
75
+
76
+ **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.
77
+
78
+ ```bash
79
+ # 1. Verify your binary is recent enough (see version table above)
80
+ wrangler-accounts --version
81
+
82
+ # 2. Authoritative state of every profile (hits Cloudflare API per profile)
83
+ wrangler-accounts list --deep
84
+ ```
85
+
86
+ How to read `list --deep` output:
87
+
88
+ | You see | Meaning | What to do |
89
+ |---|---|---|
90
+ | `STATUS valid` + `VERIFIED ✓ ok` | profile is fine | nothing — proceed with whatever the user actually asked |
91
+ | `STATUS valid*` + `VERIFIED ✓ ok` | profile is fine; access token will auto-refresh on next use | nothing — **`valid*` is healthy, do NOT re-login** |
92
+ | `STATUS EXPIRED` + `VERIFIED ✓ ok` | rare; only on `< 1.3.0` binaries — STATUS is lying | upgrade the CLI; profile is fine |
93
+ | `STATUS EXPIRED` + `VERIFIED ✗ Not logged in` | profile is genuinely broken | `wrangler-accounts login <name>` (interactive only) |
94
+ | `STATUS valid` + `VERIFIED ✗` of any kind | refresh token revoked server-side | `wrangler-accounts login <name>` (interactive only) |
95
+ | `STATUS unknown` | profile file lacks `expiration_time` | run `--deep` (already did) — trust VERIFIED |
96
+
97
+ **Rule**: only suggest `wrangler-accounts login <name>` when at least one of:
98
+ 1. `list --deep` showed `VERIFIED ✗` for that profile, OR
99
+ 2. The profile doesn't exist at all yet, OR
100
+ 3. The user explicitly says "re-authenticate" / "log me in again"
101
+
102
+ **If `list --deep` shows everything ✓ but a wrangler command still fails**, the root cause is somewhere other than wrangler-accounts — most likely:
103
+ - Project-local `./.wrangler/state/` is sharing data across profiles (see "What is and isn't isolated")
104
+ - The project's `wrangler.toml` has the wrong `account_id` hardcoded
105
+ - The user is on a CLI version below 1.2.2 (account-id cache leak)
106
+ - The wrangler subcommand actually needs `--remote` or `--local` and you forgot
107
+
32
108
  ## Quick Start
33
109
 
34
110
  - `wrangler-accounts login <name>` — interactive OAuth login into a new profile (never touches real `~/.wrangler`)
@@ -37,6 +113,8 @@ npm i -g wrangler
37
113
  - `wrangler-accounts --profile personal deploy` — one-shot override
38
114
  - `wrangler-accounts exec work -- npm run release` — run a command in an isolated subshell for the `work` profile
39
115
 
116
+ > 💡 **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".
117
+
40
118
  ## Tasks
41
119
 
42
120
  ### Run wrangler against a profile
@@ -232,9 +310,9 @@ wrangler deploy
232
310
 
233
311
  ## Troubleshooting
234
312
 
235
- ### "Profile 'X' has expired Wrangler OAuth credentials"
313
+ ### "Profile 'X' has expired Wrangler OAuth credentials and no refresh_token to renew them"
236
314
 
237
- The saved OAuth access token is past its `expiration_time` and the refresh didn't happen (or Wrangler is older than 4.x). Refresh it interactively:
315
+ 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:
238
316
 
239
317
  ```bash
240
318
  wrangler-accounts login <name>
@@ -242,6 +320,8 @@ wrangler-accounts login <name>
242
320
 
243
321
  This overwrites the existing profile with a fresh OAuth session. Any saved metadata (identity, etc.) is re-verified.
244
322
 
323
+ **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.
324
+
245
325
  ### "No profile specified. Options: ..."
246
326
 
247
327
  The user ran `wrangler-accounts <wrangler-args>` without a resolvable profile. Fix one of: