@ex-machina/opencode-anthropic-auth 0.0.16 → 0.0.17
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 +60 -0
- package/images/renaming.jpg +0 -0
- package/index.mjs +0 -16
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @ex-machina/opencode-anthropic-auth
|
|
2
|
+
|
|
3
|
+
An [OpenCode](https://github.com/anomalyco/opencode) plugin that provides Anthropic OAuth authentication, enabling Claude Pro/Max users to use their subscription directly with OpenCode.
|
|
4
|
+
|
|
5
|
+
<details>
|
|
6
|
+
<summary>This solves the ".opencode" -> ".Claude" issues too!</summary>
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
</details>
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @ex-machina/opencode-anthropic-auth
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Add the plugin to your OpenCode configuration:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"plugins": ["@ex-machina/opencode-anthropic-auth"]
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Authentication Methods
|
|
28
|
+
|
|
29
|
+
The plugin provides three authentication options:
|
|
30
|
+
|
|
31
|
+
- **Claude Pro/Max** - OAuth flow via `claude.ai` for Pro/Max subscribers. Uses your existing subscription at no additional API cost.
|
|
32
|
+
- **Create an API Key** - OAuth flow via `console.anthropic.com` that creates an API key on your behalf.
|
|
33
|
+
- **Manually enter API Key** - Standard API key entry for users who already have one.
|
|
34
|
+
|
|
35
|
+
## How It Works
|
|
36
|
+
|
|
37
|
+
For Claude Pro/Max authentication, the plugin:
|
|
38
|
+
|
|
39
|
+
1. Initiates a PKCE OAuth flow against Anthropic's authorization endpoint
|
|
40
|
+
2. Exchanges the authorization code for access and refresh tokens
|
|
41
|
+
3. Automatically refreshes expired tokens
|
|
42
|
+
4. Injects the required OAuth headers and beta flags into API requests
|
|
43
|
+
5. Zeros out model costs (since usage is covered by the subscription)
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
### Publishing
|
|
48
|
+
|
|
49
|
+
Bump the version and push to `main` -- CI will publish to npm automatically:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
bun bump # patch bump (0.0.13 -> 0.0.14)
|
|
53
|
+
bun bump minor # minor bump (0.0.13 -> 0.1.0)
|
|
54
|
+
bun bump major # major bump (0.0.13 -> 1.0.0)
|
|
55
|
+
bun bump -- --dry-run # preview without changes
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
|
Binary file
|
package/index.mjs
CHANGED
|
@@ -195,22 +195,6 @@ export async function AnthropicAuthPlugin({ client }) {
|
|
|
195
195
|
try {
|
|
196
196
|
const parsed = JSON.parse(body);
|
|
197
197
|
|
|
198
|
-
// Sanitize system prompt - server blocks "OpenCode" string
|
|
199
|
-
// Note: (?<!\/) preserves paths like /path/to/opencode-foo
|
|
200
|
-
if (parsed.system && Array.isArray(parsed.system)) {
|
|
201
|
-
parsed.system = parsed.system.map((item) => {
|
|
202
|
-
if (item.type === "text" && item.text) {
|
|
203
|
-
return {
|
|
204
|
-
...item,
|
|
205
|
-
text: item.text
|
|
206
|
-
.replace(/OpenCode/g, "Claude Code")
|
|
207
|
-
.replace(/(?<!\/)opencode/gi, "Claude"),
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
return item;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
198
|
// Add prefix to tools definitions
|
|
215
199
|
if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
216
200
|
parsed.tools = parsed.tools.map((tool) => ({
|