@slkiser/opencode-quota 2.11.1 → 2.12.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 CHANGED
@@ -78,7 +78,7 @@ That is enough for most installs. Providers are auto-detected from your existing
78
78
 
79
79
  | Provider | Auto setup | How it works |
80
80
  | --- | --- | --- |
81
- | **Anthropic (Claude)** | Needs [quick setup](#anthropic-quick-setup) | Claude Code credentials or env. |
81
+ | **Anthropic (Claude)** | Needs [quick setup](#anthropic-quick-setup) | Local Claude CLI auth/status probe. |
82
82
  | **GitHub Copilot** | Usually | OpenCode auth; PAT only for managed billing. |
83
83
  | **OpenAI** | Yes | OpenCode auth. |
84
84
  | **Cursor** | Needs [quick setup](#cursor-quick-setup) | Companion auth plugin + `provider.cursor`. |
@@ -94,20 +94,18 @@ That is enough for most installs. Providers are auto-detected from your existing
94
94
  <details>
95
95
  <summary><strong>Quick setup: Anthropic (Claude)</strong></summary>
96
96
 
97
- Anthropic quota support uses Claude Code credentials and surfaces the 5-hour and 7-day rate-limit windows.
97
+ Anthropic quota support now checks the local Claude CLI instead of passing Claude consumer OAuth tokens directly to Anthropic APIs.
98
98
 
99
- Credential resolution order:
100
-
101
- 1. `~/.claude/.credentials.json` → `claudeAiOauth.accessToken`
102
- 2. `CLAUDE_CODE_OAUTH_TOKEN` environment variable
99
+ If Claude Code is already installed and authenticated, this usually works automatically. Otherwise:
103
100
 
104
- OpenCode `auth.json` is not used for Anthropic quota resolution.
101
+ 1. Install Claude Code so `claude` is available on your `PATH`.
102
+ 2. Run `claude auth login`.
103
+ 3. Confirm `claude auth status` succeeds locally.
104
+ 4. Confirm OpenCode is configured with the `anthropic` provider.
105
105
 
106
- If Claude Code is already installed and authenticated, this usually works automatically. Otherwise:
106
+ If Claude lives at a custom path, set `experimental.quotaToast.anthropicBinaryPath`. The default is `claude`.
107
107
 
108
- 1. Run Claude Code once so it writes `~/.claude/.credentials.json`.
109
- 2. If needed, set `CLAUDE_CODE_OAUTH_TOKEN` manually as a fallback.
110
- 3. Confirm OpenCode is configured with the `anthropic` provider.
108
+ If you use Anthropic via API key in OpenCode, model usage still works normally. This plugin only shows Anthropic quota rows when the local Claude CLI exposes quota windows.
111
109
 
112
110
  For behavior details and troubleshooting, see [Anthropic notes](#anthropic-notes).
113
111
 
@@ -202,14 +200,18 @@ There is no `/token` command. The reporting commands are the `/tokens_*` family.
202
200
  <details>
203
201
  <summary><strong>Anthropic (Claude)</strong></summary>
204
202
 
205
- Quota is fetched from `GET https://api.anthropic.com/api/oauth/usage` using a Claude Code OAuth access token.
203
+ The plugin probes the local Claude CLI with `anthropicBinaryPath --version` and `anthropicBinaryPath auth status`. By default `anthropicBinaryPath` is `claude`, so standard installs work without extra config. It does not pass Claude Free/Pro/Max OAuth tokens directly to Anthropic endpoints.
204
+
205
+ If the Claude CLI exposes 5-hour and 7-day quota windows in local structured output, the plugin shows them. If the CLI only exposes auth state, Anthropic quota rows are skipped and `/quota_status` explains why.
206
206
 
207
207
  **Troubleshooting:**
208
208
 
209
209
  | Problem | Solution |
210
210
  | --- | --- |
211
- | "No credentials found" | Run Claude Code once so it writes `~/.claude/.credentials.json`, or set `CLAUDE_CODE_OAUTH_TOKEN` |
212
- | "Invalid or expired token" | Refresh `~/.claude/.credentials.json` by re-authenticating Claude Code, or update `CLAUDE_CODE_OAUTH_TOKEN` |
211
+ | `claude` not found | Install Claude Code and make sure `claude` is on your `PATH` |
212
+ | Claude installed at a custom path | Set `experimental.quotaToast.anthropicBinaryPath` to the Claude executable path |
213
+ | Not authenticated | Run `claude auth login`, then confirm `claude auth status` works |
214
+ | Authenticated but no quota rows | Your local Claude CLI version did not expose quota windows; run `/quota_status` for the exact probe result |
213
215
  | Plugin not detected | Confirm OpenCode is configured with the `anthropic` provider |
214
216
 
215
217
  </details>
@@ -418,6 +420,7 @@ Workspace-local config can still customize display/report behavior, but user/glo
418
420
  | `enableToast` | `true` | Show popup toasts |
419
421
  | `toastStyle` | `classic` | Toast layout: `classic` or `grouped` |
420
422
  | `enabledProviders` | `"auto"` | Auto-detect providers, or set an explicit provider list |
423
+ | `anthropicBinaryPath` | `"claude"` | Command/path used for local Claude CLI probing; override this for custom installs or shim locations |
421
424
  | `minIntervalMs` | `300000` | Minimum fetch interval between provider updates |
422
425
  | `toastDurationMs` | `9000` | Toast duration in milliseconds |
423
426
  | `showOnIdle` | `true` | Show toast on idle trigger |
@@ -479,7 +482,7 @@ MIT
479
482
 
480
483
  OpenCode Quota is not built by the OpenCode team and is not affiliated with OpenCode or any provider listed above.
481
484
 
482
- The Anthropic provider uses the documented OAuth usage endpoint with Claude Code credentials from `~/.claude/.credentials.json` or `CLAUDE_CODE_OAUTH_TOKEN`.
485
+ Anthropic quota detection is delegated to the local Claude CLI/runtime. OpenCode Anthropic API-key usage is unaffected, but this plugin only surfaces Anthropic quota rows when the local Claude CLI exposes them.
483
486
 
484
487
  ## Star History
485
488
 
@@ -1,20 +1,23 @@
1
1
  /**
2
- * Anthropic Claude quota fetcher.
2
+ * Anthropic Claude quota probing.
3
3
  *
4
- * Reads a Claude Code OAuth access token from local Claude credentials and
5
- * queries the Anthropic usage API to surface 5-hour and 7-day rate-limit
6
- * windows.
7
- *
8
- * Supported credential sources:
9
- * 1. ~/.claude/.credentials.json → claudeAiOauth.accessToken
10
- * 2. CLAUDE_CODE_OAUTH_TOKEN environment variable
4
+ * Uses the local Claude CLI/runtime to detect install/auth state and surface
5
+ * quota windows only when the official runtime exposes them locally. This
6
+ * module does not read Claude consumer OAuth tokens or call Anthropic's OAuth
7
+ * usage endpoint directly.
11
8
  */
12
- declare const CREDENTIALS_PATH: string;
13
9
  export interface AnthropicQuotaWindow {
14
- /** Used percentage [0..100]. */
15
- used_percentage: number;
16
- /** ISO timestamp when this window resets. */
17
- resets_at: string;
10
+ utilization?: number;
11
+ used_percentage?: number;
12
+ usedPercentage?: number;
13
+ used_percent?: number;
14
+ usedPercent?: number;
15
+ percent_used?: number;
16
+ percentUsed?: number;
17
+ resets_at?: string;
18
+ resetsAt?: string;
19
+ reset_at?: string;
20
+ resetAt?: string;
18
21
  }
19
22
  export interface AnthropicUsageResponse {
20
23
  five_hour: AnthropicQuotaWindow;
@@ -36,28 +39,35 @@ export interface AnthropicQuotaError {
36
39
  error: string;
37
40
  }
38
41
  export type AnthropicResult = AnthropicQuotaResult | AnthropicQuotaError | null;
39
- interface ClaudeCredentials {
40
- claudeAiOauth?: {
41
- accessToken?: string;
42
- expiresAt?: number;
43
- };
42
+ export type AnthropicAuthStatus = "authenticated" | "unauthenticated" | "unknown";
43
+ export type AnthropicQuotaSource = "claude-auth-status-json" | "none";
44
+ export interface AnthropicDiagnostics {
45
+ installed: boolean;
46
+ version: string | null;
47
+ authStatus: AnthropicAuthStatus;
48
+ quotaSupported: boolean;
49
+ quotaSource: AnthropicQuotaSource;
50
+ checkedCommands: string[];
51
+ message?: string;
52
+ quota?: AnthropicQuotaResult;
44
53
  }
45
- export interface ResolvedAnthropicCredentials {
46
- accessToken: string;
47
- expiresAt?: number;
48
- source: "file" | "env";
54
+ export interface AnthropicProbeOptions {
55
+ binaryPath?: string;
49
56
  }
50
- declare function readCredentialsFile(): ClaudeCredentials | null;
51
- export declare function resolveAnthropicCredentialsFromFile(credentials: ClaudeCredentials | null | undefined): ResolvedAnthropicCredentials | null;
52
- export declare function resolveAnthropicCredentials(): Promise<ResolvedAnthropicCredentials | null>;
53
- export declare function hasAnthropicCredentialsConfigured(): Promise<boolean>;
57
+ export type ClaudeCommandInvocation = {
58
+ file: string;
59
+ args: string[];
60
+ display: string;
61
+ };
62
+ export declare function resolveAnthropicBinaryPath(binaryPath?: string): string;
63
+ export declare function buildClaudeCommandInvocation(binaryPath: string, args: string[], runtime?: {
64
+ platform?: NodeJS.Platform;
65
+ comspec?: string;
66
+ }): ClaudeCommandInvocation;
54
67
  declare function parseUsageResponse(data: unknown): AnthropicQuotaResult | null;
55
- /**
56
- * Query the Anthropic OAuth usage API for Claude rate-limit windows.
57
- *
58
- * Returns null when no credentials are found (provider not configured).
59
- * Returns an error result when credentials exist but the fetch fails.
60
- */
61
- export declare function queryAnthropicQuota(): Promise<AnthropicResult>;
62
- export { CREDENTIALS_PATH, parseUsageResponse, readCredentialsFile };
68
+ export declare function clearAnthropicDiagnosticsCacheForTests(): void;
69
+ export declare function getAnthropicDiagnostics(options?: AnthropicProbeOptions): Promise<AnthropicDiagnostics>;
70
+ export declare function hasAnthropicCredentialsConfigured(options?: AnthropicProbeOptions): Promise<boolean>;
71
+ export declare function queryAnthropicQuota(options?: AnthropicProbeOptions): Promise<AnthropicResult>;
72
+ export { parseUsageResponse };
63
73
  //# sourceMappingURL=anthropic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/lib/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,QAAA,MAAM,gBAAgB,QAAkD,CAAC;AAMzE,MAAM,WAAW,oBAAoB;IACnC,gCAAgC;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,oBAAoB,CAAC;IAChC,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/D,SAAS,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAChE;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,mBAAmB,GAAG,IAAI,CAAC;AAEhF,UAAU,iBAA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