opencode-anthropic-fix 0.0.14
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/.github/workflows/publish.yml +31 -0
- package/.husky/pre-commit +2 -0
- package/.husky/pre-push +3 -0
- package/.planning/CLI-ENHANCEMENTS.md +221 -0
- package/.planning/codebase/ARCHITECTURE.md +201 -0
- package/.planning/codebase/CONCERNS.md +219 -0
- package/.planning/codebase/CONVENTIONS.md +335 -0
- package/.planning/codebase/INTEGRATIONS.md +215 -0
- package/.planning/codebase/STACK.md +160 -0
- package/.planning/codebase/STRUCTURE.md +244 -0
- package/.planning/codebase/TESTING.md +456 -0
- package/.prettierignore +3 -0
- package/.prettierrc +10 -0
- package/CONTRIBUTING.md +525 -0
- package/LICENSE +21 -0
- package/README.md +478 -0
- package/agents.md +22 -0
- package/bun.lock +43 -0
- package/cli.mjs +1773 -0
- package/cli.test.mjs +1797 -0
- package/docs/mimese-http-header-system-prompt.md +326 -0
- package/docs/plans/afcw-upstream-watcher.json +495 -0
- package/eslint.config.mjs +69 -0
- package/index.mjs +2209 -0
- package/index.test.mjs +2690 -0
- package/lib/accounts.mjs +670 -0
- package/lib/accounts.test.mjs +782 -0
- package/lib/backoff.mjs +217 -0
- package/lib/backoff.test.mjs +296 -0
- package/lib/config.mjs +366 -0
- package/lib/config.test.mjs +307 -0
- package/lib/oauth.mjs +103 -0
- package/lib/rotation.mjs +287 -0
- package/lib/rotation.test.mjs +346 -0
- package/lib/storage.mjs +265 -0
- package/lib/storage.test.mjs +470 -0
- package/nul +1 -0
- package/package.json +40 -0
- package/script/publish.ts +29 -0
- package/scripts/build.mjs +34 -0
- package/scripts/install.mjs +319 -0
package/README.md
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
# opencode-anthropic-fix
|
|
2
|
+
|
|
3
|
+
Use your Claude Pro or Max subscription with [OpenCode](https://github.com/anomalyco/opencode). Supports multiple accounts with automatic rotation when you hit rate limits.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
**Prerequisites:** [OpenCode](https://github.com/anomalyco/opencode) installed, a Claude Pro or Max subscription, Node.js 18+.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# 1. Clone and install
|
|
11
|
+
git clone https://github.com/marco-jardim/opencode-anthropic-fix.git
|
|
12
|
+
cd opencode-anthropic-fix
|
|
13
|
+
npm install
|
|
14
|
+
|
|
15
|
+
# 2. Install the plugin + CLI
|
|
16
|
+
npm run install:link
|
|
17
|
+
|
|
18
|
+
# 3. Start OpenCode and connect
|
|
19
|
+
opencode
|
|
20
|
+
# Press Ctrl+K → Connect Provider → Anthropic → "Claude Pro/Max (multi-account)"
|
|
21
|
+
# Follow the OAuth prompts to log in
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
That's it. OpenCode will now use your Claude subscription directly. All model costs show as $0.00.
|
|
25
|
+
|
|
26
|
+
## Why This Fork?
|
|
27
|
+
|
|
28
|
+
The [upstream plugin](https://github.com/anomalyco/opencode-anthropic-auth) ships as a built-in default with OpenCode. This fork adds:
|
|
29
|
+
|
|
30
|
+
- **Multi-account support** — add up to 10 Claude accounts and rotate between them
|
|
31
|
+
- **Automatic rate limit handling** — when one account hits a limit, the plugin switches to another
|
|
32
|
+
- **Health scoring** — tracks account reliability and prefers healthy accounts
|
|
33
|
+
- **Standalone CLI** — manage accounts without opening OpenCode
|
|
34
|
+
- **Configurable strategies** — sticky, round-robin, or hybrid account selection
|
|
35
|
+
- **Claude Code signature emulation** — optional Claude-style request headers with startup version lookup
|
|
36
|
+
- **Adaptive thinking for Opus 4.6** — automatically uses `adaptive-thinking-2026-01-28` and maps `budgetTokens` to effort levels (`low`/`medium`/`high`/`max`)
|
|
37
|
+
- **1M context limit override** — patches `model.limit.context` so OpenCode compacts at the right threshold while `models.dev` catches up
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
### Development (symlink)
|
|
42
|
+
|
|
43
|
+
Best for active development. Edits to source files take effect immediately.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run install:link
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This creates:
|
|
50
|
+
|
|
51
|
+
- **Plugin:** `~/.config/opencode/plugin/opencode-anthropic-auth-plugin.js` → `./index.mjs`
|
|
52
|
+
- **CLI:** `~/.local/bin/opencode-anthropic-auth` → `./cli.mjs`
|
|
53
|
+
|
|
54
|
+
### Stable (copy)
|
|
55
|
+
|
|
56
|
+
Bundles the plugin and CLI into self-contained single files (via esbuild) and copies them. No symlinks, no `node_modules` needed at the destination.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run install:copy
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This creates:
|
|
63
|
+
|
|
64
|
+
- **Plugin:** `~/.config/opencode/plugin/opencode-anthropic-auth-plugin.js` (standalone, ~50KB)
|
|
65
|
+
- **CLI:** `~/.local/bin/opencode-anthropic-auth` (standalone, ~35KB)
|
|
66
|
+
|
|
67
|
+
### Uninstall
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm run uninstall
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### PATH Setup
|
|
74
|
+
|
|
75
|
+
If `~/.local/bin` isn't on your PATH, add it:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Adding Accounts
|
|
82
|
+
|
|
83
|
+
### First Account
|
|
84
|
+
|
|
85
|
+
1. Open OpenCode
|
|
86
|
+
2. Press `Ctrl+K` → **Connect Provider** → **Anthropic**
|
|
87
|
+
3. Select **"Claude Pro/Max (multi-account)"**
|
|
88
|
+
4. Open the URL in your browser, authorize, and paste the code back
|
|
89
|
+
|
|
90
|
+
You can also add accounts directly from the CLI without opening OpenCode:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
opencode-anthropic-auth login
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Additional Accounts
|
|
97
|
+
|
|
98
|
+
Run the auth flow again (via CLI `login` or OpenCode's Connect Provider). The plugin detects existing accounts and shows a menu:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
2 account(s) configured:
|
|
102
|
+
1. alice@example.com (active)
|
|
103
|
+
2. bob@example.com
|
|
104
|
+
|
|
105
|
+
(a)dd new, (f)resh start, (m)anage, (c)ancel? [a/f/m/c]:
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- **Add** — log in with another Claude account
|
|
109
|
+
- **Fresh start** — clear all accounts and start over
|
|
110
|
+
- **Manage** — enable/disable/remove accounts inline
|
|
111
|
+
- **Cancel** — keep current setup
|
|
112
|
+
|
|
113
|
+
This fork is OAuth-first. Use `claude.ai` login flows (`login` / `reauth`) for all accounts.
|
|
114
|
+
|
|
115
|
+
## CLI
|
|
116
|
+
|
|
117
|
+
The CLI lets you manage accounts outside of OpenCode.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
opencode-anthropic-auth [command] [args]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Command | Description |
|
|
124
|
+
| ---------------------- | ------------------------------------------------------------- |
|
|
125
|
+
| `login` | Add a new account via browser OAuth flow |
|
|
126
|
+
| `logout <N>` | Revoke tokens and remove account N |
|
|
127
|
+
| `logout --all` | Revoke all tokens and clear all accounts |
|
|
128
|
+
| `reauth <N>` | Re-authenticate account N with fresh OAuth tokens |
|
|
129
|
+
| `refresh <N>` | Attempt token refresh (no browser needed) |
|
|
130
|
+
| `list` | Show all accounts with status and live usage quotas (default) |
|
|
131
|
+
| `status` | Compact one-liner for scripts/prompts |
|
|
132
|
+
| `switch <N>` | Set account N as active |
|
|
133
|
+
| `enable <N>` | Enable a disabled account |
|
|
134
|
+
| `disable <N>` | Disable an account (skipped in rotation) |
|
|
135
|
+
| `remove <N>` | Remove an account permanently |
|
|
136
|
+
| `reset <N\|all>` | Clear rate-limit / failure tracking |
|
|
137
|
+
| `stats` | Show per-account token usage statistics |
|
|
138
|
+
| `reset-stats [N\|all]` | Reset usage statistics |
|
|
139
|
+
| `strategy [name]` | Show or change selection strategy |
|
|
140
|
+
| `config` | Show configuration and file paths |
|
|
141
|
+
| `manage` | Interactive account management menu |
|
|
142
|
+
| `help` | Show help |
|
|
143
|
+
|
|
144
|
+
### Examples
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Add a new account via browser OAuth
|
|
148
|
+
opencode-anthropic-auth login
|
|
149
|
+
|
|
150
|
+
# See account status (includes live usage quotas)
|
|
151
|
+
opencode-anthropic-auth list
|
|
152
|
+
|
|
153
|
+
# Output:
|
|
154
|
+
# Anthropic Multi-Account Status
|
|
155
|
+
# # Account Status Failures Rate Limit
|
|
156
|
+
# ──────────────────────────────────────────────────────────────
|
|
157
|
+
# 1 alice@example.com ● active 0 —
|
|
158
|
+
# 5h █████░░░░░ 45% resets in 2h 30m
|
|
159
|
+
# 7d █████░░░░░ 45% resets in 4d 16h
|
|
160
|
+
# Sonnet 7d ░░░░░░░░░░ 0%
|
|
161
|
+
#
|
|
162
|
+
# 2 bob@example.com ● ready 0 —
|
|
163
|
+
# 5h ███░░░░░░░ 31% resets in 30m
|
|
164
|
+
# 7d ███████░░░ 70% resets in 19h 31m
|
|
165
|
+
# Sonnet 7d █░░░░░░░░░ 11% resets in 2d 10h
|
|
166
|
+
#
|
|
167
|
+
# Strategy: sticky | 2 of 2 enabled
|
|
168
|
+
# Storage: ~/.config/opencode/anthropic-accounts.json
|
|
169
|
+
|
|
170
|
+
# Switch active account
|
|
171
|
+
opencode-anthropic-auth switch 2
|
|
172
|
+
|
|
173
|
+
# Re-authenticate a broken account (opens browser)
|
|
174
|
+
opencode-anthropic-auth reauth 1
|
|
175
|
+
|
|
176
|
+
# Quick token refresh without browser
|
|
177
|
+
opencode-anthropic-auth refresh 1
|
|
178
|
+
|
|
179
|
+
# Revoke tokens and remove an account
|
|
180
|
+
opencode-anthropic-auth logout 2
|
|
181
|
+
|
|
182
|
+
# Revoke all tokens and clear all accounts
|
|
183
|
+
opencode-anthropic-auth logout --all
|
|
184
|
+
|
|
185
|
+
# View token usage per account
|
|
186
|
+
opencode-anthropic-auth stats
|
|
187
|
+
|
|
188
|
+
# Reset all usage counters
|
|
189
|
+
opencode-anthropic-auth reset-stats all
|
|
190
|
+
|
|
191
|
+
# One-liner for shell prompts
|
|
192
|
+
opencode-anthropic-auth status
|
|
193
|
+
# anthropic: 2 accounts (2 active), strategy: sticky, next: #1
|
|
194
|
+
|
|
195
|
+
# Interactive management
|
|
196
|
+
opencode-anthropic-auth manage
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Flags
|
|
200
|
+
|
|
201
|
+
| Flag | Description |
|
|
202
|
+
| ------------ | -------------------------------------------------- |
|
|
203
|
+
| `--force` | Skip confirmation prompts (for `remove`, `logout`) |
|
|
204
|
+
| `--all` | Target all accounts (for `logout`) |
|
|
205
|
+
| `--no-color` | Disable colored output |
|
|
206
|
+
| `--help` | Show help message |
|
|
207
|
+
|
|
208
|
+
Most commands have short aliases: `ln`, `lo`, `ra`, `rf`, `ls`, `st`, `sw`, `en`, `dis`, `rm`, `strat`, `cfg`, `mg`.
|
|
209
|
+
|
|
210
|
+
## Slash Commands in OpenCode
|
|
211
|
+
|
|
212
|
+
The plugin also registers a built-in `/anthropic` slash command so you can manage accounts without leaving OpenCode.
|
|
213
|
+
|
|
214
|
+
### Common examples
|
|
215
|
+
|
|
216
|
+
```text
|
|
217
|
+
/anthropic # list (default)
|
|
218
|
+
/anthropic usage # full account list + quota windows
|
|
219
|
+
/anthropic switch 2
|
|
220
|
+
/anthropic refresh 1
|
|
221
|
+
/anthropic logout 2 # revoke tokens and remove account 2
|
|
222
|
+
/anthropic logout --all # revoke all tokens and clear all accounts
|
|
223
|
+
/anthropic strategy hybrid
|
|
224
|
+
/anthropic stats
|
|
225
|
+
/anthropic config
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### OAuth flows from slash command
|
|
229
|
+
|
|
230
|
+
Login and reauth are two-step flows in slash mode:
|
|
231
|
+
|
|
232
|
+
```text
|
|
233
|
+
/anthropic login
|
|
234
|
+
# opens URL instructions in chat
|
|
235
|
+
/anthropic login complete <code#state>
|
|
236
|
+
|
|
237
|
+
/anthropic reauth 1
|
|
238
|
+
# opens URL instructions in chat
|
|
239
|
+
/anthropic reauth complete <code#state>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Pending slash OAuth flows expire after 10 minutes. If completion fails with an expiration message, run the start command again.
|
|
243
|
+
|
|
244
|
+
### Notes
|
|
245
|
+
|
|
246
|
+
- Destructive commands (`remove`, `logout`) run with non-interactive `--force` behavior in slash mode.
|
|
247
|
+
- Interactive `manage` is terminal-only; use granular slash commands instead.
|
|
248
|
+
|
|
249
|
+
## Account Selection Strategies
|
|
250
|
+
|
|
251
|
+
Control how the plugin picks which account to use for each request.
|
|
252
|
+
|
|
253
|
+
| Strategy | Behavior | Best For |
|
|
254
|
+
| ---------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------- |
|
|
255
|
+
| **`sticky`** (default) | Stay on one account until it fails or is rate-limited | Single account, or when you want predictable behavior |
|
|
256
|
+
| **`round-robin`** | Rotate through accounts on every request | Spreading load evenly across accounts |
|
|
257
|
+
| **`hybrid`** | Score-based selection with stickiness bias. Considers health, token budget, and freshness | Multiple accounts with varying rate limits |
|
|
258
|
+
|
|
259
|
+
### Change Strategy
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Via CLI
|
|
263
|
+
opencode-anthropic-auth strategy round-robin
|
|
264
|
+
|
|
265
|
+
# Via environment variable (overrides config file)
|
|
266
|
+
export OPENCODE_ANTHROPIC_STRATEGY=hybrid
|
|
267
|
+
|
|
268
|
+
# Via config file
|
|
269
|
+
# Edit ~/.config/opencode/anthropic-auth.json
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Configuration
|
|
273
|
+
|
|
274
|
+
Configuration is stored at `~/.config/opencode/anthropic-auth.json`. All settings are optional — defaults work well for most users.
|
|
275
|
+
|
|
276
|
+
```jsonc
|
|
277
|
+
{
|
|
278
|
+
// Account selection strategy: "sticky" | "round-robin" | "hybrid"
|
|
279
|
+
"account_selection_strategy": "sticky",
|
|
280
|
+
|
|
281
|
+
// Seconds before consecutive failure count resets (60-7200)
|
|
282
|
+
"failure_ttl_seconds": 3600,
|
|
283
|
+
|
|
284
|
+
// Enable debug logging
|
|
285
|
+
"debug": false,
|
|
286
|
+
|
|
287
|
+
// Claude Code signature emulation behavior
|
|
288
|
+
"signature_emulation": {
|
|
289
|
+
// Enable Claude-style attribution/stainless headers and betas
|
|
290
|
+
"enabled": true,
|
|
291
|
+
// Resolve latest @anthropic-ai/claude-code version once on plugin startup
|
|
292
|
+
"fetch_claude_code_version_on_startup": true,
|
|
293
|
+
// Compact long injected system instructions to reduce token usage.
|
|
294
|
+
// In "minimal" mode, repeated/contained blocks are deduplicated and title-generator
|
|
295
|
+
// requests are replaced with a compact dedicated prompt.
|
|
296
|
+
// "minimal" | "off"
|
|
297
|
+
"prompt_compaction": "minimal",
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
// Context limit override for 1M-window models.
|
|
301
|
+
// Prevents OpenCode from compacting too early when models.dev hasn't been
|
|
302
|
+
// updated yet (e.g. claude-opus-4-6 and any *-1m model variants).
|
|
303
|
+
// Only applied for OAuth (Max Plan) sessions — API key users use the
|
|
304
|
+
// context-1m-2025-08-07 beta header instead.
|
|
305
|
+
"override_model_limits": {
|
|
306
|
+
// Enable/disable the override
|
|
307
|
+
"enabled": true,
|
|
308
|
+
// Context window to inject (tokens). Default: 1_000_000.
|
|
309
|
+
"context": 1000000,
|
|
310
|
+
// Max output tokens to inject. 0 = leave the model's default unchanged.
|
|
311
|
+
"output": 0,
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
// Health score tuning (0-100 scale)
|
|
315
|
+
"health_score": {
|
|
316
|
+
"initial": 70,
|
|
317
|
+
"success_reward": 1,
|
|
318
|
+
"rate_limit_penalty": -10,
|
|
319
|
+
"failure_penalty": -20,
|
|
320
|
+
"recovery_rate_per_hour": 2,
|
|
321
|
+
"min_usable": 50,
|
|
322
|
+
"max_score": 100,
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
// Client-side rate limiting (token bucket)
|
|
326
|
+
"token_bucket": {
|
|
327
|
+
"max_tokens": 50,
|
|
328
|
+
"regeneration_rate_per_minute": 6,
|
|
329
|
+
"initial_tokens": 50,
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// Toast notification settings
|
|
333
|
+
"toasts": {
|
|
334
|
+
// Suppress non-error toasts (account status, switching)
|
|
335
|
+
"quiet": false,
|
|
336
|
+
// Minimum seconds between account-switch toasts (0-300)
|
|
337
|
+
"debounce_seconds": 30,
|
|
338
|
+
},
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Environment Variables
|
|
343
|
+
|
|
344
|
+
| Variable | Description |
|
|
345
|
+
| -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
346
|
+
| `OPENCODE_ANTHROPIC_STRATEGY` | Override the account selection strategy at runtime. |
|
|
347
|
+
| `OPENCODE_ANTHROPIC_DEBUG` | Set to `1` to enable debug logging. |
|
|
348
|
+
| `OPENCODE_ANTHROPIC_QUIET` | Set to `1` to suppress non-error toasts (account status, switching). |
|
|
349
|
+
| `OPENCODE_ANTHROPIC_EMULATE_CLAUDE_CODE_SIGNATURE` | Set to `0` to disable Claude signature emulation (legacy mode). |
|
|
350
|
+
| `OPENCODE_ANTHROPIC_FETCH_CLAUDE_CODE_VERSION` | Set to `0` to skip npm version lookup at startup. |
|
|
351
|
+
| `OPENCODE_ANTHROPIC_PROMPT_COMPACTION` | Set to `off` to disable default minimal system prompt compaction. |
|
|
352
|
+
| `OPENCODE_ANTHROPIC_DEBUG_SYSTEM_PROMPT` | Set to `1` to log the final transformed `system` prompt to stderr (title-generator requests are skipped). |
|
|
353
|
+
| `OPENCODE_ANTHROPIC_OVERRIDE_MODEL_LIMITS` | Set to `0` to disable context limit overrides for 1M-window models (e.g. when models.dev has been updated). |
|
|
354
|
+
|
|
355
|
+
### OAuth-only behavior
|
|
356
|
+
|
|
357
|
+
- The expected auth mode is OAuth (`claude login` / browser flow), not direct `ANTHROPIC_API_KEY` usage.
|
|
358
|
+
- In OAuth mode, the plugin always includes `oauth-2025-04-20` in `anthropic-beta`.
|
|
359
|
+
- This applies to all models, including Haiku.
|
|
360
|
+
|
|
361
|
+
## How It Works
|
|
362
|
+
|
|
363
|
+
When you make a request through OpenCode:
|
|
364
|
+
|
|
365
|
+
1. The plugin selects an account based on your strategy
|
|
366
|
+
2. It refreshes the OAuth token if expired
|
|
367
|
+
3. It transforms the request (adds OAuth headers, `oauth-2025-04-20`, signature headers, beta flags, tool prefixes)
|
|
368
|
+
4. If the response is account-specific (429/401, plus 400/403 billing/quota/permission errors), it marks that account and immediately tries the next account
|
|
369
|
+
5. If the response is service-wide (500/503/529), it returns the error directly (switching accounts would not help)
|
|
370
|
+
6. It tries each available account at most once per request
|
|
371
|
+
7. Successful responses have tool name prefixes stripped from the stream
|
|
372
|
+
|
|
373
|
+
The plugin also:
|
|
374
|
+
|
|
375
|
+
- Zeros out model costs (your subscription covers usage)
|
|
376
|
+
- Emulates Claude-style request headers and beta flags by default
|
|
377
|
+
- Sanitizes "OpenCode" references to "Claude Code" in system prompts (required by Anthropic's API)
|
|
378
|
+
- In `prompt_compaction="minimal"`, deduplicates repeated/contained system blocks and uses a compact dedicated prompt for internal title-generation requests
|
|
379
|
+
- Adds `?beta=true` to `/v1/messages` requests
|
|
380
|
+
|
|
381
|
+
When signature emulation is disabled (`signature_emulation.enabled=false`), the plugin falls back to legacy behavior including the Claude Code system prompt prefix.
|
|
382
|
+
|
|
383
|
+
## Files
|
|
384
|
+
|
|
385
|
+
| Path | Description |
|
|
386
|
+
| ------------------------------------------------------------- | -------------------------------------- |
|
|
387
|
+
| `~/.config/opencode/anthropic-auth.json` | Plugin configuration |
|
|
388
|
+
| `~/.config/opencode/anthropic-accounts.json` | Account credentials (0600 permissions) |
|
|
389
|
+
| `~/.config/opencode/plugin/opencode-anthropic-auth-plugin.js` | Installed plugin entry point |
|
|
390
|
+
| `~/.local/bin/opencode-anthropic-auth` | CLI binary |
|
|
391
|
+
|
|
392
|
+
Account credentials are stored with restrictive file permissions (owner read/write only) and are excluded from git via an auto-generated `.gitignore`.
|
|
393
|
+
|
|
394
|
+
## Troubleshooting
|
|
395
|
+
|
|
396
|
+
### "Provider not showing up"
|
|
397
|
+
|
|
398
|
+
Make sure the plugin is installed in `~/.config/opencode/plugin/`. Restart OpenCode after installing.
|
|
399
|
+
|
|
400
|
+
### "Auth flow completes but requests fail"
|
|
401
|
+
|
|
402
|
+
Your OAuth token may have expired. Try a quick refresh first, or re-authenticate with fresh browser login:
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
# Quick token refresh (no browser needed)
|
|
406
|
+
opencode-anthropic-auth refresh 1
|
|
407
|
+
|
|
408
|
+
# Full re-authentication (opens browser)
|
|
409
|
+
opencode-anthropic-auth reauth 1
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
Or re-run the auth flow from OpenCode: `Ctrl+K` → Connect Provider → Anthropic.
|
|
413
|
+
|
|
414
|
+
### "Need to inspect the final system prompt sent to Anthropic"
|
|
415
|
+
|
|
416
|
+
Enable system prompt debug logging:
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
export OPENCODE_ANTHROPIC_DEBUG_SYSTEM_PROMPT=1
|
|
420
|
+
opencode
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
When enabled, the plugin prints the transformed `system` block (after sanitization/compaction) to `stderr` with prefix:
|
|
424
|
+
|
|
425
|
+
```text
|
|
426
|
+
[opencode-anthropic-auth][system-debug] transformed system:
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Note: internal title-generator requests are intentionally skipped by this debug log to avoid noisy high-volume output.
|
|
430
|
+
|
|
431
|
+
### "Rate limited on all accounts"
|
|
432
|
+
|
|
433
|
+
When all accounts are exhausted for an account-specific error, the plugin returns immediately instead of sleeping in-process. Try:
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Check status
|
|
437
|
+
opencode-anthropic-auth list
|
|
438
|
+
|
|
439
|
+
# Reset tracking if stuck
|
|
440
|
+
opencode-anthropic-auth reset all
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### "Toast notifications when using other models"
|
|
444
|
+
|
|
445
|
+
You may see `Claude: <email>` toasts even when your selected model is not Anthropic (e.g., OpenAI Codex, Gemini). This is expected behavior — OpenCode uses Claude Haiku as a background "small model" for internal tasks like generating session titles, regardless of which model you selected. These background API calls go through the Anthropic provider, which triggers the plugin's fetch interceptor and its account-usage toast.
|
|
446
|
+
|
|
447
|
+
To suppress non-error toasts, set `quiet` mode in your config:
|
|
448
|
+
|
|
449
|
+
```jsonc
|
|
450
|
+
// ~/.config/opencode/anthropic-auth.json
|
|
451
|
+
{
|
|
452
|
+
"toasts": { "quiet": true },
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Or via environment variable:
|
|
457
|
+
|
|
458
|
+
```bash
|
|
459
|
+
export OPENCODE_ANTHROPIC_QUIET=1
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Error toasts (e.g., "Disabled Account 1 (token refresh failed)") are never suppressed.
|
|
463
|
+
|
|
464
|
+
### "CLI command not found"
|
|
465
|
+
|
|
466
|
+
Make sure `~/.local/bin` is on your PATH:
|
|
467
|
+
|
|
468
|
+
```bash
|
|
469
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
## License
|
|
473
|
+
|
|
474
|
+
Same as upstream. See [anomalyco/opencode-anthropic-auth](https://github.com/anomalyco/opencode-anthropic-auth).
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
_Maintained at [marco-jardim/opencode-anthropic-fix](https://github.com/marco-jardim/opencode-anthropic-fix)._
|
package/agents.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# agents.md
|
|
2
|
+
|
|
3
|
+
This repository is OAuth-first and optimized for Claude Code request mimese.
|
|
4
|
+
|
|
5
|
+
## Operating rules
|
|
6
|
+
|
|
7
|
+
- Use OAuth login flows (`opencode-anthropic-auth login` / `reauth`) for all accounts.
|
|
8
|
+
- Treat direct API-key auth as out of scope for normal operation.
|
|
9
|
+
- Keep Claude signature emulation enabled by default unless debugging a regression.
|
|
10
|
+
|
|
11
|
+
## Request-shaping expectations
|
|
12
|
+
|
|
13
|
+
- Always include OAuth beta behavior: `oauth-2025-04-20` must be present in `anthropic-beta` when authenticated via OAuth.
|
|
14
|
+
- Preserve model/provider-aware beta composition logic in `index.mjs`.
|
|
15
|
+
- Preserve Claude-style system prompt shaping (identity block + billing header block rules).
|
|
16
|
+
- Keep `metadata.user_id` composition stable across account/session context.
|
|
17
|
+
|
|
18
|
+
## Change policy for contributors and agents
|
|
19
|
+
|
|
20
|
+
- Prefer minimal diffs that keep existing runtime behavior intact.
|
|
21
|
+
- When updating beta/header logic, update docs in `docs/mimese-http-header-system-prompt.md` and `README.md` together.
|
|
22
|
+
- Add or adjust tests in `index.test.mjs` for any header/system/body mimicry change.
|
package/bun.lock
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"workspaces": {
|
|
4
|
+
"": {
|
|
5
|
+
"name": "opencode-anthropic-auth",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@openauthjs/openauth": "^0.4.3",
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@opencode-ai/plugin": "^0.4.45",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
"packages": {
|
|
15
|
+
"@openauthjs/openauth": ["@openauthjs/openauth@0.4.3", "", { "dependencies": { "@standard-schema/spec": "1.0.0-beta.3", "aws4fetch": "1.0.20", "jose": "5.9.6" }, "peerDependencies": { "arctic": "^2.2.2", "hono": "^4.0.0" } }, "sha512-RlnjqvHzqcbFVymEwhlUEuac4utA5h4nhSK/i2szZuQmxTIqbGUxZ+nM+avM+VV4Ing+/ZaNLKILoXS3yrkOOw=="],
|
|
16
|
+
|
|
17
|
+
"@opencode-ai/plugin": ["@opencode-ai/plugin@0.4.45", "", { "dependencies": { "@opencode-ai/sdk": "0.4.19" } }, "sha512-TuD+FNmA6vN+/B82qayCvOyTXRuAtfvU0U95UKSZoNrYgIBhpD/sW/oS65iUv5QwQqzO8BxI4DYWjmLIqCz8uw=="],
|
|
18
|
+
|
|
19
|
+
"@opencode-ai/sdk": ["@opencode-ai/sdk@0.4.19", "", {}, "sha512-7V+wDR1+m+TQZAraAh/bOSObiA/uysG1YIXZVe6gl1sQAXDtkG2FYCzs0gTZ/ORdkUKEnr3vyQIk895Mu0CC/w=="],
|
|
20
|
+
|
|
21
|
+
"@oslojs/asn1": ["@oslojs/asn1@1.0.0", "", { "dependencies": { "@oslojs/binary": "1.0.0" } }, "sha512-zw/wn0sj0j0QKbIXfIlnEcTviaCzYOY3V5rAyjR6YtOByFtJiT574+8p9Wlach0lZH9fddD4yb9laEAIl4vXQA=="],
|
|
22
|
+
|
|
23
|
+
"@oslojs/binary": ["@oslojs/binary@1.0.0", "", {}, "sha512-9RCU6OwXU6p67H4NODbuxv2S3eenuQ4/WFLrsq+K/k682xrznH5EVWA7N4VFk9VYVcbFtKqur5YQQZc0ySGhsQ=="],
|
|
24
|
+
|
|
25
|
+
"@oslojs/crypto": ["@oslojs/crypto@1.0.1", "", { "dependencies": { "@oslojs/asn1": "1.0.0", "@oslojs/binary": "1.0.0" } }, "sha512-7n08G8nWjAr/Yu3vu9zzrd0L9XnrJfpMioQcvCMxBIiF5orECHe5/3J0jmXRVvgfqMm/+4oxlQ+Sq39COYLcNQ=="],
|
|
26
|
+
|
|
27
|
+
"@oslojs/encoding": ["@oslojs/encoding@1.1.0", "", {}, "sha512-70wQhgYmndg4GCPxPPxPGevRKqTIJ2Nh4OkiMWmDAVYsTQ+Ta7Sq+rPevXyXGdzr30/qZBnyOalCszoMxlyldQ=="],
|
|
28
|
+
|
|
29
|
+
"@oslojs/jwt": ["@oslojs/jwt@0.2.0", "", { "dependencies": { "@oslojs/encoding": "0.4.1" } }, "sha512-bLE7BtHrURedCn4Mco3ma9L4Y1GR2SMBuIvjWr7rmQ4/W/4Jy70TIAgZ+0nIlk0xHz1vNP8x8DCns45Sb2XRbg=="],
|
|
30
|
+
|
|
31
|
+
"@standard-schema/spec": ["@standard-schema/spec@1.0.0-beta.3", "", {}, "sha512-0ifF3BjA1E8SY9C+nUew8RefNOIq0cDlYALPty4rhUm8Rrl6tCM8hBT4bhGhx7I7iXD0uAgt50lgo8dD73ACMw=="],
|
|
32
|
+
|
|
33
|
+
"arctic": ["arctic@2.3.4", "", { "dependencies": { "@oslojs/crypto": "1.0.1", "@oslojs/encoding": "1.1.0", "@oslojs/jwt": "0.2.0" } }, "sha512-+p30BOWsctZp+CVYCt7oAean/hWGW42sH5LAcRQX56ttEkFJWbzXBhmSpibbzwSJkRrotmsA+oAoJoVsU0f5xA=="],
|
|
34
|
+
|
|
35
|
+
"aws4fetch": ["aws4fetch@1.0.20", "", {}, "sha512-/djoAN709iY65ETD6LKCtyyEI04XIBP5xVvfmNxsEP0uJB5tyaGBztSryRr4HqMStr9R06PisQE7m9zDTXKu6g=="],
|
|
36
|
+
|
|
37
|
+
"hono": ["hono@4.9.1", "", {}, "sha512-qfvdJ42t6CQE0N/iSCa8KsW8SQqYD67YB+TYbwPHlnALvX+s7ynh8otR1NEk5jXtUg73gpV/B82OSufDmwtX3w=="],
|
|
38
|
+
|
|
39
|
+
"jose": ["jose@5.9.6", "", {}, "sha512-AMlnetc9+CV9asI19zHmrgS/WYsWUwCn2R7RzlbJWD7F9eWYUTGyBmU9o6PxngtLGOiDGPRu+Uc4fhKzbpteZQ=="],
|
|
40
|
+
|
|
41
|
+
"@oslojs/jwt/@oslojs/encoding": ["@oslojs/encoding@0.4.1", "", {}, "sha512-hkjo6MuIK/kQR5CrGNdAPZhS01ZCXuWDRJ187zh6qqF2+yMHZpD9fAYpX8q2bOO6Ryhl3XpCT6kUX76N8hhm4Q=="],
|
|
42
|
+
}
|
|
43
|
+
}
|