opencode-anthropic-fix 0.2.0 → 0.3.0-beta.0
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 +31 -6
- package/cli.mjs +1 -0
- package/index.mjs +160 -231
- package/lib/backoff.mjs +1 -1
- package/lib/cc-credentials.mjs +1 -1
- package/lib/config.mjs +49 -27
- package/lib/mimicry/adapter-input.mjs +671 -0
- package/lib/mimicry/context-hint-threshold.mjs +127 -0
- package/lib/mimicry/headers.mjs +71 -66
- package/lib/mimicry/request-body.mjs +23 -24
- package/lib/mimicry/system-prompt.mjs +54 -23
- package/lib/mimicry/wire-compat.mjs +305 -0
- package/lib/rotation.mjs +16 -0
- package/package.json +3 -3
- package/lib/account-state.test.mjs +0 -109
- package/lib/accounts.test.mjs +0 -912
- package/lib/adaptive-thinking-models.test.mjs +0 -30
- package/lib/backoff.test.mjs +0 -411
- package/lib/cc-credentials.test.mjs +0 -391
- package/lib/config.test.mjs +0 -757
- package/lib/context-hint-persist.mjs +0 -68
- package/lib/diagnose.test.mjs +0 -122
- package/lib/env.test.mjs +0 -25
- package/lib/haiku-call.test.mjs +0 -72
- package/lib/message-transform.test.mjs +0 -173
- package/lib/mimicry/cache.test.mjs +0 -112
- package/lib/mimicry/headers.test.mjs +0 -50
- package/lib/mimicry/models.test.mjs +0 -132
- package/lib/mimicry/request-body.test.mjs +0 -34
- package/lib/mimicry/request-helpers.test.mjs +0 -155
- package/lib/mimicry/response-stream.test.mjs +0 -127
- package/lib/mimicry/system-prompt.test.mjs +0 -73
- package/lib/oauth.test.mjs +0 -343
- package/lib/redact.test.mjs +0 -154
- package/lib/refresh-lock.test.mjs +0 -131
- package/lib/request-headers.test.mjs +0 -164
- package/lib/retry/overload-loop.test.mjs +0 -107
- package/lib/rotation.test.mjs +0 -346
- package/lib/session-metrics.test.mjs +0 -67
- package/lib/storage.test.mjs +0 -696
- package/lib/token-economy/microcompact.test.mjs +0 -28
- package/lib/token-economy/transforms.test.mjs +0 -192
- package/lib/tuning.test.mjs +0 -89
package/README.md
CHANGED
|
@@ -12,6 +12,22 @@ This fork continues that work and extends it with deeper research into how the o
|
|
|
12
12
|
|
|
13
13
|
> **Account risk.** There is a real risk of account suspension if Anthropic detects requests are not coming from Claude Code. The mimicry tries hard to make every request look as close as possible to a genuine Claude Code request, but that reduces rather than eliminates the risk. Use at your own risk.
|
|
14
14
|
|
|
15
|
+
<a id="provider-scope"></a>
|
|
16
|
+
|
|
17
|
+
## Provider Scope: Anthropic First-Party Only
|
|
18
|
+
|
|
19
|
+
This plugin targets the Anthropic first-party API and nothing else. **Amazon Bedrock, Anthropic on AWS (`anthropicAws`), Google Vertex AI, Azure/Microsoft Foundry and Mantle are permanently out of scope.** They are not a backlog item, not a "not yet" — support for them will not be added.
|
|
20
|
+
|
|
21
|
+
What that means concretely:
|
|
22
|
+
|
|
23
|
+
- The signature-emulation adapter **declines** any provider that is not `anthropic` (`lib/adapter-input.mjs`). Those requests fall through to the legacy request path, which serves them without any provider-specific branching.
|
|
24
|
+
- **Nothing is suppressed based on the provider.** There is no provider-gated logic for the `x-anthropic-billing-header` segments (`cch`, `cc_workload`), no provider filter over the `anthropic-beta` header, and no provider-conditional request-body segment. `cch=00000` and the beta list are emitted unconditionally.
|
|
25
|
+
- Constructs such as a `BEDROCK_UNSUPPORTED_BETAS` list or an `anthropic_beta` field inside the request body do not exist in this codebase. Their absence is pinned by tests.
|
|
26
|
+
|
|
27
|
+
Provider names still appear in three legitimate places, and none of them imply multi-provider support: reverse-engineering notes describing the **official upstream Claude Code binary** (which does branch by provider), Bedrock model-ARN parsing kept for identifier normalization, and the provider environment variables listed by `anthropic doctor`.
|
|
28
|
+
|
|
29
|
+
If a document or comment claims this plugin branches on the provider, that claim is stale — this section is the canonical answer.
|
|
30
|
+
|
|
15
31
|
## Quick Start
|
|
16
32
|
|
|
17
33
|
**Prerequisites:** [OpenCode](https://github.com/anomalyco/opencode) installed, a Claude Pro or Max subscription, Node.js 18+.
|
|
@@ -365,11 +381,12 @@ Pending slash OAuth flows expire after 10 minutes. If completion fails with an e
|
|
|
365
381
|
|
|
366
382
|
Control how the plugin picks which account to use for each request.
|
|
367
383
|
|
|
368
|
-
| Strategy | Behavior
|
|
369
|
-
| ---------------------- |
|
|
370
|
-
| **`sticky`** (default) | Stay on one account until it fails or is rate-limited
|
|
371
|
-
| **`round-robin`** | Rotate through accounts on every request
|
|
372
|
-
| **`hybrid`** | Score-based selection with stickiness bias. Considers health, token budget, and freshness
|
|
384
|
+
| Strategy | Behavior | Best For |
|
|
385
|
+
| ---------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
386
|
+
| **`sticky`** (default) | Stay on one account until it fails or is rate-limited | Single account, predictable behavior, full feature compatibility |
|
|
387
|
+
| **`round-robin`** | Rotate through accounts on every request | Spreading load evenly across accounts (see [limitations](#round-robin-limitations)) |
|
|
388
|
+
| **`hybrid`** | Score-based selection with stickiness bias. Considers health, token budget, and freshness | Multiple accounts with varying rate limits |
|
|
389
|
+
| **`single`** | Use one account only; stop and alert when it fails or is rate-limited (never auto-switches) | Simple multi-account setups (e.g. work vs personal) where requests must never mix accounts |
|
|
373
390
|
|
|
374
391
|
### Change Strategy
|
|
375
392
|
|
|
@@ -413,7 +430,7 @@ Configuration is stored at `~/.config/opencode/anthropic-auth.json`. All setting
|
|
|
413
430
|
|
|
414
431
|
```jsonc
|
|
415
432
|
{
|
|
416
|
-
// Account selection strategy: "sticky" | "round-robin" | "hybrid"
|
|
433
|
+
// Account selection strategy: "sticky" | "round-robin" | "hybrid" | "single"
|
|
417
434
|
"account_selection_strategy": "sticky",
|
|
418
435
|
|
|
419
436
|
// Seconds before consecutive failure count resets (60-7200)
|
|
@@ -715,6 +732,14 @@ export PATH="$HOME/.local/bin:$PATH"
|
|
|
715
732
|
|
|
716
733
|
- [AnomalyCo](https://github.com/anomalyco/opencode-anthropic-auth) — Original OpenCode Anthropic auth plugin
|
|
717
734
|
|
|
735
|
+
## Third-Party Dependencies
|
|
736
|
+
|
|
737
|
+
The outgoing Anthropic Messages request is built by
|
|
738
|
+
[`@tormentalabs/claude-code-wire-compat`](https://github.com/marco-jardim/claude-code-wire-compat),
|
|
739
|
+
licensed under GPL-3.0-or-later. Attribution for every redistributed dependency is in
|
|
740
|
+
[NOTICE](NOTICE); the pinned artifact, its integrity hash, and the rollback procedure are in
|
|
741
|
+
[docs/shared-package-provenance.md](docs/shared-package-provenance.md).
|
|
742
|
+
|
|
718
743
|
## License
|
|
719
744
|
|
|
720
745
|
This project is licensed under the [GNU General Public License v3.0](LICENSE) (GPLv3).
|
package/cli.mjs
CHANGED
|
@@ -1153,6 +1153,7 @@ export async function cmdStrategy(arg) {
|
|
|
1153
1153
|
sticky: "Stay on one account until it fails or is rate-limited",
|
|
1154
1154
|
"round-robin": "Rotate through accounts on every request",
|
|
1155
1155
|
hybrid: "Prefer healthy accounts, rotate when degraded",
|
|
1156
|
+
single: "Use one account only; stop and alert when it fails or is rate-limited",
|
|
1156
1157
|
};
|
|
1157
1158
|
|
|
1158
1159
|
for (const s of VALID_STRATEGIES) {
|