oc-auth-switcher 0.1.0 → 0.1.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.
- package/README.md +50 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
# oc-auth-switcher
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenCode auth plugin for multi-account Anthropic Claude Max rotation with automatic failover. Captures rate-limit headers in real-time and switches accounts before you hit usage limits.
|
|
4
4
|
|
|
5
5
|
## How It Works
|
|
6
6
|
|
|
7
|
-
This plugin
|
|
7
|
+
This plugin registers as the Anthropic auth provider for OpenCode. It uses [`@ex-machina/opencode-anthropic-auth`](https://github.com/ex-machina-co/opencode-anthropic-auth) as a library for request/response transformation (billing header, system prompt sanitization, tool name prefixing) and adds:
|
|
8
8
|
|
|
9
|
-
1.
|
|
10
|
-
2.
|
|
11
|
-
3.
|
|
12
|
-
4. `@ex-machina/opencode-anthropic-auth` reads the rotated credentials on the next API request
|
|
13
|
-
|
|
14
|
-
The plugin also hooks into OpenCode's `session.idle` and `chat.message` events to check cached metrics and rotate proactively before thresholds are hit.
|
|
9
|
+
1. **Multi-account rotation** — maintains a pool of OAuth accounts and selects the best one on each request
|
|
10
|
+
2. **Real-time metric capture** — reads Anthropic's rate-limit response headers on every API call (no manual pinging needed)
|
|
11
|
+
3. **Automatic failover** — when any utilization metric exceeds the threshold (default 90%), the next request automatically uses a different account
|
|
15
12
|
|
|
16
13
|
## Setup
|
|
17
14
|
|
|
18
|
-
### 1.
|
|
15
|
+
### 1. Add the plugin to your `opencode.json`
|
|
19
16
|
|
|
20
17
|
```json
|
|
21
18
|
{
|
|
22
|
-
"plugin": [
|
|
23
|
-
"@ex-machina/opencode-anthropic-auth@1.8.0",
|
|
24
|
-
"oc-auth-switcher@latest"
|
|
25
|
-
]
|
|
19
|
+
"plugin": ["oc-auth-switcher@latest"]
|
|
26
20
|
}
|
|
27
21
|
```
|
|
28
22
|
|
|
29
|
-
**
|
|
23
|
+
This is the **only** auth plugin you need for Anthropic. Do not also list `@ex-machina/opencode-anthropic-auth` — it is included as a dependency.
|
|
30
24
|
|
|
31
25
|
### 2. Add accounts
|
|
32
26
|
|
|
33
27
|
```bash
|
|
34
|
-
# Add your primary account
|
|
28
|
+
# Add your primary account (first account = always preferred)
|
|
35
29
|
oc-auth-switcher add primary
|
|
36
30
|
|
|
37
31
|
# Add fallback accounts
|
|
@@ -41,34 +35,31 @@ oc-auth-switcher add fallback-2
|
|
|
41
35
|
|
|
42
36
|
Each `add` command runs an OAuth flow — you'll be given a URL to open in your browser and prompted to paste the callback.
|
|
43
37
|
|
|
44
|
-
### 3.
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
oc-auth-switcher ping
|
|
48
|
-
```
|
|
38
|
+
### 3. Use OpenCode normally
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
The plugin handles rotation automatically. The first account in the pool is always the "primary" (preferred). When it exceeds the utilization threshold, traffic switches to the next available fallback. When the primary recovers, it switches back.
|
|
40
|
+
Metrics update automatically on every API request. When the primary account exceeds the utilization threshold, the plugin switches to the next available fallback. When the primary recovers, it switches back.
|
|
53
41
|
|
|
54
42
|
## CLI Commands
|
|
55
43
|
|
|
44
|
+
```
|
|
45
|
+
oc-auth-switcher <command> [options]
|
|
46
|
+
```
|
|
47
|
+
|
|
56
48
|
| Command | Description |
|
|
57
49
|
|---------|-------------|
|
|
58
50
|
| `add [name]` | Add a new account via OAuth |
|
|
59
|
-
| `
|
|
51
|
+
| `reauth <name>` | Re-authenticate an existing account |
|
|
60
52
|
| `usage [--watch]` | Show utilization dashboard with progress bars |
|
|
61
53
|
| `config [options]` | View/modify thresholds and check interval |
|
|
62
|
-
| `ping [name]` | Ping account(s) to refresh utilization metrics |
|
|
63
|
-
| `reauth <name>` | Re-authenticate an existing account |
|
|
64
54
|
| `switch <name>` | Manually switch to a specific account |
|
|
65
55
|
| `status` | Show current active account and rotation state |
|
|
56
|
+
| `remove <name>` | Remove an account from the pool |
|
|
66
57
|
|
|
67
58
|
## Configuration
|
|
68
59
|
|
|
69
60
|
```bash
|
|
70
|
-
# Set uniform threshold (default:
|
|
71
|
-
oc-auth-switcher config --threshold 0.
|
|
61
|
+
# Set uniform threshold (default: 90%)
|
|
62
|
+
oc-auth-switcher config --threshold 0.90
|
|
72
63
|
|
|
73
64
|
# Set per-metric thresholds (5h, 7d, 7d-sonnet)
|
|
74
65
|
oc-auth-switcher config --thresholds 90,80,70
|
|
@@ -96,6 +87,7 @@ Both files use atomic writes with `.bak` fallback for crash safety.
|
|
|
96
87
|
- If all fallbacks are also over threshold, pick the one with the lowest utilization score
|
|
97
88
|
- When on a fallback, periodically check if the primary has recovered (configurable interval)
|
|
98
89
|
- Auth failures trigger a 1-hour cooldown per account
|
|
90
|
+
- Token refresh is handled automatically with retry and fallback to other accounts
|
|
99
91
|
|
|
100
92
|
## Building from Source
|
|
101
93
|
|
|
@@ -104,6 +96,36 @@ bun install
|
|
|
104
96
|
bun run build
|
|
105
97
|
```
|
|
106
98
|
|
|
99
|
+
## Publishing to npm
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm login
|
|
103
|
+
npm publish
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The `prepublishOnly` script automatically runs `bun run build` before publishing.
|
|
107
|
+
|
|
108
|
+
### Versioning
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Patch (bug fixes)
|
|
112
|
+
npm version patch && npm publish && git push --follow-tags
|
|
113
|
+
|
|
114
|
+
# Minor (new features)
|
|
115
|
+
npm version minor && npm publish && git push --follow-tags
|
|
116
|
+
|
|
117
|
+
# Major (breaking changes)
|
|
118
|
+
npm version major && npm publish && git push --follow-tags
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Updating the ex-machina dependency
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
bun update @ex-machina/opencode-anthropic-auth
|
|
125
|
+
bun run build
|
|
126
|
+
# Test, then publish
|
|
127
|
+
```
|
|
128
|
+
|
|
107
129
|
## License
|
|
108
130
|
|
|
109
131
|
MIT
|