Skip to content

opencode support#10

Draft
dctanner wants to merge 1 commit intomainfrom
opencode-support
Draft

opencode support#10
dctanner wants to merge 1 commit intomainfrom
opencode-support

Conversation

@dctanner
Copy link
Copy Markdown
Contributor

Working except auth is not being inherited after login.

@dctanner dctanner mentioned this pull request Jan 20, 2026
@markhallen
Copy link
Copy Markdown

You're treating opencode-login like it meant "you need to auth right now!" but it actually just means "here's how you'd auth if needed." OpenCode reads creds from ~/.config/opencode/ automatically—same as Claude Code does with claude-login.

Just skip the special handling for opencode-login and go straight to session/new. If auth is actually missing, OpenCode will tell us then.


Diffs

app/src/chatSession.ts

@@ -156,12 +156,6 @@ export class ChatSession {
         this.pushSnippet(renderChatStatusSnippet("Session error", "error"));
         this.pushSnippet(renderChatErrorSnippet(details, this.errorId()));
       },
-      onAuthenticationRequired: (authMethod) => {
-        // Show authentication required message with instructions from the agent
-        const message = `**Authentication Required**\n\n${authMethod.description}\n\nAfter authenticating, come back and create a new agent.`;
-        this.pushSnippet(renderChatStatusSnippet("Authentication required", "error"));
-        this.pushSnippet(renderChatErrorSnippet(message, this.errorId()));
-      },
       onPromptResult: (_requestId, result, metadata) => {
         const promptMeta = asPromptMetadata(metadata);
         if (!promptMeta) {

app/src/agentProtocolSession.ts

@@ -47,8 +47,6 @@ export interface AgentProtocolSessionOptions {
   onInitializeError?: (error: unknown, message: Record<string, unknown>) => void;
   onSessionReady?: (sessionId: string) => void;
   onSessionError?: (error: unknown, message: Record<string, unknown>) => void;
-  /** Called when agent requires authentication (e.g., opencode-login) */
-  onAuthenticationRequired?: (authMethod: { id: string; name: string; description: string }) => void;
   onPromptQueued?: (requestId: string, text: string, metadata: unknown) => void;
   onPromptSent?: (requestId: string, text: string, metadata: unknown) => void;
   onPromptResult?: (requestId: string, result: Record<string, unknown>, metadata: unknown) => void;
@@ -94,20 +92,12 @@ export class AgentProtocolSession {
       }
       this.initializationComplete = true;
       // Check if agent advertises auth methods that require explicit authenticate call
-      const authMethods = readAuthMethods(payload.result);
-      const authMethodIds = authMethods?.map((m) => m.id) ?? [];
-      // Only call authenticate for gemini-api-key; claude-login is informational only
+      const authMethodIds = readAuthMethodIds(payload.result);
+      // Only call authenticate for gemini-api-key; claude-login and opencode-login are informational only
       // (Claude Code ACP doesn't implement authenticate - API key passed via env)
-      if (authMethodIds.includes("gemini-api-key")) {
+      // (OpenCode uses credentials stored in ~/.config/opencode - if present, auth is already done)
+      if (authMethodIds && authMethodIds.includes("gemini-api-key")) {
         this.dispatchAuthenticate("gemini-api-key");
-      } else if (authMethodIds.includes("opencode-login")) {
-        // OpenCode requires user to run `opencode auth login` in terminal
-        const method = authMethods?.find((m) => m.id === "opencode-login");
-        if (method) {
-          this.options.onAuthenticationRequired?.(method);
-        }
-        // Don't proceed to session/new - agent can't work without auth
-        return true;
       } else {
         this.dispatchSessionNew();
       }
@@ -488,28 +478,18 @@ function readArray(value: unknown): unknown[] | null {
   return Array.isArray(value) ? value : null;
 }
 
-interface AuthMethod {
-  id: string;
-  name: string;
-  description: string;
-}
-
-function readAuthMethods(result: unknown): AuthMethod[] | null {
+function readAuthMethodIds(result: unknown): string[] | null {
   const obj = readObject(result);
   if (!obj) return null;
   const methods = readArray(obj.authMethods);
   if (!methods || methods.length === 0) return [];
-  const authMethods: AuthMethod[] = [];
+  const ids: string[] = [];
   for (const m of methods) {
     const rec = readObject(m);
     const id = rec ? readString(rec.id) : null;
-    const name = rec ? readString(rec.name) : null;
-    const description = rec ? readString(rec.description) : null;
-    if (id) {
-      authMethods.push({ id, name: name ?? id, description: description ?? "" });
-    }
+    if (id) ids.push(id);
   }
-  return authMethods;
+  return ids;
 }
 
 function readPermissionOptions(value: unknown): PermissionRequestOption[] | null {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants