opencode-claude-code-wrapper 0.0.3 → 0.0.5

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 (2) hide show
  1. package/index.mjs +49 -10
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  import { generatePKCE } from "@openauthjs/openauth/pkce";
2
+ import { writeFileSync, appendFileSync, mkdirSync } from "fs";
3
+ import { homedir } from "os";
4
+ import { join } from "path";
2
5
  import {
3
6
  transformRequestToCLIArgs,
4
7
  spawnClaudeCode,
@@ -210,6 +213,24 @@ async function createNonStreamingResponse(child, requestBody) {
210
213
  });
211
214
  }
212
215
 
216
+ // Metrics logging
217
+ const METRICS_DIR = join(homedir(), ".opencode-claude-code-wrapper");
218
+ const METRICS_FILE = join(METRICS_DIR, "metrics.jsonl");
219
+
220
+ function logMetric(type, data) {
221
+ try {
222
+ mkdirSync(METRICS_DIR, { recursive: true });
223
+ const entry = {
224
+ timestamp: new Date().toISOString(),
225
+ type,
226
+ ...data,
227
+ };
228
+ appendFileSync(METRICS_FILE, JSON.stringify(entry) + "\n");
229
+ } catch (e) {
230
+ console.error("[metrics] Failed to log:", e.message);
231
+ }
232
+ }
233
+
213
234
  /**
214
235
  * Handle request via Claude Code CLI
215
236
  */
@@ -245,6 +266,26 @@ async function handleClaudeCodeRequest(input, init) {
245
266
  });
246
267
  }
247
268
 
269
+ // Log the incoming request for debugging
270
+ logMetric("request", {
271
+ model: requestBody.model,
272
+ stream: requestBody.stream,
273
+ system: requestBody.system ? (typeof requestBody.system === "string" ? requestBody.system.substring(0, 200) : "[array]") : null,
274
+ messages_count: requestBody.messages?.length,
275
+ tools_count: requestBody.tools?.length,
276
+ tool_names: requestBody.tools?.map((t) => t.name),
277
+ first_message: requestBody.messages?.[0],
278
+ last_message: requestBody.messages?.[requestBody.messages?.length - 1],
279
+ });
280
+
281
+ // Log full request body to separate file for detailed inspection
282
+ try {
283
+ writeFileSync(
284
+ join(METRICS_DIR, "last_request.json"),
285
+ JSON.stringify(requestBody, null, 2)
286
+ );
287
+ } catch (e) {}
288
+
248
289
  const isStreaming = requestBody.stream === true;
249
290
  const cliArgs = transformRequestToCLIArgs(requestBody);
250
291
  const child = spawnClaudeCode(cliArgs, { streaming: isStreaming });
@@ -268,8 +309,14 @@ export async function ClaudeCodeWrapperPlugin({ client }) {
268
309
  const auth = await getAuth();
269
310
 
270
311
  // Claude Code CLI auth - zero cost, use CLI
271
- // Detected by special key value set during authorize
272
- if (auth.type === "api" && auth.key === "claude-code-cli") {
312
+ // Detected by special key value: user enters "cli" or "claude-code" as API key
313
+ const isClaudeCodeCLI =
314
+ auth.type === "api" &&
315
+ (auth.key === "claude-code-cli" ||
316
+ auth.key === "cli" ||
317
+ auth.key === "claude-code" ||
318
+ auth.key === "cc");
319
+ if (isClaudeCodeCLI) {
273
320
  for (const model of Object.values(provider.models)) {
274
321
  model.cost = {
275
322
  input: 0,
@@ -477,14 +524,6 @@ export async function ClaudeCodeWrapperPlugin({ client }) {
477
524
  return {};
478
525
  },
479
526
  methods: [
480
- {
481
- label: "Claude Code CLI",
482
- type: "api",
483
- authorize: async () => {
484
- // Return immediately with special key marker
485
- return { type: "success", key: "claude-code-cli" };
486
- },
487
- },
488
527
  {
489
528
  label: "Claude Pro/Max",
490
529
  type: "oauth",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-claude-code-wrapper",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "OpenCode plugin that wraps Claude Code CLI for API-like access",
5
5
  "main": "./index.mjs",
6
6
  "type": "module",