@ex-machina/opencode-anthropic-auth 1.5.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.
- package/README.md +16 -3
- package/dist/transform.d.ts +6 -0
- package/dist/transform.js +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Add the plugin to your OpenCode configuration:
|
|
|
21
21
|
|
|
22
22
|
```json
|
|
23
23
|
{
|
|
24
|
-
"plugin": ["@ex-machina/opencode-anthropic-auth@1.
|
|
24
|
+
"plugin": ["@ex-machina/opencode-anthropic-auth@1.5.1"]
|
|
25
25
|
}
|
|
26
26
|
```
|
|
27
27
|
|
|
@@ -33,6 +33,16 @@ The plugin provides three authentication options:
|
|
|
33
33
|
- **Create an API Key** - OAuth flow via `console.anthropic.com` that creates an API key on your behalf.
|
|
34
34
|
- **Manually enter API Key** - Standard API key entry for users who already have one.
|
|
35
35
|
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
The plugin supports the following environment variables:
|
|
39
|
+
|
|
40
|
+
| Variable | Description |
|
|
41
|
+
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
42
|
+
| `ANTHROPIC_BASE_URL` | Override the API endpoint URL (e.g. for proxying). Must be a valid HTTP(S) URL. |
|
|
43
|
+
| `ANTHROPIC_INSECURE` | Set to `1` or `true` to skip TLS certificate verification. Only effective when `ANTHROPIC_BASE_URL` is also set. |
|
|
44
|
+
| `EXPERIMENTAL_KEEP_SYSTEM_PROMPT` | Set to `1` or `true` to keep the sanitized system prompt in the `system[]` field instead of relocating it to a user message. See [System Prompt Sanitization](#system-prompt-sanitization). |
|
|
45
|
+
|
|
36
46
|
## How It Works
|
|
37
47
|
|
|
38
48
|
For Claude Pro/Max authentication, the plugin:
|
|
@@ -46,13 +56,16 @@ For Claude Pro/Max authentication, the plugin:
|
|
|
46
56
|
|
|
47
57
|
### System Prompt Sanitization
|
|
48
58
|
|
|
49
|
-
The Anthropic API for Max subscriptions
|
|
59
|
+
The Anthropic API for Max subscriptions has specific requirements for the system prompt to identify as Claude Code. The plugin rewrites the system prompt on each request using an **anchor-based** approach that minimizes what gets changed:
|
|
50
60
|
|
|
51
61
|
1. **Identity swap** — The OpenCode identity line is removed and replaced with the Claude Code identity.
|
|
52
62
|
2. **Paragraph removal by anchor** — Any paragraph containing a known URL anchor (e.g. `github.com/anomalyco/opencode`, `opencode.ai/docs`) is removed entirely. This is resilient to upstream rewording — as long as the anchor URL appears somewhere in the paragraph, the removal works regardless of surrounding text changes.
|
|
53
63
|
3. **Inline text replacements** — Short branded strings inside paragraphs we want to keep are replaced (e.g. "OpenCode" → "the assistant" in the professional objectivity section).
|
|
54
64
|
|
|
55
|
-
Everything else in the system prompt is preserved: tone/style guidance, task management instructions, tool usage policy, environment info, skills, user/project instructions, and file paths containing "opencode".
|
|
65
|
+
Everything else in the system prompt is preserved: tone/style guidance, task management instructions, tool usage policy, environment info, skills, user/project instructions, and file paths containing "opencode". The system prompt is then **split** and only the billing header and identity line are left in the system prompt. The remainder is moved into a user message to bypass system prompt checks.
|
|
66
|
+
|
|
67
|
+
> [!NOTE]
|
|
68
|
+
> Set `EXPERIMENTAL_KEEP_SYSTEM_PROMPT=1` to skip the relocation step. The sanitized system prompt will remain in `system[]` in its entirety. This may cause API rejections for OAuth-authenticated requests.
|
|
56
69
|
|
|
57
70
|
## Development
|
|
58
71
|
|
package/dist/transform.d.ts
CHANGED
|
@@ -27,6 +27,12 @@ export declare function stripToolPrefix(text: string): string;
|
|
|
27
27
|
* Only effective when ANTHROPIC_BASE_URL is also set.
|
|
28
28
|
*/
|
|
29
29
|
export declare function isInsecure(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if system prompt relocation should be skipped.
|
|
32
|
+
* When enabled, sanitized system blocks stay in system[] instead of
|
|
33
|
+
* being moved to the first user message.
|
|
34
|
+
*/
|
|
35
|
+
export declare function experimentalKeepSystemPrompt(): boolean;
|
|
30
36
|
/**
|
|
31
37
|
* Rewrite the request URL to add ?beta=true for /v1/messages requests.
|
|
32
38
|
* When ANTHROPIC_BASE_URL is set, overrides the origin (protocol + host)
|
package/dist/transform.js
CHANGED
|
@@ -109,6 +109,15 @@ export function isInsecure() {
|
|
|
109
109
|
const raw = process.env.ANTHROPIC_INSECURE?.trim();
|
|
110
110
|
return raw === '1' || raw === 'true';
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if system prompt relocation should be skipped.
|
|
114
|
+
* When enabled, sanitized system blocks stay in system[] instead of
|
|
115
|
+
* being moved to the first user message.
|
|
116
|
+
*/
|
|
117
|
+
export function experimentalKeepSystemPrompt() {
|
|
118
|
+
const raw = process.env.EXPERIMENTAL_KEEP_SYSTEM_PROMPT?.trim();
|
|
119
|
+
return raw === '1' || raw === 'true';
|
|
120
|
+
}
|
|
112
121
|
/**
|
|
113
122
|
* Parse ANTHROPIC_BASE_URL from the environment.
|
|
114
123
|
* Returns a valid HTTP(S) URL or null if unset/invalid.
|
|
@@ -277,7 +286,9 @@ export function rewriteRequestBody(body) {
|
|
|
277
286
|
// Third-party system prompts trigger a 400 rejection when they
|
|
278
287
|
// appear in `system[]`. Keep only the identity block in `system[]`
|
|
279
288
|
// and prepend everything else to the first user message.
|
|
280
|
-
if (
|
|
289
|
+
if (!experimentalKeepSystemPrompt() &&
|
|
290
|
+
Array.isArray(parsed.system) &&
|
|
291
|
+
parsed.system.length > 1) {
|
|
281
292
|
const kept = [parsed.system[0]]; // identity block
|
|
282
293
|
const movedTexts = [];
|
|
283
294
|
for (let i = 1; i < parsed.system.length; i++) {
|