opencode-claude-auth 0.5.5 → 0.5.7
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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ OpenCode plugin that uses your existing Claude Code credentials — no separate
|
|
|
8
8
|
|
|
9
9
|
## How it works
|
|
10
10
|
|
|
11
|
-
Claude Code stores OAuth tokens in the macOS Keychain (or `~/.claude/.credentials.json` on other platforms). This plugin reads those tokens and writes them to OpenCode's `~/.local/share/opencode/auth.json
|
|
11
|
+
Claude Code stores OAuth tokens in the macOS Keychain (or `~/.claude/.credentials.json` on other platforms). This plugin reads those tokens and writes them to OpenCode's `~/.local/share/opencode/auth.json` (on Windows, it writes to both `%USERPROFILE%\.local\share\opencode\auth.json` and `%LOCALAPPDATA%\opencode\auth.json` to cover all installation methods), so you don't need to log in twice. It re-syncs every 5 minutes to pick up token refreshes. If a token is near expiry, it runs the Claude CLI to trigger a refresh.
|
|
12
12
|
|
|
13
13
|
## Prerequisites
|
|
14
14
|
|
|
@@ -66,7 +66,7 @@ The plugin checks these in order:
|
|
|
66
66
|
## How it works (technical)
|
|
67
67
|
|
|
68
68
|
- Reads OAuth tokens from macOS Keychain (`Claude Code-credentials` entry) or `~/.claude/.credentials.json` fallback
|
|
69
|
-
- Writes an `anthropic` entry to `~/.local/share/opencode/auth.json` in OpenCode's native OAuth format
|
|
69
|
+
- Writes an `anthropic` entry to `~/.local/share/opencode/auth.json` (on Windows, writes to both `%USERPROFILE%\.local\share\opencode\auth.json` and `%LOCALAPPDATA%\opencode\auth.json`) in OpenCode's native OAuth format
|
|
70
70
|
- Preserves other provider entries already in auth.json
|
|
71
71
|
- Re-syncs credentials every 5 minutes in the background
|
|
72
72
|
- When a token is within 60 seconds of expiry, runs `claude` CLI to trigger a refresh
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AA+EjD,QAAA,MAAM,MAAM,EAAE,MAmCb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,15 +3,18 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { readClaudeCredentials } from "./keychain.js";
|
|
6
|
-
function
|
|
6
|
+
function getAuthJsonPaths() {
|
|
7
|
+
const xdgPath = join(homedir(), ".local", "share", "opencode", "auth.json");
|
|
7
8
|
if (process.platform === "win32") {
|
|
8
9
|
const appData = process.env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local");
|
|
9
|
-
|
|
10
|
+
const localAppDataPath = join(appData, "opencode", "auth.json");
|
|
11
|
+
// Write to both paths on Windows: some installs (Chocolatey, npm global)
|
|
12
|
+
// use the XDG-style path, others use %LOCALAPPDATA%. See #33.
|
|
13
|
+
return [xdgPath, localAppDataPath];
|
|
10
14
|
}
|
|
11
|
-
return
|
|
15
|
+
return [xdgPath];
|
|
12
16
|
}
|
|
13
|
-
function
|
|
14
|
-
const authPath = getAuthJsonPath();
|
|
17
|
+
function syncToPath(authPath, creds) {
|
|
15
18
|
let auth = {};
|
|
16
19
|
if (existsSync(authPath)) {
|
|
17
20
|
const raw = readFileSync(authPath, "utf-8").trim();
|
|
@@ -36,9 +39,14 @@ function syncAuthJson(creds) {
|
|
|
36
39
|
}
|
|
37
40
|
writeFileSync(authPath, JSON.stringify(auth, null, 2), "utf-8");
|
|
38
41
|
}
|
|
42
|
+
function syncAuthJson(creds) {
|
|
43
|
+
for (const authPath of getAuthJsonPaths()) {
|
|
44
|
+
syncToPath(authPath, creds);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
39
47
|
function refreshViaCli() {
|
|
40
48
|
try {
|
|
41
|
-
execSync("claude -p . --model
|
|
49
|
+
execSync("claude -p . --model haiku", {
|
|
42
50
|
timeout: 60_000,
|
|
43
51
|
encoding: "utf-8",
|
|
44
52
|
env: { ...process.env, TERM: "dumb" },
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,qBAAqB,EAA0B,MAAM,eAAe,CAAA;AAE7E,SAAS,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,qBAAqB,EAA0B,MAAM,eAAe,CAAA;AAE7E,SAAS,gBAAgB;IACvB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,E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