opencode-anthropic-fix 0.0.24 → 0.0.25

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.mjs +27 -53
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -45,6 +45,7 @@ The [original plugin](https://github.com/anomalyco/opencode-anthropic-auth) prov
45
45
  - **Claude Code signature emulation** — full HTTP header, system prompt, beta flag, and metadata mimicry derived from Claude Code's open source code
46
46
  - **OAuth endpoint fingerprint parity** — sends Claude Code-style `User-Agent` on `/v1/oauth/token` and `/v1/oauth/revoke` to match current OAuth validation
47
47
  - **Effort-based thinking for Opus 4.6** — maps `budgetTokens` to effort levels (`low`/`medium`/`high`) and includes `effort-2025-11-24`
48
+ - **Upstream-aligned auto betas** — `advanced-tool-use-2025-11-20` and `fast-mode-2026-02-01` auto-included to match Claude Code 2.1.79+ (`redact-thinking-2026-02-12` available as opt-in to preserve thinking block visibility)
48
49
  - **1M context limit override** — patches `model.limit.context` so OpenCode compacts at the right threshold while `models.dev` catches up
49
50
  - **Runtime config + custom betas** — `/anthropic set`, `/anthropic config`, and `/anthropic betas` slash commands for live feature toggling without restarting OpenCode
50
51
  - **Files API integration** — upload, list, download, and manage files via `/anthropic files` with endpoint/content-scoped `files-api-2025-04-14` beta injection
@@ -273,7 +274,6 @@ Add or remove beta flags that get included in every `anthropic-beta` header. Per
273
274
  /anthropic betas add <beta-name> # add a custom beta
274
275
  /anthropic betas remove <beta-name> # remove a custom beta
275
276
  /anthropic betas add 1m # shortcut => context-1m-2025-08-07
276
- /anthropic betas add fast # shortcut => fast-mode-2026-02-01
277
277
  ```
278
278
 
279
279
  **Available preset betas** (shown by `/anthropic betas`):
@@ -288,7 +288,7 @@ Add or remove beta flags that get included in every `anthropic-beta` header. Per
288
288
  | `mcp-servers-2025-12-04` | MCP servers in API request payload |
289
289
  | `web-search-2025-03-05` | Web search (Vertex/Foundry only) |
290
290
  | `context-1m-2025-08-07` | 1M context beta (provider/model dependent) |
291
- | `fast-mode-2026-02-01` | Faster Opus mode (experimental) |
291
+ | `redact-thinking-2026-02-12` | Hide thinking blocks from responses (opt-in) |
292
292
 
293
293
  Example workflow:
294
294
 
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createInterface } from "node:readline/promises";
2
2
  import { stdin, stdout } from "node:process";
3
- import { createHash, randomUUID } from "node:crypto";
3
+ import { randomBytes, randomUUID } from "node:crypto";
4
4
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { join, resolve, basename } from "node:path";
6
6
  import { AccountManager } from "./lib/accounts.mjs";
@@ -107,9 +107,10 @@ const FALLBACK_CLAUDE_CLI_VERSION = "2.1.79";
107
107
  const CLAUDE_CODE_NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
108
108
  const CLAUDE_CODE_BETA_FLAG = "claude-code-20250219";
109
109
  const EFFORT_BETA_FLAG = "effort-2025-11-24";
110
+ const REDACT_THINKING_BETA_FLAG = "redact-thinking-2026-02-12";
111
+ const ADVANCED_TOOL_USE_BETA_FLAG = "advanced-tool-use-2025-11-20";
112
+ const FAST_MODE_BETA_FLAG = "fast-mode-2026-02-01";
110
113
  const TOKEN_COUNTING_BETA_FLAG = "token-counting-2024-11-01";
111
- const BILLING_HASH_SALT = "59cf53e54c78";
112
- const BILLING_HASH_POSITIONS = [4, 7, 20];
113
114
  const CLAUDE_CODE_IDENTITY_STRING = "You are Claude Code, Anthropic's official CLI for Claude.";
114
115
  const KNOWN_IDENTITY_STRINGS = new Set([
115
116
  CLAUDE_CODE_IDENTITY_STRING,
@@ -429,39 +430,6 @@ function buildStainlessHelperHeader(tools, messages) {
429
430
  return Array.from(helpers).join(", ");
430
431
  }
431
432
 
432
- /**
433
- * @param {any} content
434
- * @returns {string}
435
- */
436
- function extractTextContent(content) {
437
- if (typeof content === "string") return content;
438
- if (!Array.isArray(content)) return "";
439
-
440
- const parts = [];
441
- for (const block of content) {
442
- if (!block || typeof block !== "object") continue;
443
- if (block.type === "text" && typeof block.text === "string") {
444
- parts.push(block.text);
445
- }
446
- }
447
- return parts.join("\n");
448
- }
449
-
450
- /**
451
- * @param {any[]} messages
452
- * @returns {string}
453
- */
454
- function getFirstUserText(messages) {
455
- for (const message of messages) {
456
- if (!message || typeof message !== "object") continue;
457
- if (message.role !== "user") continue;
458
-
459
- const text = extractTextContent(message.content);
460
- if (text) return text;
461
- }
462
- return "";
463
- }
464
-
465
433
  /**
466
434
  * @param {{id?: string, accountUuid?: string} | null | undefined} account
467
435
  * @returns {string}
@@ -503,18 +471,12 @@ function buildRequestMetadata(input) {
503
471
  * @param {any[]} messages
504
472
  * @returns {string}
505
473
  */
506
- function buildAnthropicBillingHeader(claudeCliVersion, messages) {
474
+ function buildAnthropicBillingHeader(claudeCliVersion) {
507
475
  if (isFalsyEnv(process.env.CLAUDE_CODE_ATTRIBUTION_HEADER)) return "";
508
476
 
509
- const firstUserText = getFirstUserText(messages);
510
- const sampled = BILLING_HASH_POSITIONS.map((position) => firstUserText[position] || "0").join("");
511
- const hash = createHash("sha256")
512
- .update(`${BILLING_HASH_SALT}${sampled}${claudeCliVersion}`)
513
- .digest("hex")
514
- .slice(0, 3);
515
-
516
- const entrypoint = process.env.CLAUDE_CODE_ENTRYPOINT || "unknown";
517
- return `x-anthropic-billing-header: cc_version=${claudeCliVersion}.${hash}; cc_entrypoint=${entrypoint}; cch=00000;`;
477
+ const cch = randomBytes(3).toString("hex").slice(0, 5);
478
+ const entrypoint = process.env.CLAUDE_CODE_ENTRYPOINT || "cli";
479
+ return `x-anthropic-billing-header: cc_version=${claudeCliVersion}; cc_entrypoint=${entrypoint}; cch=${cch};`;
518
480
  }
519
481
 
520
482
  /**
@@ -659,10 +621,9 @@ function normalizeSystemTextBlocks(system) {
659
621
  /**
660
622
  * @param {Array<{type: string, text: string, cache_control?: {type: string}}>} system
661
623
  * @param {{enabled: boolean, claudeCliVersion: string, promptCompactionMode: 'minimal' | 'off'}} signature
662
- * @param {any[]} messages
663
624
  * @returns {Array<{type: string, text: string, cache_control?: {type: string}}>}
664
625
  */
665
- function buildSystemPromptBlocks(system, signature, messages) {
626
+ function buildSystemPromptBlocks(system, signature) {
666
627
  const titleGeneratorRequest = isTitleGeneratorSystemBlocks(system);
667
628
 
668
629
  let sanitized = system.map((item) => ({
@@ -685,7 +646,7 @@ function buildSystemPromptBlocks(system, signature, messages) {
685
646
  );
686
647
 
687
648
  const blocks = [];
688
- const billingHeader = buildAnthropicBillingHeader(signature.claudeCliVersion, messages);
649
+ const billingHeader = buildAnthropicBillingHeader(signature.claudeCliVersion);
689
650
  if (billingHeader) {
690
651
  blocks.push({ type: "text", text: billingHeader });
691
652
  }
@@ -752,6 +713,20 @@ function buildAnthropicBetaHeader(
752
713
  betas.push("files-api-2025-04-14");
753
714
  }
754
715
 
716
+ // NOTE: redact-thinking-2026-02-12 is in upstream 2.1.79+ base profile but
717
+ // intentionally NOT auto-included here — OpenCode users benefit from seeing
718
+ // thinking blocks. Available via /anthropic betas add redact-thinking-2026-02-12.
719
+
720
+ // Advanced tool use improvements — in upstream 2.1.79+ base profile.
721
+ if (!disableExperimentalBetas) {
722
+ betas.push(ADVANCED_TOOL_USE_BETA_FLAG);
723
+ }
724
+
725
+ // Fast mode — in upstream 2.1.79+ base profile.
726
+ if (!disableExperimentalBetas) {
727
+ betas.push(FAST_MODE_BETA_FLAG);
728
+ }
729
+
755
730
  if (isOpus46Model(model)) {
756
731
  // Opus 4.6 uses effort-based thinking controls.
757
732
  betas.push(EFFORT_BETA_FLAG);
@@ -1049,15 +1024,13 @@ function transformRequestBody(body, signature, runtime) {
1049
1024
  if (Object.prototype.hasOwnProperty.call(parsed, "betas")) {
1050
1025
  delete parsed.betas;
1051
1026
  }
1052
- const messages = Array.isArray(parsed.messages) ? parsed.messages : [];
1053
-
1054
1027
  // Normalize thinking block for adaptive (Opus 4.6) vs manual (older models).
1055
1028
  if (Object.prototype.hasOwnProperty.call(parsed, "thinking")) {
1056
1029
  parsed.thinking = normalizeThinkingBlock(parsed.thinking, parsed.model || "");
1057
1030
  }
1058
1031
 
1059
1032
  // Sanitize system prompt and optionally inject Claude Code identity/billing blocks.
1060
- parsed.system = buildSystemPromptBlocks(normalizeSystemTextBlocks(parsed.system), signature, messages);
1033
+ parsed.system = buildSystemPromptBlocks(normalizeSystemTextBlocks(parsed.system), signature);
1061
1034
 
1062
1035
  if (signature.enabled) {
1063
1036
  const currentMetadata =
@@ -2114,6 +2087,7 @@ export async function AnthropicAuthPlugin({ client }) {
2114
2087
  "",
2115
2088
  "Preset betas (auto-computed per model/provider):",
2116
2089
  " oauth-2025-04-20, claude-code-20250219,",
2090
+ " advanced-tool-use-2025-11-20, fast-mode-2026-02-01,",
2117
2091
  " interleaved-thinking-2025-05-14 (non-Opus 4.6) OR effort-2025-11-24 (Opus 4.6),",
2118
2092
  " files-api-2025-04-14 (only /v1/files and requests with file_id),",
2119
2093
  " token-counting-2024-11-01 (only /v1/messages/count_tokens),",
@@ -2130,8 +2104,8 @@ export async function AnthropicAuthPlugin({ client }) {
2130
2104
  " /anthropic betas add web-search-2025-03-05",
2131
2105
  " /anthropic betas add compact-2026-01-12",
2132
2106
  " /anthropic betas add mcp-servers-2025-12-04",
2107
+ " /anthropic betas add redact-thinking-2026-02-12",
2133
2108
  " /anthropic betas add 1m (shortcut for context-1m-2025-08-07)",
2134
- " /anthropic betas add fast (shortcut for fast-mode-2026-02-01)",
2135
2109
  "",
2136
2110
  "Remove: /anthropic betas remove <beta>",
2137
2111
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-fix",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "main": "./index.mjs",
5
5
  "files": [
6
6
  "index.mjs",